This commit is contained in:
@@ -51,6 +51,21 @@ func (c *LibraryController) Create(w http.ResponseWriter, r *http.Request) {
|
||||
jsonMsg(w, "Add library successfully.")
|
||||
}
|
||||
|
||||
func (c *LibraryController) GetByID(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
|
||||
}
|
||||
l, err := c.service.GetByID(id)
|
||||
if err != nil {
|
||||
jsonError(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
jsonResponse(w, l, http.StatusOK)
|
||||
}
|
||||
|
||||
func (c *LibraryController) UpdateName(w http.ResponseWriter, r *http.Request) {
|
||||
idParam := chi.URLParam(r, "id")
|
||||
id, err := strconv.Atoi(idParam)
|
||||
|
||||
@@ -25,6 +25,21 @@ func (c *SongController) GetAllWithDetails(w http.ResponseWriter, r *http.Reques
|
||||
jsonResponse(w, songs, http.StatusOK)
|
||||
}
|
||||
|
||||
func (c *SongController) GetByIDWithDetails(w http.ResponseWriter, r *http.Request) {
|
||||
paramID := chi.URLParam(r, "id")
|
||||
id, err := strconv.Atoi(paramID)
|
||||
if err != nil {
|
||||
http.Error(w, "无效的歌曲 ID", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
song, err := c.service.GetByIDWithDetails(id)
|
||||
if err != nil {
|
||||
jsonError(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
jsonResponse(w, song, http.StatusOK)
|
||||
}
|
||||
|
||||
func (c *SongController) Stream(w http.ResponseWriter, r *http.Request) {
|
||||
paramID := chi.URLParam(r, "id")
|
||||
id, err := strconv.Atoi(paramID)
|
||||
|
||||
Reference in New Issue
Block a user