mirror of
https://github.com/gabehf/Koito.git
synced 2026-03-18 03:36:35 -07:00
chore: expand debug logging + embeddable version
This commit is contained in:
parent
edbd7d506e
commit
e92733823d
25 changed files with 563 additions and 303 deletions
|
|
@ -5,24 +5,41 @@ import (
|
|||
"strconv"
|
||||
|
||||
"github.com/gabehf/koito/internal/db"
|
||||
"github.com/gabehf/koito/internal/logger"
|
||||
"github.com/gabehf/koito/internal/utils"
|
||||
)
|
||||
|
||||
func GetArtistHandler(store db.DB) func(w http.ResponseWriter, r *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
l := logger.FromContext(ctx)
|
||||
|
||||
l.Debug().Msg("GetArtistHandler: Received request to retrieve artist")
|
||||
|
||||
idStr := r.URL.Query().Get("id")
|
||||
id, err := strconv.Atoi(idStr)
|
||||
if err != nil {
|
||||
utils.WriteError(w, "id is invalid", 400)
|
||||
if idStr == "" {
|
||||
l.Debug().Msg("GetArtistHandler: Missing artist ID in request")
|
||||
utils.WriteError(w, "id must be provided", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
artist, err := store.GetArtist(r.Context(), db.GetArtistOpts{ID: int32(id)})
|
||||
id, err := strconv.Atoi(idStr)
|
||||
if err != nil {
|
||||
l.Debug().AnErr("error", err).Msg("GetArtistHandler: Invalid artist ID")
|
||||
utils.WriteError(w, "id is invalid", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
l.Debug().Msgf("GetArtistHandler: Retrieving artist with ID %d", id)
|
||||
|
||||
artist, err := store.GetArtist(ctx, db.GetArtistOpts{ID: int32(id)})
|
||||
if err != nil {
|
||||
l.Err(err).Msgf("GetArtistHandler: Failed to retrieve artist with ID %d", id)
|
||||
utils.WriteError(w, "artist with specified id could not be found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
l.Debug().Msgf("GetArtistHandler: Successfully retrieved artist with ID %d", id)
|
||||
utils.WriteJSON(w, http.StatusOK, artist)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue