diff options
| author | Bobby <[email protected]> | 2026-02-24 16:48:00 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2026-02-24 16:48:00 +0530 |
| commit | d3507ae5b9d88a250b444c0e996fa07f84f6e3c5 (patch) | |
| tree | 64680e5ba7c9b4aa2e412c5bb9611df0e940d971 /utils | |
| parent | c6ff27b989047cf0af8d6cf2aa86c8e80547cf10 (diff) | |
| download | metachan-d3507ae5b9d88a250b444c0e996fa07f84f6e3c5.tar.xz metachan-d3507ae5b9d88a250b444c0e996fa07f84f6e3c5.zip | |
feat: Refactor anime and character handling
- Removed old GetAnimeEpisodes and GetAnimeEpisodesByMALID functions, replaced with a new implementation in episodes.go.
- Added GetAnimeCharacters and GetAnimeCharacter functions to handle character retrieval.
- Introduced CharacterAnimeAppearance entity to track character appearances in anime.
- Updated repositories to manage character data and enrich character details.
- Implemented enriched_at timestamp for both anime and characters to track data updates.
- Added CharacterSync task to periodically enrich character data from the Jikan API.
- Updated router to include new character-related endpoints.
Diffstat (limited to 'utils')
| -rw-r--r-- | utils/api/jikan/jikan.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/utils/api/jikan/jikan.go b/utils/api/jikan/jikan.go index 8812c5a..507130a 100644 --- a/utils/api/jikan/jikan.go +++ b/utils/api/jikan/jikan.go @@ -316,3 +316,22 @@ func GetProducerByID(producerID int) (*types.JikanSingleProducerResponse, error) } return &response, nil } + +func GetCharacterByMALID(id int) (*types.JikanCharacterFullResponse, error) { + url := fmt.Sprintf("%s/characters/%d/full", jikanAPIBaseURL, id) + ctx, cancel := context.WithTimeout(context.Background(), contextTimeout) + defer cancel() + + bytes, err := clientInstance.makeRequest(ctx, url) + if err != nil { + logger.Errorf("JikanClient", "GetCharacterByMALID failed for ID %d: %v", id, err) + return nil, errors.New("failed to fetch character data from Jikan API") + } + + var response types.JikanCharacterFullResponse + if err := json.Unmarshal(bytes, &response); err != nil { + logger.Errorf("JikanClient", "Failed to unmarshal character response for ID %d: %v", id, err) + return nil, errors.New("failed to parse character data from Jikan API") + } + return &response, nil +} |
