refactors data access layer to use pop ORM for eager loading, adds book titles rented to renters in response body

This commit is contained in:
David Lick
2020-05-31 00:40:32 -04:00
parent a06b4d70ab
commit 28e52a4e08
29 changed files with 732 additions and 287 deletions
+1 -8
View File
@@ -6,7 +6,6 @@ import (
"errors"
"io/ioutil"
"net/http"
"strconv"
"github.com/davidlick/bookish/bookish-server/internal"
"github.com/davidlick/bookish/bookish-server/mysql"
@@ -36,13 +35,7 @@ func (s *Server) renterCtx(next http.Handler) http.Handler {
ctx := r.Context()
id := chi.URLParam(r, "renterId")
renterId, err := strconv.Atoi(id)
if err != nil {
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
return
}
renter, err := s.Renter.FetchRenter(renterId)
renter, err := s.Renters.FetchRenter(id)
if err != nil && errors.Is(mysql.ErrNotFound, err) {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return