refactor(server/api): resolveByID helper for parseUUID->fetch->404 (T4)
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
|
||||
"git.fabledsword.com/bvandeusen/minstrel/internal/apierror"
|
||||
@@ -218,20 +217,9 @@ func (h *handlers) handleGetRequest(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
id, ok := parseUUID(chi.URLParam(r, "id"))
|
||||
if !ok {
|
||||
writeErr(w, apierror.BadRequest("bad_request", "invalid request id"))
|
||||
return
|
||||
}
|
||||
|
||||
row, err := dbq.New(h.pool).GetLidarrRequestByID(r.Context(), id)
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
writeErr(w, apierror.NotFound("request"))
|
||||
return
|
||||
}
|
||||
h.logger.Error("api: get request", "err", err)
|
||||
writeErr(w, apierror.InternalMsg("get failed", err))
|
||||
row, apiErr := resolveByID(r, "id", dbq.New(h.pool).GetLidarrRequestByID, "request")
|
||||
if apiErr != nil {
|
||||
writeErr(w, apiErr)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user