This commit is contained in:
@@ -195,6 +195,21 @@ func (c *LibraryController) GetArtists(w http.ResponseWriter, r *http.Request) {
|
||||
jsonResponse(w, artists, http.StatusOK)
|
||||
}
|
||||
|
||||
func (c *LibraryController) GetArtist(w http.ResponseWriter, r *http.Request) {
|
||||
idParam := chi.URLParam(r, "id")
|
||||
id, err := strconv.Atoi(idParam)
|
||||
if err != nil {
|
||||
jsonError(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
artist, err := c.service.GetArtist(id)
|
||||
if err != nil {
|
||||
jsonError(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
jsonResponse(w, artist, http.StatusOK)
|
||||
}
|
||||
|
||||
func (c *LibraryController) GetAlbums(w http.ResponseWriter, r *http.Request) {
|
||||
albums, err := c.service.GetAlbums()
|
||||
if err != nil {
|
||||
@@ -203,3 +218,18 @@ func (c *LibraryController) GetAlbums(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
jsonResponse(w, albums, http.StatusOK)
|
||||
}
|
||||
|
||||
func (c *LibraryController) GetAlbum(w http.ResponseWriter, r *http.Request) {
|
||||
idParam := chi.URLParam(r, "id")
|
||||
id, err := strconv.Atoi(idParam)
|
||||
if err != nil {
|
||||
jsonError(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
album, err := c.service.GetAlbum(id)
|
||||
if err != nil {
|
||||
jsonError(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
jsonResponse(w, album, http.StatusOK)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user