Skip to content

Commit

Permalink
Add the skeleton of the createPlaylist Subsonic endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ironsmile committed Oct 12, 2024
1 parent fd53218 commit 6de0f0f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
16 changes: 13 additions & 3 deletions sqls/migrations/010_playlists.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
-- migrate Up

-- +migrate Up
CREATE TABLE IF NOT EXISTS `playlists` (
`id` integer not null primary key,
`name` text not null,
Expand All @@ -9,5 +8,16 @@ CREATE TABLE IF NOT EXISTS `playlists` (
`updated_at` integer not null
);

-- migrate Down
CREATE TABLE IF NOT EXISTS `playlists_tracks` (
`playlist_id` integer not null,
`track_id` integer not null,
`order` integer not null default 0,
FOREIGN KEY(playlist_id) REFERENCES playlists(id) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY(track_id) REFERENCES tracks(id) ON UPDATE CASCADE ON DELETE CASCADE
);

create unique index if not exists playlist_pairs on `playlists_tracks` ('playlist_id', `track_id`);

-- +migrate Down
drop table if exists `playlists`;
drop table if exists `playlists_tracks`;
35 changes: 35 additions & 0 deletions src/webserver/subsonic/create_playlist.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package subsonic

import (
"net/http"
"strconv"
)

func (s *subsonic) createPlaylist(w http.ResponseWriter, req *http.Request) {
if playlistID := req.Form.Get("playlistId"); playlistID != "" {
s.cretePlaylistUpdate(w, req)
} else {
s.cretePlaylistNew(w, req)
}
}

func (s *subsonic) cretePlaylistNew(w http.ResponseWriter, req *http.Request) {
name := req.Form.Get("name")
if name == "" {
resp := responseError(errCodeMissingParameter, "playlist name is required")
encodeResponse(w, req, resp)
return
}

}

func (s *subsonic) cretePlaylistUpdate(w http.ResponseWriter, req *http.Request) {
playlistID, err := strconv.ParseInt(req.Form.Get("playlistId"), 10, 64)
if err != nil {
resp := responseError(errCodeNotFound, "playlist not found")
encodeResponse(w, req, resp)
return
}

_ = playlistID
}
1 change: 1 addition & 0 deletions src/webserver/subsonic/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func (s *subsonic) initRouter() {
setUpHandler("/deleteInternetRadioStation", s.deleteInternetRadioStation)
setUpHandler("/getUser", s.getUser)
setUpHandler("/getRandomSongs", s.getRandomSongs)
setUpHandler("/createPlaylist", s.createPlaylist)

s.mux = s.authHandler(router)
}
Expand Down

0 comments on commit 6de0f0f

Please # to comment.