Rework search to show jobId matches in table, add projectId search

This commit is contained in:
Christoph Kluge
2022-12-14 10:02:22 +01:00
parent ac8548a950
commit c9ee8b552d
3 changed files with 32 additions and 20 deletions

View File

@@ -295,14 +295,13 @@ func main() {
}
secured.Handle("/query", graphQLEndpoint)
// Send a searchId and then reply with a redirect to a user or job. // IMPROVE HERE
// Send a searchId and then reply with a redirect to a user, or directly send query to job table for jobid and project.
secured.HandleFunc("/search", func(rw http.ResponseWriter, r *http.Request) {
if search := r.URL.Query().Get("searchId"); search != "" {
job, username, err := api.JobRepository.FindJobOrUser(r.Context(), search)
if err == repository.ErrNotFound {
http.Redirect(rw, r, "/monitoring/jobs/?jobId="+url.QueryEscape(search), http.StatusTemporaryRedirect) // Directly to table! -> Running Jobs probably
return
} else if err != nil {
_, username, project, err := api.JobRepository.FindJobOrUserOrProject(r.Context(), search)
if err != nil {
http.Error(rw, err.Error(), http.StatusInternalServerError)
return
}
@@ -310,10 +309,14 @@ func main() {
if username != "" {
http.Redirect(rw, r, "/monitoring/user/"+username, http.StatusTemporaryRedirect)
return
} else if (project != "") {
http.Redirect(rw, r, "/monitoring/jobs/?projectMatch=eq&project="+project, http.StatusTemporaryRedirect) // Directly to table!
return
} else {
http.Redirect(rw, r, fmt.Sprintf("/monitoring/job/%d", job), http.StatusTemporaryRedirect)
http.Redirect(rw, r, "/monitoring/jobs/?jobId="+url.QueryEscape(search), http.StatusTemporaryRedirect) // Directly to table!
return
}
} else {
http.Error(rw, "'searchId' query parameter missing", http.StatusBadRequest)
}