This repository has been archived by the owner on Sep 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
character.go
102 lines (92 loc) · 3.25 KB
/
character.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package api
import (
"net/http"
"strconv"
"github.com/go-chi/chi"
"github.com/rl404/go-malscraper"
"github.com/rl404/mal-api/internal/pkg/utils"
)
type char struct {
mal *malscraper.Malscraper
}
func registerCharacter(r chi.Router, mal *malscraper.Malscraper) {
c := char{mal: mal}
r.Get("/character/{id}", c.getCharacter)
r.Get("/character/{id}/anime", c.getCharacterAnime)
r.Get("/character/{id}/manga", c.getCharacterManga)
r.Get("/character/{id}/article", c.getCharacterArticle)
r.Get("/character/{id}/pictures", c.getCharacterPicture)
r.Get("/character/{id}/clubs", c.getCharacterClub)
}
// @summary Get character details
// @tags character
// @accept json
// @produce json
// @param id path integer true "Character ID"
// @success 200 {object} utils.Response{data=model.Character}
// @router /character/{id} [get]
func (c *char) getCharacter(w http.ResponseWriter, r *http.Request) {
id, _ := strconv.Atoi(chi.URLParam(r, "id"))
data, code, err := c.mal.GetCharacter(id)
utils.ResponseWithJSON(w, code, data, err)
}
// @summary Get character animeography list
// @tags character
// @accept json
// @produce json
// @param id path integer true "Character ID"
// @success 200 {object} utils.Response{data=[]model.Role}
// @router /character/{id}/anime [get]
func (c *char) getCharacterAnime(w http.ResponseWriter, r *http.Request) {
id, _ := strconv.Atoi(chi.URLParam(r, "id"))
data, code, err := c.mal.GetCharacterAnime(id)
utils.ResponseWithJSON(w, code, data, err)
}
// @summary Get character mangaography list
// @tags character
// @accept json
// @produce json
// @param id path integer true "Character ID"
// @success 200 {object} utils.Response{data=[]model.Role}
// @router /character/{id}/manga [get]
func (c *char) getCharacterManga(w http.ResponseWriter, r *http.Request) {
id, _ := strconv.Atoi(chi.URLParam(r, "id"))
data, code, err := c.mal.GetCharacterManga(id)
utils.ResponseWithJSON(w, code, data, err)
}
// @summary Get character article featured list
// @tags character
// @accept json
// @produce json
// @param id path integer true "Character ID"
// @success 200 {object} utils.Response{data=[]model.ArticleItem}
// @router /character/{id}/article [get]
func (c *char) getCharacterArticle(w http.ResponseWriter, r *http.Request) {
id, _ := strconv.Atoi(chi.URLParam(r, "id"))
data, code, err := c.mal.GetCharacterArticle(id)
utils.ResponseWithJSON(w, code, data, err)
}
// @summary Get character picture list
// @tags character
// @accept json
// @produce json
// @param id path integer true "Character ID"
// @success 200 {object} utils.Response{data=[]string}
// @router /character/{id}/pictures [get]
func (c *char) getCharacterPicture(w http.ResponseWriter, r *http.Request) {
id, _ := strconv.Atoi(chi.URLParam(r, "id"))
data, code, err := c.mal.GetCharacterPicture(id)
utils.ResponseWithJSON(w, code, data, err)
}
// @summary Get character club list
// @tags character
// @accept json
// @produce json
// @param id path integer true "Character ID"
// @success 200 {object} utils.Response{data=[]model.ClubItem}
// @router /character/{id}/clubs [get]
func (c *char) getCharacterClub(w http.ResponseWriter, r *http.Request) {
id, _ := strconv.Atoi(chi.URLParam(r, "id"))
data, code, err := c.mal.GetCharacterClub(id)
utils.ResponseWithJSON(w, code, data, err)
}