mirror of https://github.com/gabehf/Koito.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
670 B
29 lines
670 B
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"github.com/gabehf/koito/internal/db"
|
|
"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) {
|
|
|
|
idStr := r.URL.Query().Get("id")
|
|
id, err := strconv.Atoi(idStr)
|
|
if err != nil {
|
|
utils.WriteError(w, "id is invalid", 400)
|
|
return
|
|
}
|
|
|
|
artist, err := store.GetArtist(r.Context(), db.GetArtistOpts{ID: int32(id)})
|
|
if err != nil {
|
|
utils.WriteError(w, "artist with specified id could not be found", http.StatusNotFound)
|
|
return
|
|
}
|
|
utils.WriteJSON(w, http.StatusOK, artist)
|
|
}
|
|
}
|