feat: new schema for images

This commit is contained in:
Iron_Felix 2025-11-16 02:14:38 +03:00
parent e18f4a44c3
commit d1180a426f
2 changed files with 28 additions and 11 deletions

View file

@ -31,6 +31,13 @@ const (
Planned TitleStatus = "planned"
)
// Image defines model for Image.
type Image struct {
Id *int64 `json:"id,omitempty"`
ImagePath *string `json:"image_path,omitempty"`
StorageType *string `json:"storage_type,omitempty"`
}
// ReleaseSeason Title release season
type ReleaseSeason string
@ -57,7 +64,7 @@ type Title struct {
// Id Unique title ID (primary key)
Id int64 `json:"id"`
PosterId *int64 `json:"poster_id,omitempty"`
Poster *Image `json:"poster,omitempty"`
Rating *float64 `json:"rating,omitempty"`
RatingCount *int32 `json:"rating_count,omitempty"`
@ -178,12 +185,12 @@ func (a *Title) UnmarshalJSON(b []byte) error {
delete(object, "id")
}
if raw, found := object["poster_id"]; found {
err = json.Unmarshal(raw, &a.PosterId)
if raw, found := object["poster"]; found {
err = json.Unmarshal(raw, &a.Poster)
if err != nil {
return fmt.Errorf("error reading 'poster_id': %w", err)
return fmt.Errorf("error reading 'poster': %w", err)
}
delete(object, "poster_id")
delete(object, "poster")
}
if raw, found := object["rating"]; found {
@ -295,10 +302,10 @@ func (a Title) MarshalJSON() ([]byte, error) {
return nil, fmt.Errorf("error marshaling 'id': %w", err)
}
if a.PosterId != nil {
object["poster_id"], err = json.Marshal(a.PosterId)
if a.Poster != nil {
object["poster"], err = json.Marshal(a.Poster)
if err != nil {
return nil, fmt.Errorf("error marshaling 'poster_id': %w", err)
return nil, fmt.Errorf("error marshaling 'poster': %w", err)
}
}

View file

@ -565,6 +565,17 @@ paths:
components:
schemas:
Image:
type: object
properties:
id:
type: integer
format: int64
storage_type:
type: string
image_path:
type: string
TitleStatus:
type: string
description: Title status
@ -665,9 +676,8 @@ components:
$ref: '#/components/schemas/Studio'
tags:
$ref: '#/components/schemas/Tags'
poster_id:
type: integer
format: int64
poster:
$ref: '#/components/schemas/Image'
title_status:
$ref: '#/components/schemas/TitleStatus'
rating: