mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 20:34:37 +03:00
Model refactor, part 2 (#4092)
* Move conversions into changesetTranslator * Improve mutation error messages * Use models.New and models.NewPartial everywhere * Replace getStashIDsFor functions * Remove ImageCreateInput * Remove unused parameters * Refactor matching functions --------- Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
This commit is contained in:
@@ -36,6 +36,39 @@ type Image struct {
|
||||
PerformerIDs RelatedIDs `json:"performer_ids"`
|
||||
}
|
||||
|
||||
func NewImage() Image {
|
||||
currentTime := time.Now()
|
||||
return Image{
|
||||
CreatedAt: currentTime,
|
||||
UpdatedAt: currentTime,
|
||||
}
|
||||
}
|
||||
|
||||
type ImagePartial struct {
|
||||
Title OptionalString
|
||||
// Rating expressed in 1-100 scale
|
||||
Rating OptionalInt
|
||||
URL OptionalString
|
||||
Date OptionalDate
|
||||
Organized OptionalBool
|
||||
OCounter OptionalInt
|
||||
StudioID OptionalInt
|
||||
CreatedAt OptionalTime
|
||||
UpdatedAt OptionalTime
|
||||
|
||||
GalleryIDs *UpdateIDs
|
||||
TagIDs *UpdateIDs
|
||||
PerformerIDs *UpdateIDs
|
||||
PrimaryFileID *FileID
|
||||
}
|
||||
|
||||
func NewImagePartial() ImagePartial {
|
||||
currentTime := time.Now()
|
||||
return ImagePartial{
|
||||
UpdatedAt: NewOptionalTime(currentTime),
|
||||
}
|
||||
}
|
||||
|
||||
func (i *Image) LoadFiles(ctx context.Context, l FileLoader) error {
|
||||
return i.Files.load(func() ([]File, error) {
|
||||
return l.GetFiles(ctx, i.ID)
|
||||
@@ -102,43 +135,3 @@ func (i Image) DisplayName() string {
|
||||
|
||||
return strconv.Itoa(i.ID)
|
||||
}
|
||||
|
||||
type ImageCreateInput struct {
|
||||
*Image
|
||||
FileIDs []FileID
|
||||
}
|
||||
|
||||
type ImagePartial struct {
|
||||
Title OptionalString
|
||||
// Rating expressed in 1-100 scale
|
||||
Rating OptionalInt
|
||||
URL OptionalString
|
||||
Date OptionalDate
|
||||
Organized OptionalBool
|
||||
OCounter OptionalInt
|
||||
StudioID OptionalInt
|
||||
CreatedAt OptionalTime
|
||||
UpdatedAt OptionalTime
|
||||
|
||||
GalleryIDs *UpdateIDs
|
||||
TagIDs *UpdateIDs
|
||||
PerformerIDs *UpdateIDs
|
||||
PrimaryFileID *FileID
|
||||
}
|
||||
|
||||
func NewImagePartial() ImagePartial {
|
||||
updatedTime := time.Now()
|
||||
return ImagePartial{
|
||||
UpdatedAt: NewOptionalTime(updatedTime),
|
||||
}
|
||||
}
|
||||
|
||||
type Images []*Image
|
||||
|
||||
func (i *Images) Append(o interface{}) {
|
||||
*i = append(*i, o.(*Image))
|
||||
}
|
||||
|
||||
func (i *Images) New() interface{} {
|
||||
return &Image{}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user