This repository has been archived by the owner on Sep 22, 2021. It is now read-only.
/
character.go
138 lines (106 loc) · 3.15 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package validator
import (
"net/http"
"github.com/rl404/go-malscraper/errors"
"github.com/rl404/go-malscraper/internal"
"github.com/rl404/go-malscraper/model"
)
// GetCharacter to get character detail information.
func (v *Validator) GetCharacter(id int) (*model.Character, int, error) {
if id <= 0 {
return nil, http.StatusBadRequest, errors.ErrInvalidID
}
// Check empty id.
key := internal.GetKey(internal.KeyEmptyChar, id)
if v.isEmptyID(key) {
return nil, http.StatusNotFound, errors.ErrNot200
}
// Parse.
data, code, err := v.api.GetCharacter(id)
// Save empty id.
v.saveEmptyID(code, key)
return data, code, err
}
// GetCharacterArticle to get character featured article list.
func (v *Validator) GetCharacterArticle(id int) ([]model.ArticleItem, int, error) {
if id <= 0 {
return nil, http.StatusBadRequest, errors.ErrInvalidID
}
// Check empty id.
key := internal.GetKey(internal.KeyEmptyChar, id)
if v.isEmptyID(key) {
return nil, http.StatusNotFound, errors.ErrNot200
}
// Parse.
data, code, err := v.api.GetCharacterArticle(id)
// Save empty id.
v.saveEmptyID(code, key)
return data, code, err
}
// GetCharacterOgraphy to get character animeography/mangaography list.
func (v *Validator) GetCharacterOgraphy(t string, id int) ([]model.Role, int, error) {
if t != AnimeType && t != MangaType {
return nil, http.StatusBadRequest, errors.ErrInvalidType
}
if id <= 0 {
return nil, http.StatusBadRequest, errors.ErrInvalidID
}
// Check empty id.
key := internal.GetKey(internal.KeyEmptyChar, id)
if v.isEmptyID(key) {
return nil, http.StatusNotFound, errors.ErrNot200
}
// Parse.
data, code, err := v.api.GetCharacterOgraphy(t, id)
// Save empty id.
v.saveEmptyID(code, key)
return data, code, err
}
// GetCharacterPicture to get character picture list.
func (v *Validator) GetCharacterPicture(id int) ([]string, int, error) {
if id <= 0 {
return nil, http.StatusBadRequest, errors.ErrInvalidID
}
// Check empty id.
key := internal.GetKey(internal.KeyEmptyChar, id)
if v.isEmptyID(key) {
return nil, http.StatusNotFound, errors.ErrNot200
}
// Parse.
data, code, err := v.api.GetCharacterPicture(id)
// Save empty id.
v.saveEmptyID(code, key)
return data, code, err
}
// GetCharacterClub to get character club list.
func (v *Validator) GetCharacterClub(id int) ([]model.ClubItem, int, error) {
if id <= 0 {
return nil, http.StatusBadRequest, errors.ErrInvalidID
}
// Check empty id.
key := internal.GetKey(internal.KeyEmptyChar, id)
if v.isEmptyID(key) {
return nil, http.StatusNotFound, errors.ErrNot200
}
// Parse.
data, code, err := v.api.GetCharacterClub(id)
// Save empty id.
v.saveEmptyID(code, key)
return data, code, err
}
// GetCharacterVA to get character voice actor list.
func (v *Validator) GetCharacterVA(id int) ([]model.Role, int, error) {
if id <= 0 {
return nil, http.StatusBadRequest, errors.ErrInvalidID
}
// Check empty id.
key := internal.GetKey(internal.KeyEmptyChar, id)
if v.isEmptyID(key) {
return nil, http.StatusNotFound, errors.ErrNot200
}
// Parse.
data, code, err := v.api.GetCharacterVA(id)
// Save empty id.
v.saveEmptyID(code, key)
return data, code, err
}