refactor: extract CurrentUser and CurrentUserID helpers

This commit is contained in:
2026-05-28 12:51:11 +02:00
committed by Milas Holsting
parent 8454d01b09
commit bf28c307c9
4 changed files with 67 additions and 102 deletions

View File

@@ -25,11 +25,7 @@ func (h *WatchlistHandler) Register(r *gin.Engine) {
}
func (h *WatchlistHandler) HandleUpdateWatchlist(c *gin.Context) {
user, _ := c.Get("User")
userID := ""
if u, ok := user.(*domain.User); ok {
userID = u.ID
}
userID := server.CurrentUserID(c)
var body struct {
AnimeID int64 `json:"animeId"`
@@ -58,11 +54,7 @@ func (h *WatchlistHandler) HandleUpdateWatchlist(c *gin.Context) {
}
func (h *WatchlistHandler) HandleDeleteWatchlist(c *gin.Context) {
user, _ := c.Get("User")
userID := ""
if u, ok := user.(*domain.User); ok {
userID = u.ID
}
userID := server.CurrentUserID(c)
animeID, err := strconv.ParseInt(c.Param("id"), 10, 64)
@@ -89,11 +81,7 @@ func (h *WatchlistHandler) HandleDeleteWatchlist(c *gin.Context) {
}
func (h *WatchlistHandler) HandleDeleteContinueWatching(c *gin.Context) {
user, _ := c.Get("User")
userID := ""
if u, ok := user.(*domain.User); ok {
userID = u.ID
}
userID := server.CurrentUserID(c)
animeID, err := strconv.ParseInt(c.Param("id"), 10, 64)
@@ -120,11 +108,8 @@ func (h *WatchlistHandler) HandleDeleteContinueWatching(c *gin.Context) {
}
func (h *WatchlistHandler) HandleGetWatchlist(c *gin.Context) {
user, _ := c.Get("User")
userID := ""
if u, ok := user.(*domain.User); ok {
userID = u.ID
}
user := server.CurrentUser(c)
userID := server.CurrentUserID(c)
entries, err := h.svc.GetWatchlist(c.Request.Context(), userID)
if err != nil {