From 6de0f0ff9ebd242c46d000f47e349e18bcf42078 Mon Sep 17 00:00:00 2001 From: Doychin Atanasov Date: Sat, 12 Oct 2024 22:06:00 +0300 Subject: [PATCH] Add the skeleton of the createPlaylist Subsonic endpoint --- sqls/migrations/010_playlists.sql | 16 +++++++++-- src/webserver/subsonic/create_playlist.go | 35 +++++++++++++++++++++++ src/webserver/subsonic/index.go | 1 + 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 src/webserver/subsonic/create_playlist.go diff --git a/sqls/migrations/010_playlists.sql b/sqls/migrations/010_playlists.sql index 01da610..7a3ad31 100644 --- a/sqls/migrations/010_playlists.sql +++ b/sqls/migrations/010_playlists.sql @@ -1,5 +1,4 @@ --- migrate Up - +-- +migrate Up CREATE TABLE IF NOT EXISTS `playlists` ( `id` integer not null primary key, `name` text not null, @@ -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`; diff --git a/src/webserver/subsonic/create_playlist.go b/src/webserver/subsonic/create_playlist.go new file mode 100644 index 0000000..19d1bd0 --- /dev/null +++ b/src/webserver/subsonic/create_playlist.go @@ -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 +} diff --git a/src/webserver/subsonic/index.go b/src/webserver/subsonic/index.go index f2e8ee2..8e524e6 100644 --- a/src/webserver/subsonic/index.go +++ b/src/webserver/subsonic/index.go @@ -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) }