-
Notifications
You must be signed in to change notification settings - Fork 5
/
potfile.go
35 lines (28 loc) · 838 Bytes
/
potfile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package controllers
import (
"net/http"
"github.com/labstack/echo/v4"
"github.com/lachlan2k/phatcrack/api/internal/db"
"github.com/lachlan2k/phatcrack/api/internal/util"
"github.com/lachlan2k/phatcrack/common/pkg/apitypes"
)
func HookPotfileEndpoints(api *echo.Group) {
api.POST("/search", handlePotfileSearch)
}
func handlePotfileSearch(c echo.Context) error {
req, err := util.BindAndValidate[apitypes.PotfileSearchRequestDTO](c)
if err != nil {
return err
}
results, err := db.SearchPotfile(req.Hashes)
if err != nil {
return util.ServerError("Failed to search for hash", err)
}
dtoResults := make([]apitypes.PotfileSearchResultDTO, len(results))
for i, result := range results {
dtoResults[i] = result.ToDTO()
}
return c.JSON(http.StatusOK, apitypes.PotfileSearchResponseDTO{
Results: dtoResults,
})
}