diff --git a/internal/srv/restSrvV1/playlist.go b/internal/srv/restSrvV1/playlist.go index bf8a4e0..f6403a4 100644 --- a/internal/srv/restSrvV1/playlist.go +++ b/internal/srv/restSrvV1/playlist.go @@ -12,7 +12,13 @@ import ( func (s *RestServer) readPlaylists(w http.ResponseWriter, r *http.Request) { s.log.Debugf("Read playlists") - playlists, err := s.store.ReadPlaylists(nil, &restApiV1.PlaylistFilter{}) + var playlistFilter restApiV1.PlaylistFilter + err := json.NewDecoder(r.Body).Decode(&playlistFilter) + if err != nil { + s.log.Panicf("Unable to interpret data to read the playlists: %v", err) + } + + playlists, err := s.store.ReadPlaylists(nil, &playlistFilter) if err != nil { s.log.Panicf("Unable to read playlists: %v", err) } diff --git a/internal/version/version.go b/internal/version/version.go index 0448cd2..c30c55e 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -8,6 +8,6 @@ var ( AppVersion = restApiV1.Version{ MajorNumber: 0, MinorNumber: 3, - PatchNumber: 1, + PatchNumber: 2, } ) diff --git a/restClientV1/playlist.go b/restClientV1/playlist.go index 7576cc0..3b7c090 100644 --- a/restClientV1/playlist.go +++ b/restClientV1/playlist.go @@ -25,6 +25,24 @@ func (c *RestClient) CreatePlaylist(playListMeta *restApiV1.PlaylistMeta) (*rest } +func (c *RestClient) ReadPlaylist(playlistFilter *restApiV1.PlaylistFilter) ([]restApiV1.Playlist, ClientError) { + var playlistList []restApiV1.Playlist + + encodedPlaylistFilter, _ := json.Marshal(playlistFilter) + + response, cliErr := c.doGetRequestWithContent("/playlists", JsonContentType, bytes.NewBuffer(encodedPlaylistFilter)) + if cliErr != nil { + return nil, cliErr + } + defer response.Body.Close() + + if err := json.NewDecoder(response.Body).Decode(&playlistList); err != nil { + return nil, NewClientError(err) + } + + return playlistList, nil +} + func (c *RestClient) UpdatePlaylist(playlistId restApiV1.PlaylistId, playlistMeta *restApiV1.PlaylistMeta) (*restApiV1.Playlist, ClientError) { var playlist *restApiV1.Playlist diff --git a/restClientV1/restClient.go b/restClientV1/restClient.go index fcc2327..a3f7caf 100644 --- a/restClientV1/restClient.go +++ b/restClientV1/restClient.go @@ -229,6 +229,9 @@ func (c *RestClient) doRequest(method, relativeUrl string, contentType string, b func (c *RestClient) doGetRequest(relativeUrl string) (*http.Response, ClientError) { return c.doRequest("GET", relativeUrl, "", nil) } +func (c *RestClient) doGetRequestWithContent(relativeUrl string, contentType string, body io.Reader) (*http.Response, ClientError) { + return c.doRequest("GET", relativeUrl, contentType, body) +} func (c *RestClient) doDeleteRequest(relativeUrl string) (*http.Response, ClientError) { return c.doRequest("DELETE", relativeUrl, "", nil) } diff --git a/restClientV1/song.go b/restClientV1/song.go index c961cb4..c200a00 100644 --- a/restClientV1/song.go +++ b/restClientV1/song.go @@ -7,6 +7,22 @@ import ( "io" ) +func (c *RestClient) ReadSong(songId restApiV1.SongId) (*restApiV1.Song, ClientError) { + var song *restApiV1.Song + + response, cliErr := c.doGetRequest("/songs/" + string(songId)) + if cliErr != nil { + return nil, cliErr + } + defer response.Body.Close() + + if err := json.NewDecoder(response.Body).Decode(&song); err != nil { + return nil, NewClientError(err) + } + + return song, nil +} + func (c *RestClient) ReadSongContent(songId restApiV1.SongId) (io.ReadCloser, int64, ClientError) { response, cliErr := c.doGetRequest("/songContents/" + string(songId))