forked from nihonium/nyanimedb
feat: GetUsertitles implemented
This commit is contained in:
parent
cbbc2c179d
commit
e792d5780b
8 changed files with 456 additions and 283 deletions
|
|
@ -17,7 +17,24 @@ func NewServer(db *sqlc.Queries) Server {
|
|||
return Server{db: db}
|
||||
}
|
||||
|
||||
func (s Server) mapTitle(ctx context.Context, title sqlc.SearchTitlesRow) (oapi.Title, error) {
|
||||
func (s Server) mapTitle(ctx context.Context, title sqlc.GetTitleByIDRow) (oapi.Title, error) {
|
||||
|
||||
oapi_title := oapi.Title{
|
||||
EpisodesAired: title.EpisodesAired,
|
||||
EpisodesAll: title.EpisodesAired,
|
||||
// EpisodesLen: &episodes_lens,
|
||||
Id: title.ID,
|
||||
// Poster: &oapi_image,
|
||||
Rating: title.Rating,
|
||||
RatingCount: title.RatingCount,
|
||||
// ReleaseSeason: &release_season,
|
||||
ReleaseYear: title.ReleaseYear,
|
||||
// Studio: &oapi_studio,
|
||||
// Tags: oapi_tag_names,
|
||||
// TitleNames: title_names,
|
||||
// TitleStatus: oapi_status,
|
||||
// AdditionalProperties:
|
||||
}
|
||||
|
||||
title_names := make(map[string][]string, 0)
|
||||
err := json.Unmarshal(title.TitleNames, &title_names)
|
||||
|
|
@ -25,10 +42,13 @@ func (s Server) mapTitle(ctx context.Context, title sqlc.SearchTitlesRow) (oapi.
|
|||
return oapi.Title{}, fmt.Errorf("unmarshal TitleNames: %v", err)
|
||||
}
|
||||
|
||||
episodes_lens := make(map[string]float64, 0)
|
||||
err = json.Unmarshal(title.EpisodesLen, &episodes_lens)
|
||||
if err != nil {
|
||||
return oapi.Title{}, fmt.Errorf("unmarshal EpisodesLen: %v", err)
|
||||
if title.EpisodesLen != nil && len(title.EpisodesLen) > 0 {
|
||||
episodes_lens := make(map[string]float64, 0)
|
||||
err = json.Unmarshal(title.EpisodesLen, &episodes_lens)
|
||||
if err != nil {
|
||||
return oapi.Title{}, fmt.Errorf("unmarshal EpisodesLen: %v", err)
|
||||
}
|
||||
oapi_title.EpisodesLen = &episodes_lens
|
||||
}
|
||||
|
||||
oapi_tag_names := make(oapi.Tags, 0)
|
||||
|
|
@ -38,17 +58,19 @@ func (s Server) mapTitle(ctx context.Context, title sqlc.SearchTitlesRow) (oapi.
|
|||
}
|
||||
|
||||
var oapi_studio oapi.Studio
|
||||
|
||||
oapi_studio.Id = title.StudioID
|
||||
if title.StudioName != nil {
|
||||
oapi_studio.Name = *title.StudioName
|
||||
}
|
||||
oapi_studio.Description = title.StudioDesc
|
||||
if title.StudioIllustID != nil {
|
||||
oapi_studio.Poster.Id = title.StudioIllustID
|
||||
oapi_studio.Poster.ImagePath = title.StudioImagePath
|
||||
oapi_studio.Poster.StorageType = &title.StudioStorageType
|
||||
if title.StudioID != 0 {
|
||||
oapi_studio.Id = title.StudioID
|
||||
oapi_studio.Description = title.StudioDesc
|
||||
if title.StudioIllustID != nil {
|
||||
oapi_studio.Poster.Id = title.StudioIllustID
|
||||
oapi_studio.Poster.ImagePath = title.StudioImagePath
|
||||
oapi_studio.Poster.StorageType = &title.StudioStorageType
|
||||
}
|
||||
}
|
||||
oapi_title.Studio = &oapi_studio
|
||||
|
||||
var oapi_image oapi.Image
|
||||
|
||||
|
|
@ -62,27 +84,13 @@ func (s Server) mapTitle(ctx context.Context, title sqlc.SearchTitlesRow) (oapi.
|
|||
if title.ReleaseSeason != nil {
|
||||
release_season = oapi.ReleaseSeason(*title.ReleaseSeason)
|
||||
}
|
||||
oapi_title.ReleaseSeason = &release_season
|
||||
|
||||
oapi_status, err := TitleStatus2oapi(&title.TitleStatus)
|
||||
if err != nil {
|
||||
return oapi.Title{}, fmt.Errorf("TitleStatus2oapi: %v", err)
|
||||
}
|
||||
oapi_title := oapi.Title{
|
||||
EpisodesAired: title.EpisodesAired,
|
||||
EpisodesAll: title.EpisodesAired,
|
||||
EpisodesLen: &episodes_lens,
|
||||
Id: title.ID,
|
||||
Poster: &oapi_image,
|
||||
Rating: title.Rating,
|
||||
RatingCount: title.RatingCount,
|
||||
ReleaseSeason: &release_season,
|
||||
ReleaseYear: title.ReleaseYear,
|
||||
Studio: &oapi_studio,
|
||||
Tags: oapi_tag_names,
|
||||
TitleNames: title_names,
|
||||
TitleStatus: oapi_status,
|
||||
// AdditionalProperties:
|
||||
}
|
||||
oapi_title.TitleStatus = oapi_status
|
||||
|
||||
return oapi_title, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue