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" 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 // ReleaseSeason Title release season
type ReleaseSeason string type ReleaseSeason string
@ -57,7 +64,7 @@ type Title struct {
// Id Unique title ID (primary key) // Id Unique title ID (primary key)
Id int64 `json:"id"` Id int64 `json:"id"`
PosterId *int64 `json:"poster_id,omitempty"` Poster *Image `json:"poster,omitempty"`
Rating *float64 `json:"rating,omitempty"` Rating *float64 `json:"rating,omitempty"`
RatingCount *int32 `json:"rating_count,omitempty"` RatingCount *int32 `json:"rating_count,omitempty"`
@ -178,12 +185,12 @@ func (a *Title) UnmarshalJSON(b []byte) error {
delete(object, "id") delete(object, "id")
} }
if raw, found := object["poster_id"]; found { if raw, found := object["poster"]; found {
err = json.Unmarshal(raw, &a.PosterId) err = json.Unmarshal(raw, &a.Poster)
if err != nil { 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 { 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) return nil, fmt.Errorf("error marshaling 'id': %w", err)
} }
if a.PosterId != nil { if a.Poster != nil {
object["poster_id"], err = json.Marshal(a.PosterId) object["poster"], err = json.Marshal(a.Poster)
if err != nil { 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: components:
schemas: schemas:
Image:
type: object
properties:
id:
type: integer
format: int64
storage_type:
type: string
image_path:
type: string
TitleStatus: TitleStatus:
type: string type: string
description: Title status description: Title status
@ -665,9 +676,8 @@ components:
$ref: '#/components/schemas/Studio' $ref: '#/components/schemas/Studio'
tags: tags:
$ref: '#/components/schemas/Tags' $ref: '#/components/schemas/Tags'
poster_id: poster:
type: integer $ref: '#/components/schemas/Image'
format: int64
title_status: title_status:
$ref: '#/components/schemas/TitleStatus' $ref: '#/components/schemas/TitleStatus'
rating: rating: