refactor: dedupe watchlist ids

This commit is contained in:
2026-06-01 22:15:21 +02:00
committed by Milas Holsting
parent b9e1cc9aeb
commit 0cc9207755

View File

@@ -57,14 +57,12 @@ func (h *WatchlistHandler) HandleUpdateWatchlist(c *gin.Context) {
func (h *WatchlistHandler) HandleDeleteWatchlist(c *gin.Context) {
userID := server.CurrentUserID(c)
animeID, err := strconv.ParseInt(c.Param("id"), 10, 64)
if err != nil || animeID <= 0 {
server.RespondHTMLOrJSONError(c, http.StatusBadRequest, "invalid anime id")
animeID, ok := parseAnimeIDParam(c)
if !ok {
return
}
err = h.svc.RemoveEntry(c.Request.Context(), userID, animeID)
err := h.svc.RemoveEntry(c.Request.Context(), userID, animeID)
if err != nil {
server.RespondError(
c,
@@ -84,14 +82,12 @@ func (h *WatchlistHandler) HandleDeleteWatchlist(c *gin.Context) {
func (h *WatchlistHandler) HandleDeleteContinueWatching(c *gin.Context) {
userID := server.CurrentUserID(c)
animeID, err := strconv.ParseInt(c.Param("id"), 10, 64)
if err != nil || animeID <= 0 {
server.RespondHTMLOrJSONError(c, http.StatusBadRequest, "invalid anime id")
animeID, ok := parseAnimeIDParam(c)
if !ok {
return
}
err = h.svc.DeleteContinueWatching(c.Request.Context(), userID, animeID)
err := h.svc.DeleteContinueWatching(c.Request.Context(), userID, animeID)
if err != nil {
server.RespondError(
c,
@@ -108,6 +104,16 @@ func (h *WatchlistHandler) HandleDeleteContinueWatching(c *gin.Context) {
c.Status(http.StatusOK)
}
func parseAnimeIDParam(c *gin.Context) (int64, bool) {
animeID, err := strconv.ParseInt(c.Param("id"), 10, 64)
if err != nil || animeID <= 0 {
server.RespondHTMLOrJSONError(c, http.StatusBadRequest, "invalid anime id")
return 0, false
}
return animeID, true
}
func (h *WatchlistHandler) HandleGetWatchlist(c *gin.Context) {
user := server.CurrentUser(c)
userID := server.CurrentUserID(c)