Add GET /produce endpoint

This commit is contained in:
2021-06-20 21:05:54 -04:00
parent 2bf46c5fe6
commit ee79403dbf
2 changed files with 75 additions and 0 deletions
+14
View File
@@ -12,6 +12,7 @@ import (
func (s *server) produceGroup(r chi.Router) {
r.Group(func(r chi.Router) {
r.Route("/produce", func(r chi.Router) {
r.Get("/", s.handleGetAllProduce)
r.Post("/", s.handleAddProduce)
})
})
@@ -42,3 +43,16 @@ func (s *server) handleAddProduce(w http.ResponseWriter, r *http.Request) {
s.writeSuccess(ctx, w, nil, http.StatusCreated)
return
}
func (s *server) handleGetAllProduce(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
items, err := s.produceSvc.All()
if err != nil {
s.writeError(ctx, w, err, http.StatusInternalServerError)
return
}
s.writeSuccess(ctx, w, items, http.StatusOK)
return
}