@@ -15,18 +15,12 @@ func playlistStatisticsHandler(c *gin.Context) {
1515 return
1616 }
1717
18- playlistUrl := c .Query ("playlist" )
19- if playlistUrl == "" {
18+ playlistId := c .Query ("playlist" )
19+ if playlistId == "" {
2020 c .AbortWithError (http .StatusBadRequest , fmt .Errorf ("no playlist given" ))
2121 return
2222 }
2323
24- playlistId , err := getPlaylistIdFromURL (playlistUrl )
25- if err != nil {
26- c .AbortWithError (http .StatusBadRequest , fmt .Errorf ("could not extract playlist id from url" ))
27- return
28- }
29-
3024 result , err := queries .GetStatistics1 (c , db.GetStatistics1Params {
3125 User : user .ID ,
3226 Playlist : playlistId ,
@@ -36,5 +30,27 @@ func playlistStatisticsHandler(c *gin.Context) {
3630 return
3731 }
3832
39- c .JSON (http .StatusOK , result )
33+ c .JSON (http .StatusOK , Statistics1ToJson (result ))
34+ }
35+
36+ type GetStatisticsJsonResult struct {
37+ ID string `json:"id"`
38+ Title string `json:"title"`
39+ Artists string `json:"artists"`
40+ Image string `json:"image"`
41+ Points int64 `json:"points"`
42+ }
43+
44+ func Statistics1ToJson (result []db.GetStatistics1Row ) []GetStatisticsJsonResult {
45+ ret := make ([]GetStatisticsJsonResult , len (result ))
46+ for i , result := range result {
47+ ret [i ] = GetStatisticsJsonResult {
48+ ID : result .ID ,
49+ Title : result .Title .String ,
50+ Artists : result .Artists .String ,
51+ Image : result .Image .String ,
52+ Points : result .Points ,
53+ }
54+ }
55+ return ret
4056}
0 commit comments