create support for releases, artists, tracks, and credits
Signed-off-by: ari melody <ari@arimelody.me>
This commit is contained in:
parent
442889340c
commit
9329aa9f60
19 changed files with 252 additions and 37 deletions
46
api/track.go
Normal file
46
api/track.go
Normal file
|
@ -0,0 +1,46 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"arimelody.me/arimelody.me/global"
|
||||
"arimelody.me/arimelody.me/music/model"
|
||||
controller "arimelody.me/arimelody.me/music/controller"
|
||||
)
|
||||
|
||||
func CreateTrack() http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
var track model.Track
|
||||
err := json.NewDecoder(r.Body).Decode(&track)
|
||||
if err != nil {
|
||||
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if track.Title == "" {
|
||||
http.Error(w, "Track title cannot be empty", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
trackID, err := controller.CreateTrackDB(global.DB, &track)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to create credit: %s\n", err)
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
track.ID = trackID
|
||||
global.Tracks = append(global.Tracks, &track)
|
||||
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusCreated)
|
||||
err = json.NewEncoder(w).Encode(track)
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue