Skip to content

Commit

Permalink
Merge pull request #553 from NBISweden/dev/search-improvements
Browse files Browse the repository at this point in the history
Use issues.json to get search issue subjects
  • Loading branch information
jonandernovella authored Aug 8, 2022
2 parents 40783bb + 1a100fb commit dfefb6b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 21 additions & 4 deletions backend/api/issueSearchHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package api
import (
"encoding/json"
"fmt"
"strings"
"urdr-api/internal/config"

"github.com/gofiber/fiber/v2"
Expand Down Expand Up @@ -51,11 +50,29 @@ func issueSearchHandler(c *fiber.Ctx) error {
var foundIssues []Issue

for _, issue := range searchResponse.Results {
if issue.Type == "issue" && strings.Contains(issue.Title, "):") {
issueSubject := strings.TrimSpace(strings.Split(issue.Title, "):")[1])
if issue.Type == "issue" {

c.Request().URI().SetQueryString(
fmt.Sprintf("issue_id=%d", issue.Id))

if err := getIssuesHandler(c); err != nil {
} else if c.Response().StatusCode() != fiber.StatusOK {
return nil
}

// Parse the response and fill out the subjects.
issuesResponse := struct {
Issues []Issue `json:"issues"`
}{}

if err := json.Unmarshal(c.Response().Body(), &issuesResponse); err != nil {
c.Response().Reset()
return c.SendStatus(fiber.StatusUnprocessableEntity)
}

issue := Issue{
Id: issue.Id,
Subject: issueSubject,
Subject: issuesResponse.Issues[0].Subject,
}
foundIssues = append(foundIssues, issue)
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/QuickAdd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export const QuickAdd = ({
};

const foundIssues: { issues: Issue[] } = await fetch(
`${PUBLIC_API_URL}/api/search?q=${searchQuery}`,
`${PUBLIC_API_URL}/api/search?q=${searchQuery}&limit=5`,
{
method: "POST",
headers: headers,
Expand Down

0 comments on commit dfefb6b

Please sign in to comment.