diff --git a/backend/endpoints.go b/backend/endpoints.go index 8ec77127..afe9c5e7 100644 --- a/backend/endpoints.go +++ b/backend/endpoints.go @@ -73,7 +73,16 @@ func SearchName(c *gin.Context) { if len(results.Names) > maxResults { results.Names = results.Names[:maxResults] } - c.JSON(http.StatusOK, results) + // todo: bug here as an empty struct is returned if no results are found higher up in the stack + if len(results.Names) > 1 { + c.JSON(http.StatusOK, results) + } else if len(results.Names) == 1 { + if len(results.Names[0].Name) > 0 { + c.JSON(http.StatusOK, results) + } else { + c.JSON(http.StatusNoContent, nil) + } + } } } diff --git a/frontend/components/organisms/searchPage.tsx b/frontend/components/organisms/searchPage.tsx index 6863a1a3..91d06ddf 100644 --- a/frontend/components/organisms/searchPage.tsx +++ b/frontend/components/organisms/searchPage.tsx @@ -32,7 +32,7 @@ function SearchPage() { placeholder="Search for a lifter..." onChange={async e => setInputSearch(e.target.value)} /> - Number of lifters found: {data?.total}, showing {data?.names.length} + Number of lifters found: {(data?.total) || 0}, showing {(data?.names.length) || 0}
{data && (