This commit is contained in:
@@ -249,6 +249,21 @@ func (c *LibraryController) GetAlbums(w http.ResponseWriter, r *http.Request) {
|
||||
jsonResponse(w, albums, http.StatusOK)
|
||||
}
|
||||
|
||||
func (c *LibraryController) GetAlbumsByArtist(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
|
||||
}
|
||||
albums, err := c.service.GetAlbumsByArtistWithDetail(id)
|
||||
if err != nil {
|
||||
jsonError(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
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)
|
||||
@@ -263,3 +278,18 @@ func (c *LibraryController) GetAlbum(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
jsonResponse(w, album, http.StatusOK)
|
||||
}
|
||||
|
||||
func (c *LibraryController) GetAlbumCover(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
|
||||
}
|
||||
coverPath, err := c.service.GetAlbumCover(id)
|
||||
if err != nil {
|
||||
jsonError(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
http.ServeFile(w, r, coverPath)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user