mirror of
https://github.com/gabehf/Koito.git
synced 2026-03-17 11:16:35 -07:00
chore: initial public commit
This commit is contained in:
commit
fc9054b78c
250 changed files with 32809 additions and 0 deletions
31
engine/handlers/get_track.go
Normal file
31
engine/handlers/get_track.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gabehf/koito/internal/db"
|
||||
"github.com/gabehf/koito/internal/logger"
|
||||
"github.com/gabehf/koito/internal/utils"
|
||||
)
|
||||
|
||||
func GetTrackHandler(store db.DB) func(w http.ResponseWriter, r *http.Request) {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
l := logger.FromContext(r.Context())
|
||||
|
||||
idStr := r.URL.Query().Get("id")
|
||||
id, err := strconv.Atoi(idStr)
|
||||
if err != nil {
|
||||
utils.WriteError(w, "id is invalid", 400)
|
||||
return
|
||||
}
|
||||
|
||||
track, err := store.GetTrack(r.Context(), db.GetTrackOpts{ID: int32(id)})
|
||||
if err != nil {
|
||||
l.Err(err).Msg("Failed to get top albums")
|
||||
utils.WriteError(w, "track with specified id could not be found", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
utils.WriteJSON(w, http.StatusOK, track)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue