fix: bad types from sql

This commit is contained in:
Iron_Felix 2025-11-25 03:55:23 +03:00
parent 4c7d03cddc
commit 673ce48fac
5 changed files with 91 additions and 57 deletions

View file

@ -81,56 +81,56 @@ func (s Server) GetTagsByTitleId(ctx context.Context, id int64) (oapi.Tags, erro
return oapi_tag_names, nil
}
func (s Server) GetImage(ctx context.Context, id int64) (*oapi.Image, error) {
// func (s Server) GetImage(ctx context.Context, id int64) (*oapi.Image, error) {
var oapi_image oapi.Image
// var oapi_image oapi.Image
sqlc_image, err := s.db.GetImageByID(ctx, id)
if err != nil {
if err == pgx.ErrNoRows {
return nil, nil //todo: error reference in db
}
return &oapi_image, fmt.Errorf("query GetImageByID: %v", err)
}
// sqlc_image, err := s.db.GetImageByID(ctx, id)
// if err != nil {
// if err == pgx.ErrNoRows {
// return nil, nil //todo: error reference in db
// }
// return &oapi_image, fmt.Errorf("query GetImageByID: %v", err)
// }
//can cast and dont use brain cause all this fields required in image table
oapi_image.Id = &sqlc_image.ID
oapi_image.ImagePath = &sqlc_image.ImagePath
storageTypeStr := string(sqlc_image.StorageType)
oapi_image.StorageType = &storageTypeStr
// //can cast and dont use brain cause all this fields required in image table
// oapi_image.Id = &sqlc_image.ID
// oapi_image.ImagePath = &sqlc_image.ImagePath
// storageTypeStr := string(sqlc_image.StorageType)
// oapi_image.StorageType = string(storageTypeStr)
return &oapi_image, nil
}
// return &oapi_image, nil
// }
func (s Server) GetStudio(ctx context.Context, id int64) (*oapi.Studio, error) {
// func (s Server) GetStudio(ctx context.Context, id int64) (*oapi.Studio, error) {
var oapi_studio oapi.Studio
// var oapi_studio oapi.Studio
sqlc_studio, err := s.db.GetStudioByID(ctx, id)
if err != nil {
if err == pgx.ErrNoRows {
return nil, nil
}
return &oapi_studio, fmt.Errorf("query GetStudioByID: %v", err)
}
// sqlc_studio, err := s.db.GetStudioByID(ctx, id)
// if err != nil {
// if err == pgx.ErrNoRows {
// return nil, nil
// }
// return &oapi_studio, fmt.Errorf("query GetStudioByID: %v", err)
// }
oapi_studio.Id = sqlc_studio.ID
oapi_studio.Name = sqlc_studio.StudioName
oapi_studio.Description = sqlc_studio.StudioDesc
// oapi_studio.Id = sqlc_studio.ID
// oapi_studio.Name = sqlc_studio.StudioName
// oapi_studio.Description = sqlc_studio.StudioDesc
if sqlc_studio.IllustID == nil {
return &oapi_studio, nil
}
oapi_illust, err := s.GetImage(ctx, *sqlc_studio.IllustID)
if err != nil {
return &oapi_studio, fmt.Errorf("GetImage: %v", err)
}
if oapi_illust != nil {
oapi_studio.Poster = oapi_illust
}
// if sqlc_studio.IllustID == nil {
// return &oapi_studio, nil
// }
// oapi_illust, err := s.GetImage(ctx, *sqlc_studio.IllustID)
// if err != nil {
// return &oapi_studio, fmt.Errorf("GetImage: %v", err)
// }
// if oapi_illust != nil {
// oapi_studio.Poster = oapi_illust
// }
return &oapi_studio, nil
}
// return &oapi_studio, nil
// }
func (s Server) GetTitlesTitleId(ctx context.Context, request oapi.GetTitlesTitleIdRequestObject) (oapi.GetTitlesTitleIdResponseObject, error) {
var oapi_title oapi.Title
@ -233,6 +233,11 @@ func (s Server) GetTitles(ctx context.Context, request oapi.GetTitlesRequestObje
// StudioImagePath: title.StudioImagePath,
}
// if title.TitleStorageType != nil {
// s := *title.TitleStorageType
// _title.TitleStorageType = string(s)
// }
t, err := s.mapTitle(ctx, _title)
if err != nil {
log.Errorf("%v", err)