Skip to content

Commit fd8e6de

Browse files
committed
feat: add deletion of songs from playlist
1 parent 558e348 commit fd8e6de

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

infrastructure/setup/app.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ func (app *App) MapRoutes() {
9696
var playerController = player.NewController(app.Config, app.Db)
9797
app.handleFunc("GET /player", authRequired(playerController.GetPlayer))
9898
app.handleFunc("POST /addSong/{path...}", authRequired(playerController.AddSong))
99+
app.handleFunc("DELETE /removeSong/{id}", authRequired(playerController.RemoveSong))
99100
app.handleFunc("POST /reportSongDuration/{queuedSongId}", authRequired(playerController.ReportSongDuration))
100101

101102
app.handleFunc("GET /public/{path...}", pages.PublicHandler)

pages/player/GetPlayer.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,16 @@ func (controller *Controller) ReportSongDuration(w reqRes.MyResponseWriter, r *r
117117

118118
w.Header().Set("HX-Trigger", "playerReloadEvent")
119119
}
120+
121+
func (controller *Controller) RemoveSong(w reqRes.MyResponseWriter, r *reqRes.MyRequest) {
122+
pathQueryParam := r.PathValue("id")
123+
124+
result := controller.db.Delete(&models.QueuedSong{}, pathQueryParam)
125+
if result.Error != nil {
126+
message := fmt.Sprintf("Failed to delete song from queue: \n%v", result.Error)
127+
w.Error(message, http.StatusBadRequest)
128+
return
129+
}
130+
131+
controller.GetPlayer(w, r)
132+
}

pages/player/playerPartial.gohtml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
<td class="align-start">
1818
{{.Path}}
1919
</td>
20+
<td class="align-end short">
21+
<button class="icon-button" hx-delete="/removeSong/{{.ID}}" hx-target="#player-partial"
22+
hx-swap="outerHTML">
23+
<img src="/public/icons/delete.svg" width="20" height="20" alt="Delete"/>
24+
</button>
25+
</td>
2026
</tr>
2127
{{end}}
2228
</tbody>

0 commit comments

Comments
 (0)