Gallery URLs (#4114)

* Initial backend changes
* Fix unit tests
* UI changes
* Fix missing URL filters
This commit is contained in:
WithoutPants
2023-09-25 12:27:20 +10:00
committed by GitHub
parent a369e395e7
commit 9577600804
29 changed files with 361 additions and 117 deletions

View File

@@ -17,6 +17,11 @@ import (
var invalidID = -1
func loadGalleryRelationships(ctx context.Context, expected models.Gallery, actual *models.Gallery) error {
if expected.URLs.Loaded() {
if err := actual.LoadURLs(ctx, db.Gallery); err != nil {
return err
}
}
if expected.SceneIDs.Loaded() {
if err := actual.LoadSceneIDs(ctx, db.Gallery); err != nil {
return err
@@ -72,7 +77,7 @@ func Test_galleryQueryBuilder_Create(t *testing.T) {
"full",
models.Gallery{
Title: title,
URL: url,
URLs: models.NewRelatedStrings([]string{url}),
Date: &date,
Details: details,
Rating: &rating,
@@ -90,7 +95,7 @@ func Test_galleryQueryBuilder_Create(t *testing.T) {
"with file",
models.Gallery{
Title: title,
URL: url,
URLs: models.NewRelatedStrings([]string{url}),
Date: &date,
Details: details,
Rating: &rating,
@@ -222,7 +227,7 @@ func Test_galleryQueryBuilder_Update(t *testing.T) {
&models.Gallery{
ID: galleryIDs[galleryIdxWithScene],
Title: title,
URL: url,
URLs: models.NewRelatedStrings([]string{url}),
Date: &date,
Details: details,
Rating: &rating,
@@ -243,6 +248,7 @@ func Test_galleryQueryBuilder_Update(t *testing.T) {
"clear nullables",
&models.Gallery{
ID: galleryIDs[galleryIdxWithImage],
URLs: models.NewRelatedStrings([]string{}),
SceneIDs: models.NewRelatedIDs([]int{}),
TagIDs: models.NewRelatedIDs([]int{}),
PerformerIDs: models.NewRelatedIDs([]int{}),
@@ -384,7 +390,7 @@ func clearGalleryPartial() models.GalleryPartial {
return models.GalleryPartial{
Title: models.OptionalString{Set: true, Null: true},
Details: models.OptionalString{Set: true, Null: true},
URL: models.OptionalString{Set: true, Null: true},
URLs: &models.UpdateStrings{Mode: models.RelationshipUpdateModeSet},
Date: models.OptionalDate{Set: true, Null: true},
Rating: models.OptionalInt{Set: true, Null: true},
StudioID: models.OptionalInt{Set: true, Null: true},
@@ -416,9 +422,12 @@ func Test_galleryQueryBuilder_UpdatePartial(t *testing.T) {
"full",
galleryIDs[galleryIdxWithImage],
models.GalleryPartial{
Title: models.NewOptionalString(title),
Details: models.NewOptionalString(details),
URL: models.NewOptionalString(url),
Title: models.NewOptionalString(title),
Details: models.NewOptionalString(details),
URLs: &models.UpdateStrings{
Values: []string{url},
Mode: models.RelationshipUpdateModeSet,
},
Date: models.NewOptionalDate(date),
Rating: models.NewOptionalInt(rating),
Organized: models.NewOptionalBool(true),
@@ -443,7 +452,7 @@ func Test_galleryQueryBuilder_UpdatePartial(t *testing.T) {
ID: galleryIDs[galleryIdxWithImage],
Title: title,
Details: details,
URL: url,
URLs: models.NewRelatedStrings([]string{url}),
Date: &date,
Rating: &rating,
Organized: true,
@@ -1653,7 +1662,13 @@ func TestGalleryQueryURL(t *testing.T) {
verifyFn := func(g *models.Gallery) {
t.Helper()
verifyString(t, g.URL, urlCriterion)
urls := g.URLs.List()
var url string
if len(urls) > 0 {
url = urls[0]
}
verifyString(t, url, urlCriterion)
}
verifyGalleryQuery(t, filter, verifyFn)
@@ -1683,6 +1698,12 @@ func verifyGalleryQuery(t *testing.T, filter models.GalleryFilterType, verifyFn
galleries := queryGallery(ctx, t, sqb, &filter, nil)
for _, g := range galleries {
if err := g.LoadURLs(ctx, sqb); err != nil {
t.Errorf("Error loading gallery URLs: %v", err)
}
}
// assume it should find at least one
assert.Greater(t, len(galleries), 0)