aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorBobby <[email protected]>2026-02-03 14:50:13 +0530
committerBobby <[email protected]>2026-02-03 14:50:13 +0530
commite4d65624c49c11db7da46d05f5e4caeec79bd955 (patch)
tree57d7e68bffa0592129d1a75af9f05896bb6f926d /utils
parented36e0308c7cd3a6197c899cb16bfe65cc5194b4 (diff)
downloadmetachan-e4d65624c49c11db7da46d05f5e4caeec79bd955.tar.xz
metachan-e4d65624c49c11db7da46d05f5e4caeec79bd955.zip
Add genre-based anime retrieval with pagination and related database updates
Diffstat (limited to 'utils')
-rw-r--r--utils/api/jikan/jikan.go20
-rw-r--r--utils/api/jikan/types.go51
2 files changed, 71 insertions, 0 deletions
diff --git a/utils/api/jikan/jikan.go b/utils/api/jikan/jikan.go
index 1e45c74..4f34dc3 100644
--- a/utils/api/jikan/jikan.go
+++ b/utils/api/jikan/jikan.go
@@ -280,3 +280,23 @@ func (c *JikanClient) GetAnimeGenres() (*JikanGenresResponse, error) {
return &genresResponse, nil
}
+
+// GetAnimeByGenre fetches paginated anime list for a specific genre
+func (c *JikanClient) GetAnimeByGenre(genreID int, page int, limit int) (*JikanAnimeListResponse, error) {
+ apiURL := fmt.Sprintf("https://api.jikan.moe/v4/anime?genres=%d&page=%d&limit=%d", genreID, page, limit)
+
+ ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+ defer cancel()
+
+ bodyBytes, err := c.makeRequest(ctx, apiURL)
+ if err != nil {
+ return nil, fmt.Errorf("failed to get anime by genre: %w", err)
+ }
+
+ var listResponse JikanAnimeListResponse
+ if err := json.Unmarshal(bodyBytes, &listResponse); err != nil {
+ return nil, fmt.Errorf("failed to decode anime list response: %w", err)
+ }
+
+ return &listResponse, nil
+}
diff --git a/utils/api/jikan/types.go b/utils/api/jikan/types.go
index 393be56..6e7d7f7 100644
--- a/utils/api/jikan/types.go
+++ b/utils/api/jikan/types.go
@@ -27,6 +27,57 @@ type JikanGenresResponse struct {
Data []JikanGenre `json:"data"`
}
+// JikanAnimeListItem represents a single anime in list responses
+type JikanAnimeListItem struct {
+ MALID int `json:"mal_id"`
+ URL string `json:"url"`
+ Title string `json:"title"`
+ TitleEnglish string `json:"title_english"`
+ TitleJapanese string `json:"title_japanese"`
+ TitleSynonyms []string `json:"title_synonyms"`
+ Type string `json:"type"`
+ Source string `json:"source"`
+ Episodes int `json:"episodes"`
+ Status string `json:"status"`
+ Airing bool `json:"airing"`
+ Synopsis string `json:"synopsis"`
+ Score float64 `json:"score"`
+ ScoredBy int `json:"scored_by"`
+ Rank int `json:"rank"`
+ Popularity int `json:"popularity"`
+ Members int `json:"members"`
+ Favorites int `json:"favorites"`
+ Season string `json:"season"`
+ Year int `json:"year"`
+ Images struct {
+ JPG struct {
+ ImageURL string `json:"image_url"`
+ SmallImageURL string `json:"small_image_url"`
+ LargeImageURL string `json:"large_image_url"`
+ } `json:"jpg"`
+ } `json:"images"`
+ Genres []JikanGenericMALStructure `json:"genres"`
+ ExplicitGenres []JikanGenericMALStructure `json:"explicit_genres"`
+ Producers []JikanGenericMALStructure `json:"producers"`
+ Licensors []JikanGenericMALStructure `json:"licensors"`
+ Studios []JikanGenericMALStructure `json:"studios"`
+}
+
+// JikanAnimeListResponse represents paginated anime list response
+type JikanAnimeListResponse struct {
+ Pagination struct {
+ LastVisiblePage int `json:"last_visible_page"`
+ HasNextPage bool `json:"has_next_page"`
+ CurrentPage int `json:"current_page"`
+ Items struct {
+ Count int `json:"count"`
+ Total int `json:"total"`
+ PerPage int `json:"per_page"`
+ } `json:"items"`
+ } `json:"pagination"`
+ Data []JikanAnimeListItem `json:"data"`
+}
+
// JikanAnimeResponse represents the main anime response from Jikan API
type JikanAnimeResponse struct {
Data struct {