fix: bad types from sql
This commit is contained in:
parent
4c7d03cddc
commit
673ce48fac
5 changed files with 91 additions and 57 deletions
|
|
@ -17,6 +17,22 @@ func NewServer(db *sqlc.Queries) Server {
|
|||
return Server{db: db}
|
||||
}
|
||||
|
||||
func sql2StorageType(s *sqlc.StorageTypeT) (*oapi.ImageStorageType, error) {
|
||||
if s == nil {
|
||||
return nil, nil
|
||||
}
|
||||
var t oapi.ImageStorageType
|
||||
switch *s {
|
||||
case sqlc.StorageTypeTLocal:
|
||||
t = oapi.Local
|
||||
case sqlc.StorageTypeTS3:
|
||||
t = oapi.S3
|
||||
default:
|
||||
return nil, fmt.Errorf("unexpected storage type: %s", *s)
|
||||
}
|
||||
return &t, nil
|
||||
}
|
||||
|
||||
func (s Server) mapTitle(ctx context.Context, title sqlc.GetTitleByIDRow) (oapi.Title, error) {
|
||||
|
||||
oapi_title := oapi.Title{
|
||||
|
|
@ -70,7 +86,13 @@ func (s Server) mapTitle(ctx context.Context, title sqlc.GetTitleByIDRow) (oapi.
|
|||
oapi_studio.Poster = &oapi.Image{}
|
||||
oapi_studio.Poster.Id = title.StudioIllustID
|
||||
oapi_studio.Poster.ImagePath = title.StudioImagePath
|
||||
oapi_studio.Poster.StorageType = &title.StudioStorageType
|
||||
|
||||
s, err := sql2StorageType(title.StudioStorageType)
|
||||
if err != nil {
|
||||
return oapi.Title{}, fmt.Errorf("mapTitle, studio storage type: %v", err)
|
||||
}
|
||||
oapi_studio.Poster.StorageType = s
|
||||
|
||||
}
|
||||
}
|
||||
oapi_title.Studio = &oapi_studio
|
||||
|
|
@ -80,7 +102,11 @@ func (s Server) mapTitle(ctx context.Context, title sqlc.GetTitleByIDRow) (oapi.
|
|||
if title.PosterID != nil {
|
||||
oapi_image.Id = title.PosterID
|
||||
oapi_image.ImagePath = title.TitleImagePath
|
||||
oapi_image.StorageType = &title.TitleStorageType
|
||||
s, err := sql2StorageType(title.TitleStorageType)
|
||||
if err != nil {
|
||||
return oapi.Title{}, fmt.Errorf("mapTitle, title starage type: %v", err)
|
||||
}
|
||||
oapi_image.StorageType = s
|
||||
}
|
||||
oapi_title.Poster = &oapi_image
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue