stash/pkg/models/model_studio.go
DingDongSoLong4 24e4719abc
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>
2023-09-11 12:24:15 +10:00

78 lines
1.8 KiB
Go

package models
import (
"context"
"time"
)
type Studio struct {
ID int `json:"id"`
Name string `json:"name"`
URL string `json:"url"`
ParentID *int `json:"parent_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
// Rating expressed in 1-100 scale
Rating *int `json:"rating"`
Details string `json:"details"`
IgnoreAutoTag bool `json:"ignore_auto_tag"`
Aliases RelatedStrings `json:"aliases"`
StashIDs RelatedStashIDs `json:"stash_ids"`
}
func NewStudio() Studio {
currentTime := time.Now()
return Studio{
CreatedAt: currentTime,
UpdatedAt: currentTime,
}
}
// StudioPartial represents part of a Studio object. It is used to update the database entry.
type StudioPartial struct {
ID int
Name OptionalString
URL OptionalString
ParentID OptionalInt
// Rating expressed in 1-100 scale
Rating OptionalInt
Details OptionalString
CreatedAt OptionalTime
UpdatedAt OptionalTime
IgnoreAutoTag OptionalBool
Aliases *UpdateStrings
StashIDs *UpdateStashIDs
}
func NewStudioPartial() StudioPartial {
currentTime := time.Now()
return StudioPartial{
UpdatedAt: NewOptionalTime(currentTime),
}
}
func (s *Studio) LoadAliases(ctx context.Context, l AliasLoader) error {
return s.Aliases.load(func() ([]string, error) {
return l.GetAliases(ctx, s.ID)
})
}
func (s *Studio) LoadStashIDs(ctx context.Context, l StashIDLoader) error {
return s.StashIDs.load(func() ([]StashID, error) {
return l.GetStashIDs(ctx, s.ID)
})
}
func (s *Studio) LoadRelationships(ctx context.Context, l PerformerReader) error {
if err := s.LoadAliases(ctx, l); err != nil {
return err
}
if err := s.LoadStashIDs(ctx, l); err != nil {
return err
}
return nil
}