From ff15a82f106741effbe727087c5649bd8c7adea5 Mon Sep 17 00:00:00 2001 From: mkelvers Date: Wed, 13 May 2026 13:10:04 +0200 Subject: [PATCH] fix: watchlist 500 from missing UUID and toast classList error --- internal/watchlist/handler/handler.go | 11 ++++++----- internal/watchlist/service/service.go | 3 +++ static/toast.ts | 3 ++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/internal/watchlist/handler/handler.go b/internal/watchlist/handler/handler.go index 71f633b..2066a80 100644 --- a/internal/watchlist/handler/handler.go +++ b/internal/watchlist/handler/handler.go @@ -30,15 +30,16 @@ func (h *WatchlistHandler) HandleUpdateWatchlist(c *gin.Context) { userID = u.ID } - animeID, _ := strconv.ParseInt(c.PostForm("anime_id"), 10, 64) - status := c.PostForm("status") - - if animeID <= 0 || status == "" { + var body struct { + AnimeID int64 `json:"animeId"` + Status string `json:"status"` + } + if err := c.ShouldBindJSON(&body); err != nil || body.AnimeID <= 0 || body.Status == "" { c.Status(http.StatusBadRequest) return } - err := h.svc.UpdateEntry(c.Request.Context(), userID, animeID, status) + err := h.svc.UpdateEntry(c.Request.Context(), userID, body.AnimeID, body.Status) if err != nil { c.Status(http.StatusInternalServerError) return diff --git a/internal/watchlist/service/service.go b/internal/watchlist/service/service.go index 5547fc6..a60a747 100644 --- a/internal/watchlist/service/service.go +++ b/internal/watchlist/service/service.go @@ -6,6 +6,8 @@ import ( "mal/integrations/jikan" "mal/internal/db" "mal/internal/domain" + + "github.com/google/uuid" ) type watchlistService struct { @@ -34,6 +36,7 @@ func (s *watchlistService) UpdateEntry(ctx context.Context, userID string, anime } _, err = s.repo.UpsertWatchListEntry(ctx, db.UpsertWatchListEntryParams{ + ID: uuid.New().String(), UserID: userID, AnimeID: animeID, Status: status, diff --git a/static/toast.ts b/static/toast.ts index 9043356..04bec74 100644 --- a/static/toast.ts +++ b/static/toast.ts @@ -29,7 +29,8 @@ const showToast = ({ message, duration = 3000 }: ToastOptions): void => { return; } - const toast = template.content.cloneNode(true) as HTMLElement; + const toast = template.content.cloneNode(true).firstElementChild as HTMLElement; + if (!toast) return; const messageEl = toast.querySelector('.toast-message'); const closeBtn = toast.querySelector('.toast-close');