refactor: use int64 for watchlist map keys
This commit is contained in:
@@ -27,7 +27,7 @@ func NewAnimeHandler(svc domain.AnimeService, watchlistSvc domain.WatchlistServi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *AnimeHandler) watchlistMapForAnimes(ctx context.Context, userID string, animes []domain.Anime) map[int]bool {
|
func (h *AnimeHandler) watchlistMapForAnimes(ctx context.Context, userID string, animes []domain.Anime) map[int64]bool {
|
||||||
animeIDs := make([]int64, 0, len(animes))
|
animeIDs := make([]int64, 0, len(animes))
|
||||||
for _, anime := range animes {
|
for _, anime := range animes {
|
||||||
if anime.MalID > 0 {
|
if anime.MalID > 0 {
|
||||||
@@ -37,14 +37,14 @@ func (h *AnimeHandler) watchlistMapForAnimes(ctx context.Context, userID string,
|
|||||||
return h.watchlistMapForIDs(ctx, userID, animeIDs)
|
return h.watchlistMapForIDs(ctx, userID, animeIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *AnimeHandler) watchlistMapForIDs(ctx context.Context, userID string, animeIDs []int64) map[int]bool {
|
func (h *AnimeHandler) watchlistMapForIDs(ctx context.Context, userID string, animeIDs []int64) map[int64]bool {
|
||||||
if userID == "" || len(animeIDs) == 0 {
|
if userID == "" || len(animeIDs) == 0 {
|
||||||
return map[int]bool{}
|
return map[int64]bool{}
|
||||||
}
|
}
|
||||||
|
|
||||||
watchlistMap, err := h.watchlistSvc.GetWatchlistMap(ctx, userID, animeIDs)
|
watchlistMap, err := h.watchlistSvc.GetWatchlistMap(ctx, userID, animeIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return map[int]bool{}
|
return map[int64]bool{}
|
||||||
}
|
}
|
||||||
return watchlistMap
|
return watchlistMap
|
||||||
}
|
}
|
||||||
@@ -74,7 +74,7 @@ func (h *AnimeHandler) HandleCatalog(c *gin.Context) {
|
|||||||
c.HTML(http.StatusOK, "index.gohtml", gin.H{
|
c.HTML(http.StatusOK, "index.gohtml", gin.H{
|
||||||
"CurrentPath": "/",
|
"CurrentPath": "/",
|
||||||
"User": user,
|
"User": user,
|
||||||
"WatchlistMap": map[int]bool{},
|
"WatchlistMap": map[int64]bool{},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ func (h *AnimeHandler) renderCatalogSection(c *gin.Context, section string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
watchlistMap := map[int]bool{}
|
watchlistMap := map[int64]bool{}
|
||||||
if animes, ok := data["Animes"].([]domain.Anime); ok {
|
if animes, ok := data["Animes"].([]domain.Anime); ok {
|
||||||
watchlistMap = h.watchlistMapForAnimes(c.Request.Context(), userID, animes)
|
watchlistMap = h.watchlistMapForAnimes(c.Request.Context(), userID, animes)
|
||||||
}
|
}
|
||||||
@@ -143,7 +143,7 @@ func (h *AnimeHandler) renderDiscoverSection(c *gin.Context, section string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
watchlistMap := map[int]bool{}
|
watchlistMap := map[int64]bool{}
|
||||||
if animes, ok := data["Animes"].([]domain.Anime); ok {
|
if animes, ok := data["Animes"].([]domain.Anime); ok {
|
||||||
watchlistMap = h.watchlistMapForAnimes(c.Request.Context(), userID, animes)
|
watchlistMap = h.watchlistMapForAnimes(c.Request.Context(), userID, animes)
|
||||||
}
|
}
|
||||||
@@ -401,7 +401,7 @@ func (h *AnimeHandler) HandleQuickSearch(c *gin.Context) {
|
|||||||
Type: anime.Type,
|
Type: anime.Type,
|
||||||
Year: anime.Year,
|
Year: anime.Year,
|
||||||
Image: anime.ImageURL(),
|
Image: anime.ImageURL(),
|
||||||
InWatchlist: watchlistMap[anime.MalID],
|
InWatchlist: watchlistMap[int64(anime.MalID)],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, output)
|
c.JSON(http.StatusOK, output)
|
||||||
@@ -609,7 +609,7 @@ func (h *AnimeHandler) HandleRandomAnime(c *gin.Context) {
|
|||||||
inWatchlist := false
|
inWatchlist := false
|
||||||
if u, ok := user.(*domain.User); ok {
|
if u, ok := user.(*domain.User); ok {
|
||||||
watchlistMap := h.watchlistMapForIDs(c.Request.Context(), u.ID, []int64{int64(anime.MalID)})
|
watchlistMap := h.watchlistMapForIDs(c.Request.Context(), u.ID, []int64{int64(anime.MalID)})
|
||||||
inWatchlist = watchlistMap[anime.MalID]
|
inWatchlist = watchlistMap[int64(anime.MalID)]
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ type WatchlistService interface {
|
|||||||
UpdateEntry(ctx context.Context, userID string, animeID int64, status string) error
|
UpdateEntry(ctx context.Context, userID string, animeID int64, status string) error
|
||||||
RemoveEntry(ctx context.Context, userID string, animeID int64) error
|
RemoveEntry(ctx context.Context, userID string, animeID int64) error
|
||||||
GetWatchlist(ctx context.Context, userID string) ([]UserWatchListRow, error)
|
GetWatchlist(ctx context.Context, userID string) ([]UserWatchListRow, error)
|
||||||
GetWatchlistMap(ctx context.Context, userID string, animeIDs []int64) (map[int]bool, error)
|
GetWatchlistMap(ctx context.Context, userID string, animeIDs []int64) (map[int64]bool, error)
|
||||||
GetCommandPaletteWatchlist(ctx context.Context, userID string, query string, limit int64) ([]UserWatchListRow, error)
|
GetCommandPaletteWatchlist(ctx context.Context, userID string, query string, limit int64) ([]UserWatchListRow, error)
|
||||||
GetCommandPaletteContinueWatching(ctx context.Context, userID string, query string, limit int64) ([]db.GetContinueWatchingEntriesRow, error)
|
GetCommandPaletteContinueWatching(ctx context.Context, userID string, query string, limit int64) ([]db.GetContinueWatchingEntriesRow, error)
|
||||||
GetWatchListEntry(ctx context.Context, userID string, animeID int64) (WatchlistEntry, error)
|
GetWatchListEntry(ctx context.Context, userID string, animeID int64) (WatchlistEntry, error)
|
||||||
|
|||||||
@@ -55,8 +55,8 @@ func (s *watchlistService) GetWatchlist(ctx context.Context, userID string) ([]d
|
|||||||
return s.repo.GetUserWatchList(ctx, userID)
|
return s.repo.GetUserWatchList(ctx, userID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *watchlistService) GetWatchlistMap(ctx context.Context, userID string, animeIDs []int64) (map[int]bool, error) {
|
func (s *watchlistService) GetWatchlistMap(ctx context.Context, userID string, animeIDs []int64) (map[int64]bool, error) {
|
||||||
watchlistMap := make(map[int]bool)
|
watchlistMap := make(map[int64]bool)
|
||||||
if userID == "" || len(animeIDs) == 0 {
|
if userID == "" || len(animeIDs) == 0 {
|
||||||
return watchlistMap, nil
|
return watchlistMap, nil
|
||||||
}
|
}
|
||||||
@@ -67,7 +67,7 @@ func (s *watchlistService) GetWatchlistMap(ctx context.Context, userID string, a
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, animeID := range matches {
|
for _, animeID := range matches {
|
||||||
watchlistMap[int(animeID)] = true
|
watchlistMap[animeID] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
return watchlistMap, nil
|
return watchlistMap, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user