mirror of
https://github.com/ultrasn0w/huso.git
synced 2025-12-13 14:09:52 +01:00
More struct work
This commit is contained in:
12
klotz.go
12
klotz.go
@@ -2,13 +2,19 @@ package main
|
|||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
type Anime struct {
|
type AnimeUser struct {
|
||||||
Anime int64 `json:"anime"`
|
Anime int64 `json:"anime"`
|
||||||
Users []WatchUser `json:"users"`
|
Users []WatchUser `json:"users"`
|
||||||
Data AnimeDetail `json:"data"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type AnimeDetail struct {
|
type AnimeUserDetail struct {
|
||||||
|
Anime int64 `json:"anime"`
|
||||||
|
Users []WatchUser `json:"users"`
|
||||||
|
Data Anime `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Anime struct {
|
||||||
|
Anime int64 `json:"anime"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
TitleEn string `json:"title_en"`
|
TitleEn string `json:"title_en"`
|
||||||
TitleJp string `json:"title_jp"`
|
TitleJp string `json:"title_jp"`
|
||||||
|
|||||||
10
knecht.go
10
knecht.go
@@ -87,10 +87,7 @@ func GetSeasonDataAll() ([]Anime, []byte, error) {
|
|||||||
animes := make([]Anime, 0)
|
animes := make([]Anime, 0)
|
||||||
// convert to anime
|
// convert to anime
|
||||||
for _, a := range data.Data {
|
for _, a := range data.Data {
|
||||||
animes = append(animes, Anime{
|
animes = append(animes, JikanConvert(&a))
|
||||||
Anime: a.MalID,
|
|
||||||
Data: JikanConvert(&a),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
for i := 2; data.Pagination.HasNextPage; i++ {
|
for i := 2; data.Pagination.HasNextPage; i++ {
|
||||||
color.Infof("Seite %d abfragen...\n", i)
|
color.Infof("Seite %d abfragen...\n", i)
|
||||||
@@ -104,10 +101,7 @@ func GetSeasonDataAll() ([]Anime, []byte, error) {
|
|||||||
data.Pagination.Items.Count += newData.Pagination.Items.Count
|
data.Pagination.Items.Count += newData.Pagination.Items.Count
|
||||||
// convert to anime
|
// convert to anime
|
||||||
for _, a := range newData.Data {
|
for _, a := range newData.Data {
|
||||||
animes = append(animes, Anime{
|
animes = append(animes, JikanConvert(&a))
|
||||||
Anime: a.MalID,
|
|
||||||
Data: JikanConvert(&a),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
color.Infof("%d Anime bekommen\n", len(animes))
|
color.Infof("%d Anime bekommen\n", len(animes))
|
||||||
|
|||||||
22
nuss.go
22
nuss.go
@@ -30,8 +30,8 @@ func SaveUser(user *UserData) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddUserToAnime(username string, userId, animeId int64) (*Anime, error) {
|
func AddUserToAnime(username string, userId, animeId int64) (*AnimeUser, error) {
|
||||||
var anime Anime
|
var anime AnimeUser
|
||||||
err := db.Update(
|
err := db.Update(
|
||||||
func(tx *nutsdb.Tx) error {
|
func(tx *nutsdb.Tx) error {
|
||||||
keyBytes := Int64ToByte(animeId)
|
keyBytes := Int64ToByte(animeId)
|
||||||
@@ -50,7 +50,7 @@ func AddUserToAnime(username string, userId, animeId int64) (*Anime, error) {
|
|||||||
for _, u := range users {
|
for _, u := range users {
|
||||||
if u.MalID == userId {
|
if u.MalID == userId {
|
||||||
// early terminate
|
// early terminate
|
||||||
anime = Anime{
|
anime = AnimeUser{
|
||||||
Anime: animeId,
|
Anime: animeId,
|
||||||
Users: users,
|
Users: users,
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ func AddUserToAnime(username string, userId, animeId int64) (*Anime, error) {
|
|||||||
Username: username,
|
Username: username,
|
||||||
MalID: userId,
|
MalID: userId,
|
||||||
})
|
})
|
||||||
anime = Anime{
|
anime = AnimeUser{
|
||||||
Anime: animeId,
|
Anime: animeId,
|
||||||
Users: users,
|
Users: users,
|
||||||
}
|
}
|
||||||
@@ -76,8 +76,8 @@ func AddUserToAnime(username string, userId, animeId int64) (*Anime, error) {
|
|||||||
return &anime, err
|
return &anime, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteUserFromAnime(username string, userId, animeId int64) (*Anime, error) {
|
func DeleteUserFromAnime(username string, userId, animeId int64) (*AnimeUser, error) {
|
||||||
var anime Anime
|
var anime AnimeUser
|
||||||
err := db.Update(
|
err := db.Update(
|
||||||
func(tx *nutsdb.Tx) error {
|
func(tx *nutsdb.Tx) error {
|
||||||
keyBytes := Int64ToByte(animeId)
|
keyBytes := Int64ToByte(animeId)
|
||||||
@@ -100,7 +100,7 @@ func DeleteUserFromAnime(username string, userId, animeId int64) (*Anime, error)
|
|||||||
users[i] = users[len(users)-1]
|
users[i] = users[len(users)-1]
|
||||||
users = users[:len(users)-1]
|
users = users[:len(users)-1]
|
||||||
// check if anime needs recycling
|
// check if anime needs recycling
|
||||||
anime = Anime{
|
anime = AnimeUser{
|
||||||
Anime: animeId,
|
Anime: animeId,
|
||||||
Users: users,
|
Users: users,
|
||||||
}
|
}
|
||||||
@@ -164,15 +164,15 @@ func DeleteUserFromAnimes(userId int64) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadAnimes() ([]Anime, error) {
|
func ReadAnimeUsers() ([]AnimeUser, error) {
|
||||||
var animes []Anime
|
var animes []AnimeUser
|
||||||
err := db.View(
|
err := db.View(
|
||||||
func(tx *nutsdb.Tx) error {
|
func(tx *nutsdb.Tx) error {
|
||||||
entries, err := tx.GetAll(bucketAnime)
|
entries, err := tx.GetAll(bucketAnime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
animes = make([]Anime, 0)
|
animes = make([]AnimeUser, 0)
|
||||||
// iterate entries
|
// iterate entries
|
||||||
for _, e := range entries {
|
for _, e := range entries {
|
||||||
// decode anime list
|
// decode anime list
|
||||||
@@ -185,7 +185,7 @@ func ReadAnimes() ([]Anime, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
anime := Anime{
|
anime := AnimeUser{
|
||||||
Anime: animeId,
|
Anime: animeId,
|
||||||
Users: users,
|
Users: users,
|
||||||
}
|
}
|
||||||
|
|||||||
10
ober.go
10
ober.go
@@ -64,19 +64,19 @@ func WatchGet(ctx *fasthttp.RequestCtx) {
|
|||||||
}
|
}
|
||||||
userId = user.MalID
|
userId = user.MalID
|
||||||
}
|
}
|
||||||
animes, err := ReadAnimes()
|
animes, err := ReadAnimeUsers()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// check if no anime were inserted
|
// check if no anime were inserted
|
||||||
if err != nutsdb.ErrBucketEmpty {
|
if err != nutsdb.ErrBucketEmpty {
|
||||||
addErrorToCtx(ctx, err)
|
addErrorToCtx(ctx, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
animes = make([]Anime, 0)
|
animes = make([]AnimeUser, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// apply single user logic
|
// apply single user logic
|
||||||
if usrVal != nil {
|
if usrVal != nil {
|
||||||
filteredAnimes := make([]Anime, 0)
|
filteredAnimes := make([]AnimeUser, 0)
|
||||||
for _, a := range animes {
|
for _, a := range animes {
|
||||||
for _, u := range a.Users {
|
for _, u := range a.Users {
|
||||||
if u.MalID == userId {
|
if u.MalID == userId {
|
||||||
@@ -226,7 +226,7 @@ func processUpdateReq(ctx *fasthttp.RequestCtx, update bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
body := ctx.PostBody()
|
body := ctx.PostBody()
|
||||||
var animes []Anime
|
var animes []AnimeUser
|
||||||
err := json.Unmarshal(body, &animes)
|
err := json.Unmarshal(body, &animes)
|
||||||
if err != nil || len(animes) == 0 {
|
if err != nil || len(animes) == 0 {
|
||||||
ctx.WriteString(err.Error())
|
ctx.WriteString(err.Error())
|
||||||
@@ -248,7 +248,7 @@ func processUpdateReq(ctx *fasthttp.RequestCtx, update bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var animeData *Anime
|
var animeData *AnimeUser
|
||||||
// update or delete request
|
// update or delete request
|
||||||
if update {
|
if update {
|
||||||
// anime exitsts => save
|
// anime exitsts => save
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func JikanConvert(jik *SeasonAnimeJikan) AnimeDetail {
|
func JikanConvert(jik *SeasonAnimeJikan) Anime {
|
||||||
res := AnimeDetail{
|
res := Anime{
|
||||||
|
Anime: jik.MalID,
|
||||||
Title: jik.Title,
|
Title: jik.Title,
|
||||||
TitleEn: jik.TitleEnglish,
|
TitleEn: jik.TitleEnglish,
|
||||||
TitleJp: jik.TitleJapanese,
|
TitleJp: jik.TitleJapanese,
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ body { background-color: #1a1a1a; color: #fff; }
|
|||||||
<table>
|
<table>
|
||||||
{% for _, anime := range animes %}
|
{% for _, anime := range animes %}
|
||||||
<tr>
|
<tr>
|
||||||
<td><strong>{%s anime.Data.Title %}</strong></td>
|
<td><strong>{%s anime.Title %}</strong></td>
|
||||||
<td>{%dl anime.Anime %}</td>
|
<td>{%dl anime.Anime %}</td>
|
||||||
<td>{%d anime.Data.Episodes %}</td>
|
<td>{%d anime.Episodes %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func StreamIndex(qw422016 *qt422016.Writer, animes []Anime) {
|
|||||||
//line season.qtpl:31
|
//line season.qtpl:31
|
||||||
qw422016.N().S(` <tr> <td><strong>`)
|
qw422016.N().S(` <tr> <td><strong>`)
|
||||||
//line season.qtpl:33
|
//line season.qtpl:33
|
||||||
qw422016.E().S(anime.Data.Title)
|
qw422016.E().S(anime.Title)
|
||||||
//line season.qtpl:33
|
//line season.qtpl:33
|
||||||
qw422016.N().S(`</strong></td> <td>`)
|
qw422016.N().S(`</strong></td> <td>`)
|
||||||
//line season.qtpl:34
|
//line season.qtpl:34
|
||||||
@@ -41,7 +41,7 @@ func StreamIndex(qw422016 *qt422016.Writer, animes []Anime) {
|
|||||||
//line season.qtpl:34
|
//line season.qtpl:34
|
||||||
qw422016.N().S(`</td> <td>`)
|
qw422016.N().S(`</td> <td>`)
|
||||||
//line season.qtpl:35
|
//line season.qtpl:35
|
||||||
qw422016.N().D(anime.Data.Episodes)
|
qw422016.N().D(anime.Episodes)
|
||||||
//line season.qtpl:35
|
//line season.qtpl:35
|
||||||
qw422016.N().S(`</td> </tr> `)
|
qw422016.N().S(`</td> </tr> `)
|
||||||
//line season.qtpl:37
|
//line season.qtpl:37
|
||||||
|
|||||||
Reference in New Issue
Block a user