Files

47 lines
1.4 KiB
Go

package http
import "git.jokresner.de/johannes/meilisearch-showcase/internal/domain/catalog"
type errorResponse struct {
Error string `json:"error"`
}
type movieResponse struct {
ID string `json:"id"`
Title string `json:"title"`
Overview string `json:"overview,omitempty"`
Genres []string `json:"genres"`
Year int `json:"year"`
Rating float64 `json:"rating"`
Match string `json:"match,omitempty"` // highlighted title
}
type facetResponse struct {
Value string `json:"value"`
Count int `json:"count"`
}
type searchResponse struct {
Hits []movieResponse `json:"hits"`
EstimatedTotal int64 `json:"estimatedTotal"`
ProcessingMS int64 `json:"processingMs"`
Genres []facetResponse `json:"genres,omitempty"`
}
func toMovieResponse(m *catalog.Movie) movieResponse {
return movieResponse{ID: m.ID().String(), Title: m.Title(), Overview: m.Overview(), Genres: m.Genres(), Year: m.Year(), Rating: m.Rating()}
}
func toSearchResponse(r catalog.Results) searchResponse {
out := searchResponse{EstimatedTotal: r.EstimatedTotal, ProcessingMS: r.ProcessingMS, Hits: make([]movieResponse, 0, len(r.Hits))}
for _, h := range r.Hits {
mr := toMovieResponse(h.Movie)
mr.Match = h.Formatted
out.Hits = append(out.Hits, mr)
}
for _, f := range r.Genres {
out.Genres = append(out.Genres, facetResponse{Value: f.Value, Count: f.Count})
}
return out
}