From 0de6696e70c4f2b46ed4b58baa644dbc037abe60 Mon Sep 17 00:00:00 2001 From: InfiniteStash <117855276+InfiniteStash@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:05:30 +0000 Subject: [PATCH 1/3] Refactor database date formats --- gqlgen.yml | 8 - pkg/api/performer_edit_integration_test.go | 10 +- pkg/api/performer_integration_test.go | 10 +- pkg/api/resolver_model_performer.go | 6 +- pkg/api/resolver_model_performer_edit.go | 4 - pkg/api/resolver_model_scene.go | 10 +- pkg/api/resolver_model_scene_edit.go | 4 - pkg/api/scene_edit_integration_test.go | 19 +-- pkg/api/sql_resolver.go | 35 +++-- pkg/database/database.go | 2 +- .../postgres/37_date_columns.up.sql | 29 ++++ pkg/models/extension_edit_details.go | 4 +- pkg/models/extension_edit_details_test.go | 144 ++++++++---------- pkg/models/generated_exec.go | 80 +--------- pkg/models/model_edit.go | 58 ++++--- pkg/models/model_performer.go | 79 +++------- pkg/models/model_performer_test.go | 134 ++++++++-------- pkg/models/model_scene.go | 61 ++------ pkg/models/translate.go | 24 --- 19 files changed, 270 insertions(+), 451 deletions(-) create mode 100644 pkg/database/migrations/postgres/37_date_columns.up.sql diff --git a/gqlgen.yml b/gqlgen.yml index f5f0bbf02..905ba0f88 100644 --- a/gqlgen.yml +++ b/gqlgen.yml @@ -25,14 +25,6 @@ models: fields: url: resolver: true - PerformerEdit: - fields: - birthdate: - resolver: true - SceneEdit: - fields: - date: - resolver: true QueryPerformersResultType: model: github.com/stashapp/stash-box/pkg/models.PerformerQuery QueryEditsResultType: diff --git a/pkg/api/performer_edit_integration_test.go b/pkg/api/performer_edit_integration_test.go index 5cf5a401a..accf506e8 100644 --- a/pkg/api/performer_edit_integration_test.go +++ b/pkg/api/performer_edit_integration_test.go @@ -89,15 +89,13 @@ func (s *performerEditTestRunner) verifyPerformerEditDetails(input models.Perfor c := fieldComparator{r: &s.testRunner} c.strPtrStrPtr(input.Name, performerDetails.Name, "Name") c.strPtrStrPtr(input.Disambiguation, performerDetails.Disambiguation, "Disambiguation") + c.strPtrStrPtr(input.Birthdate, performerDetails.Birthdate, "Birthdate") assert.DeepEqual(s.t, input.Aliases, performerDetails.AddedAliases) assert.Assert(s.t, input.Gender.IsValid() && (input.Gender.String() == *performerDetails.Gender)) s.compareURLs(input.Urls, performerDetails.AddedUrls) - date, accuracy, _ := models.ParseFuzzyString(input.Birthdate) - assert.Assert(s.t, accuracy.Valid && (accuracy.String == *performerDetails.BirthdateAccuracy)) - assert.Assert(s.t, date.Valid && (date.String == *performerDetails.Birthdate)) assert.Assert(s.t, input.Ethnicity.IsValid() && (input.Ethnicity.String() == *performerDetails.Ethnicity)) assert.Assert(s.t, input.Country != nil && (*input.Country == *performerDetails.Country)) assert.Assert(s.t, input.EyeColor.IsValid() && (input.EyeColor.String() == *performerDetails.EyeColor)) @@ -142,14 +140,10 @@ func (s *performerEditTestRunner) verifyPerformerEdit(input models.PerformerEdit urls, _ := resolver.Urls(s.ctx, performer) s.compareURLs(input.Urls, urls) - date, accuracy, _ := models.ParseFuzzyString(input.Birthdate) - if input.Birthdate == nil { - assert.Assert(s.t, !performer.BirthdateAccuracy.Valid) assert.Assert(s.t, !performer.Birthdate.Valid) } else { - assert.Equal(s.t, accuracy.String, performer.BirthdateAccuracy.String) - assert.Equal(s.t, date.String, performer.Birthdate.String) + assert.Equal(s.t, *input.Birthdate, performer.Birthdate.String) } if input.Ethnicity == nil { diff --git a/pkg/api/performer_integration_test.go b/pkg/api/performer_integration_test.go index cd4c6259e..043463811 100644 --- a/pkg/api/performer_integration_test.go +++ b/pkg/api/performer_integration_test.go @@ -102,9 +102,8 @@ func (s *performerTestRunner) verifyCreatedPerformer(input models.PerformerCreat urls, _ := s.resolver.Performer().Urls(s.ctx, performer) assert.Assert(s.t, compareUrls(input.Urls, urls), "Urls") - inputDate, inputAccuracy, _ := models.ParseFuzzyString(input.Birthdate) - birthdate, _ := r.Birthdate(s.ctx, performer) - assert.Assert(s.t, bothNil(birthdate, input.Birthdate) || (!oneNil(birthdate, input.Birthdate) && birthdate.Date == inputDate.String && birthdate.Accuracy.String() == inputAccuracy.String)) + birthdate, _ := r.BirthDate(s.ctx, performer) + assert.DeepEqual(s.t, birthdate, input.Birthdate) ethnicity, _ := r.Ethnicity(s.ctx, performer) assert.DeepEqual(s.t, ethnicity, input.Ethnicity) @@ -263,9 +262,8 @@ func (s *performerTestRunner) verifyUpdatedPerformer(input models.PerformerUpdat urls, _ := s.resolver.Performer().Urls(s.ctx, performer) assert.Assert(s.t, compareUrls(input.Urls, urls)) - inputDate, inputAccuracy, _ := models.ParseFuzzyString(input.Birthdate) - birthdate, _ := r.Birthdate(s.ctx, performer) - assert.Assert(s.t, birthdate == nil || (birthdate.Date == inputDate.String && birthdate.Accuracy.String() == inputAccuracy.String)) + birthdate, _ := s.resolver.Performer().BirthDate(s.ctx, performer) + assert.DeepEqual(s.t, birthdate, input.Birthdate) tattoos, _ := s.resolver.Performer().Tattoos(s.ctx, performer) assert.Assert(s.t, compareBodyMods(input.Tattoos, tattoos)) diff --git a/pkg/api/resolver_model_performer.go b/pkg/api/resolver_model_performer.go index c19ff47f5..b7756661d 100644 --- a/pkg/api/resolver_model_performer.go +++ b/pkg/api/resolver_model_performer.go @@ -45,13 +45,13 @@ func (r *performerResolver) Urls(ctx context.Context, obj *models.Performer) ([] return dataloader.For(ctx).PerformerUrlsByID.Load(obj.ID) } +// Deprecated: use `BirthDate` func (r *performerResolver) Birthdate(ctx context.Context, obj *models.Performer) (*models.FuzzyDate, error) { - ret := obj.ResolveBirthdate() - return &ret, nil + return resolveFuzzyDate(obj.Birthdate), nil } func (r *performerResolver) BirthDate(ctx context.Context, obj *models.Performer) (*string, error) { - return resolveFuzzyDate(&obj.Birthdate.String, &obj.BirthdateAccuracy.String), nil + return resolveNullString(obj.Birthdate), nil } func (r *performerResolver) Age(ctx context.Context, obj *models.Performer) (*int, error) { diff --git a/pkg/api/resolver_model_performer_edit.go b/pkg/api/resolver_model_performer_edit.go index e030e25cb..b8691fcbe 100644 --- a/pkg/api/resolver_model_performer_edit.go +++ b/pkg/api/resolver_model_performer_edit.go @@ -64,10 +64,6 @@ func (r *performerEditResolver) RemovedImages(ctx context.Context, obj *models.P return imageList(ctx, obj.RemovedImages) } -func (r *performerEditResolver) Birthdate(ctx context.Context, obj *models.PerformerEdit) (*string, error) { - return resolveFuzzyDate(obj.Birthdate, obj.BirthdateAccuracy), nil -} - func (r *performerEditResolver) Images(ctx context.Context, obj *models.PerformerEdit) ([]*models.Image, error) { fac := r.getRepoFactory(ctx) id, err := fac.Edit().FindPerformerID(obj.EditID) diff --git a/pkg/api/resolver_model_scene.go b/pkg/api/resolver_model_scene.go index a9ac04698..a371259c0 100644 --- a/pkg/api/resolver_model_scene.go +++ b/pkg/api/resolver_model_scene.go @@ -34,13 +34,17 @@ func (r *sceneResolver) Code(ctx context.Context, obj *models.Scene) (*string, e return resolveNullString(obj.Code), nil } -// Deprecated: use `DateFuzzy` +// Deprecated: use `ReleaseDate` func (r *sceneResolver) Date(ctx context.Context, obj *models.Scene) (*string, error) { - return &obj.ResolveDate().Date, nil + ret := resolveFuzzyDate(obj.Date) + if ret != nil { + return &ret.Date, nil + } + return nil, nil } func (r *sceneResolver) ReleaseDate(ctx context.Context, obj *models.Scene) (*string, error) { - return resolveFuzzyDate(&obj.Date.String, &obj.DateAccuracy.String), nil + return resolveNullString(obj.Date), nil } func (r *sceneResolver) Studio(ctx context.Context, obj *models.Scene) (*models.Studio, error) { diff --git a/pkg/api/resolver_model_scene_edit.go b/pkg/api/resolver_model_scene_edit.go index b7cd4f676..bfebbbf02 100644 --- a/pkg/api/resolver_model_scene_edit.go +++ b/pkg/api/resolver_model_scene_edit.go @@ -133,10 +133,6 @@ func (r *sceneEditResolver) Fingerprints(ctx context.Context, obj *models.SceneE return ret, nil } -func (r *sceneEditResolver) Date(ctx context.Context, obj *models.SceneEdit) (*string, error) { - return resolveFuzzyDate(obj.Date, obj.DateAccuracy), nil -} - func (r *sceneEditResolver) Images(ctx context.Context, obj *models.SceneEdit) ([]*models.Image, error) { fac := r.getRepoFactory(ctx) id, err := fac.Edit().FindSceneID(obj.EditID) diff --git a/pkg/api/scene_edit_integration_test.go b/pkg/api/scene_edit_integration_test.go index 837bbe084..f4a215beb 100644 --- a/pkg/api/scene_edit_integration_test.go +++ b/pkg/api/scene_edit_integration_test.go @@ -94,10 +94,7 @@ func (s *sceneEditTestRunner) verifySceneEditDetails(input models.SceneEditDetai c.strPtrStrPtr(input.Code, sceneDetails.Code, "Code") c.uuidPtrUUIDPtr(input.StudioID, sceneDetails.StudioID, "StudioID") c.intPtrInt64Ptr(input.Duration, sceneDetails.Duration, "Duration") - - inputDate, inputAccuracy, _ := models.ParseFuzzyString(input.Date) - assert.Assert(s.t, inputAccuracy.Valid && (inputAccuracy.String == *sceneDetails.DateAccuracy), "DateAccuracy mismatch") - assert.Equal(s.t, inputDate.String, *sceneDetails.Date) + c.strPtrStrPtr(input.Date, sceneDetails.Date, "Date") s.compareURLs(input.Urls, sceneDetails.AddedUrls) @@ -119,19 +116,7 @@ func (s *sceneEditTestRunner) verifySceneEdit(input models.SceneEditDetailsInput c.strPtrNullStr(input.Code, scene.Code, "Code") c.uuidPtrNullUUID(input.StudioID, scene.StudioID, "StudioID") c.intPtrNullInt64(input.Duration, scene.Duration, "Duration") - - inputDate, inputAccuracy, _ := models.ParseFuzzyString(input.Date) - if input.Date == nil { - assert.Assert(s.t, !scene.DateAccuracy.Valid) - } else { - assert.Equal(s.t, inputAccuracy.String, scene.DateAccuracy.String) - } - - if input.Date == nil { - assert.Assert(s.t, !scene.Date.Valid) - } else { - assert.Equal(s.t, inputDate.String, scene.Date.String) - } + c.strPtrNullStr(input.Date, scene.Date, "Date") urls, _ := resolver.Urls(s.ctx, scene) s.compareURLs(input.Urls, urls) diff --git a/pkg/api/sql_resolver.go b/pkg/api/sql_resolver.go index fbd91fb8e..ce41b5954 100644 --- a/pkg/api/sql_resolver.go +++ b/pkg/api/sql_resolver.go @@ -2,6 +2,7 @@ package api import ( "database/sql" + "fmt" "github.com/stashapp/stash-box/pkg/models" "github.com/stashapp/stash-box/pkg/utils" @@ -31,25 +32,27 @@ func resolveNullInt64(value sql.NullInt64) (*int, error) { return nil, nil } -func resolveFuzzyDate(date *string, accuracy *string) *string { - if date == nil || *date == "" { +func resolveFuzzyDate(date sql.NullString) *models.FuzzyDate { + if !date.Valid { return nil } - resolvedAccuracy := models.DateAccuracyEnumDay.String() - if accuracy != nil && *accuracy != "" { - resolvedAccuracy = *accuracy - } - - switch resolvedAccuracy { - case models.DateAccuracyEnumDay.String(): - return date - case models.DateAccuracyEnumMonth.String(): - ret := (*date)[0:7] - return &ret - case models.DateAccuracyEnumYear.String(): - ret := (*date)[0:4] - return &ret + switch { + case len(date.String) == 4: + return &models.FuzzyDate{ + Accuracy: models.DateAccuracyEnumYear, + Date: fmt.Sprintf("%s-01-01", date.String), + } + case len(date.String) == 7: + return &models.FuzzyDate{ + Accuracy: models.DateAccuracyEnumMonth, + Date: fmt.Sprintf("%s-01", date.String), + } + case len(date.String) == 10: + return &models.FuzzyDate{ + Accuracy: models.DateAccuracyEnumDay, + Date: date.String, + } } return nil diff --git a/pkg/database/database.go b/pkg/database/database.go index b8144804d..824f76784 100644 --- a/pkg/database/database.go +++ b/pkg/database/database.go @@ -4,7 +4,7 @@ import ( "github.com/jmoiron/sqlx" ) -var appSchemaVersion uint = 36 +var appSchemaVersion uint = 37 var databaseProviders map[string]databaseProvider diff --git a/pkg/database/migrations/postgres/37_date_columns.up.sql b/pkg/database/migrations/postgres/37_date_columns.up.sql new file mode 100644 index 000000000..3ef6281f8 --- /dev/null +++ b/pkg/database/migrations/postgres/37_date_columns.up.sql @@ -0,0 +1,29 @@ +-- Transform scene date columns to single string column +ALTER TABLE "scenes" RENAME COLUMN "date" TO "date_old"; +ALTER TABLE "scenes" ADD COLUMN "date" TEXT; + +UPDATE "scenes" SET "date" = ( + CASE + WHEN "date_accuracy" = 'DAY' THEN TO_CHAR("date_old", 'YYYY-MM-DD') + WHEN "date_accuracy" = 'MONTH' THEN TO_CHAR("date_old", 'YYYY-MM') + WHEN "date_accuracy" = 'YEAR' THEN TO_CHAR("date_old", 'YYYY') + END +); + +ALTER TABLE "scenes" DROP COLUMN "date_old"; +ALTER TABLE "scenes" DROP COLUMN "date_accuracy"; + +-- Transform performers birthdate columns to single string column +ALTER TABLE "performers" RENAME COLUMN "birthdate" TO "birthdate_old"; +ALTER TABLE "performers" ADD COLUMN "birthdate" TEXT; + +UPDATE "performers" SET "birthdate" = ( + CASE + WHEN "birthdate_accuracy" = 'DAY' THEN TO_CHAR("birthdate_old", 'YYYY-MM-DD') + WHEN "birthdate_accuracy" = 'MONTH' THEN TO_CHAR("birthdate_old", 'YYYY-MM') + WHEN "birthdate_accuracy" = 'YEAR' THEN TO_CHAR("birthdate_old", 'YYYY') + END +); + +ALTER TABLE "performers" DROP COLUMN "birthdate_old"; +ALTER TABLE "performers" DROP COLUMN "birthdate_accuracy"; diff --git a/pkg/models/extension_edit_details.go b/pkg/models/extension_edit_details.go index 4122abebb..89c38eecd 100644 --- a/pkg/models/extension_edit_details.go +++ b/pkg/models/extension_edit_details.go @@ -61,7 +61,7 @@ func (e PerformerEditDetailsInput) PerformerEditFromDiff(orig Performer, inputAr oldData.Gender, newData.Gender = ed.nullStringEnum(orig.Gender, e.Gender) } if e.Birthdate != nil || inputArgs.Field("birthdate").IsNull() { - oldData.Birthdate, oldData.BirthdateAccuracy, newData.Birthdate, newData.BirthdateAccuracy = ed.fuzzyDate(orig.Birthdate, orig.BirthdateAccuracy, e.Birthdate) + oldData.Birthdate, newData.Birthdate = ed.nullString(orig.Birthdate, e.Birthdate) } if e.Ethnicity != nil || inputArgs.Field("ethnicity").IsNull() { oldData.Ethnicity, newData.Ethnicity = ed.nullStringEnum(orig.Ethnicity, e.Ethnicity) @@ -183,7 +183,7 @@ func (e SceneEditDetailsInput) SceneEditFromDiff(orig Scene, inputArgs utils.Arg oldData.Details, newData.Details = ed.nullString(orig.Details, e.Details) } if e.Date != nil || inputArgs.Field("date").IsNull() { - oldData.Date, oldData.DateAccuracy, newData.Date, newData.DateAccuracy = ed.fuzzyDate(orig.Date, orig.DateAccuracy, e.Date) + oldData.Date, newData.Date = ed.nullString(orig.Date, e.Date) } if e.StudioID != nil || inputArgs.Field("studio_id").IsNull() { oldData.StudioID, newData.StudioID = ed.nullUUID(orig.StudioID, e.StudioID) diff --git a/pkg/models/extension_edit_details_test.go b/pkg/models/extension_edit_details_test.go index c3d6c58e8..d63d8baf8 100644 --- a/pkg/models/extension_edit_details_test.go +++ b/pkg/models/extension_edit_details_test.go @@ -24,13 +24,7 @@ var ( aGenderStr = aGender.String() bGenderStr = bGender.String() aDate = "2001-01-01" - bDate = "2002-01-01" - aDateShort = "2001-01-01" - bDateShort = "2002-01" - aDateAcc = DateAccuracyEnumDay - bDateAcc = DateAccuracyEnumMonth - aDateAccStr = aDateAcc.String() - bDateAccStr = bDateAcc.String() + bDate = "2002-01" aEthnicity = EthnicityEnumAsian bEthnicity = EthnicityEnumBlack aEthnicityStr = aEthnicity.String() @@ -145,29 +139,28 @@ func TestTagEditFromDiff(t *testing.T) { func TestPerformerEditFromDiff(t *testing.T) { orig := Performer{ - Name: aName, - Disambiguation: sql.NullString{String: aDisambiguation, Valid: true}, - Gender: sql.NullString{String: aGender.String(), Valid: true}, - Birthdate: SQLDate{String: aDate, Valid: true}, - BirthdateAccuracy: sql.NullString{String: aDateAcc.String(), Valid: true}, - Ethnicity: sql.NullString{String: aEthnicityStr, Valid: true}, - Country: sql.NullString{String: aCountry, Valid: true}, - EyeColor: sql.NullString{String: aEyeColorStr, Valid: true}, - HairColor: sql.NullString{String: aHairColorStr, Valid: true}, - Height: sql.NullInt64{Int64: int64(aHeight), Valid: true}, - CupSize: sql.NullString{String: aCupSize, Valid: true}, - BandSize: sql.NullInt64{Int64: int64(aBandSize), Valid: true}, - WaistSize: sql.NullInt64{Int64: int64(aWaistSize), Valid: true}, - HipSize: sql.NullInt64{Int64: int64(aHipSize), Valid: true}, - BreastType: sql.NullString{String: aBreastType.String(), Valid: true}, - CareerStartYear: sql.NullInt64{Int64: int64(aStartYear), Valid: true}, - CareerEndYear: sql.NullInt64{Int64: int64(aEndYear), Valid: true}, + Name: aName, + Disambiguation: sql.NullString{String: aDisambiguation, Valid: true}, + Gender: sql.NullString{String: aGender.String(), Valid: true}, + Birthdate: sql.NullString{String: aDate, Valid: true}, + Ethnicity: sql.NullString{String: aEthnicityStr, Valid: true}, + Country: sql.NullString{String: aCountry, Valid: true}, + EyeColor: sql.NullString{String: aEyeColorStr, Valid: true}, + HairColor: sql.NullString{String: aHairColorStr, Valid: true}, + Height: sql.NullInt64{Int64: int64(aHeight), Valid: true}, + CupSize: sql.NullString{String: aCupSize, Valid: true}, + BandSize: sql.NullInt64{Int64: int64(aBandSize), Valid: true}, + WaistSize: sql.NullInt64{Int64: int64(aWaistSize), Valid: true}, + HipSize: sql.NullInt64{Int64: int64(aHipSize), Valid: true}, + BreastType: sql.NullString{String: aBreastType.String(), Valid: true}, + CareerStartYear: sql.NullInt64{Int64: int64(aStartYear), Valid: true}, + CareerEndYear: sql.NullInt64{Int64: int64(aEndYear), Valid: true}, } input := PerformerEditDetailsInput{ Name: &bName, Disambiguation: &bDisambiguation, Gender: &bGender, - Birthdate: &bDateShort, + Birthdate: &bDate, Ethnicity: &bEthnicity, Country: &bCountry, EyeColor: &bEyeColor, @@ -186,42 +179,40 @@ func TestPerformerEditFromDiff(t *testing.T) { assert.DeepEqual(t, PerformerEditData{ New: &PerformerEdit{ - Name: &bName, - Disambiguation: &bDisambiguation, - Gender: &bGenderStr, - Birthdate: &bDate, - BirthdateAccuracy: &bDateAccStr, - Ethnicity: &bEthnicityStr, - Country: &bCountry, - EyeColor: &bEyeColorStr, - HairColor: &bHairColorStr, - Height: &bHeight64, - CupSize: &bCupSize, - BandSize: &bBandSize64, - WaistSize: &bWaistSize64, - HipSize: &bHipSize64, - BreastType: &bBreastTypeStr, - CareerStartYear: &bStartYear64, - CareerEndYear: &bEndYear64, + Name: &bName, + Disambiguation: &bDisambiguation, + Gender: &bGenderStr, + Birthdate: &bDate, + Ethnicity: &bEthnicityStr, + Country: &bCountry, + EyeColor: &bEyeColorStr, + HairColor: &bHairColorStr, + Height: &bHeight64, + CupSize: &bCupSize, + BandSize: &bBandSize64, + WaistSize: &bWaistSize64, + HipSize: &bHipSize64, + BreastType: &bBreastTypeStr, + CareerStartYear: &bStartYear64, + CareerEndYear: &bEndYear64, }, Old: &PerformerEdit{ - Name: &aName, - Disambiguation: &aDisambiguation, - Gender: &aGenderStr, - Birthdate: &aDate, - BirthdateAccuracy: &aDateAccStr, - Ethnicity: &aEthnicityStr, - Country: &aCountry, - EyeColor: &aEyeColorStr, - HairColor: &aHairColorStr, - Height: &aHeight64, - CupSize: &aCupSize, - BandSize: &aBandSize64, - WaistSize: &aWaistSize64, - HipSize: &aHipSize64, - BreastType: &aBreastTypeStr, - CareerStartYear: &aStartYear64, - CareerEndYear: &aEndYear64, + Name: &aName, + Disambiguation: &aDisambiguation, + Gender: &aGenderStr, + Birthdate: &aDate, + Ethnicity: &aEthnicityStr, + Country: &aCountry, + EyeColor: &aEyeColorStr, + HairColor: &aHairColorStr, + Height: &aHeight64, + CupSize: &aCupSize, + BandSize: &aBandSize64, + WaistSize: &aWaistSize64, + HipSize: &aHipSize64, + BreastType: &aBreastTypeStr, + CareerStartYear: &aStartYear64, + CareerEndYear: &aEndYear64, }, }, *out) @@ -232,23 +223,22 @@ func TestPerformerEditFromDiff(t *testing.T) { out, _ = input.PerformerEditFromDiff(emptyOrig, mockedArguments) assert.DeepEqual(t, PerformerEditData{ New: &PerformerEdit{ - Name: &bName, - Disambiguation: &bDisambiguation, - Gender: &bGenderStr, - Birthdate: &bDate, - BirthdateAccuracy: &bDateAccStr, - Ethnicity: &bEthnicityStr, - Country: &bCountry, - EyeColor: &bEyeColorStr, - HairColor: &bHairColorStr, - Height: &bHeight64, - CupSize: &bCupSize, - BandSize: &bBandSize64, - WaistSize: &bWaistSize64, - HipSize: &bHipSize64, - BreastType: &bBreastTypeStr, - CareerStartYear: &bStartYear64, - CareerEndYear: &bEndYear64, + Name: &bName, + Disambiguation: &bDisambiguation, + Gender: &bGenderStr, + Birthdate: &bDate, + Ethnicity: &bEthnicityStr, + Country: &bCountry, + EyeColor: &bEyeColorStr, + HairColor: &bHairColorStr, + Height: &bHeight64, + CupSize: &bCupSize, + BandSize: &bBandSize64, + WaistSize: &bWaistSize64, + HipSize: &bHipSize64, + BreastType: &bBreastTypeStr, + CareerStartYear: &bStartYear64, + CareerEndYear: &bEndYear64, }, Old: &PerformerEdit{ Name: &aName, @@ -267,7 +257,7 @@ func TestPerformerEditFromDiff(t *testing.T) { Name: &aName, Disambiguation: &aDisambiguation, Gender: &aGender, - Birthdate: &aDateShort, + Birthdate: &aDate, Ethnicity: &aEthnicity, Country: &aCountry, EyeColor: &aEyeColor, diff --git a/pkg/models/generated_exec.go b/pkg/models/generated_exec.go index ddabfae1e..cd45f771e 100644 --- a/pkg/models/generated_exec.go +++ b/pkg/models/generated_exec.go @@ -728,7 +728,6 @@ type PerformerDraftResolver interface { type PerformerEditResolver interface { Gender(ctx context.Context, obj *PerformerEdit) (*GenderEnum, error) - Birthdate(ctx context.Context, obj *PerformerEdit) (*string, error) Ethnicity(ctx context.Context, obj *PerformerEdit) (*EthnicityEnum, error) EyeColor(ctx context.Context, obj *PerformerEdit) (*EyeColorEnum, error) @@ -820,7 +819,6 @@ type SceneDraftResolver interface { Image(ctx context.Context, obj *SceneDraft) (*Image, error) } type SceneEditResolver interface { - Date(ctx context.Context, obj *SceneEdit) (*string, error) Studio(ctx context.Context, obj *SceneEdit) (*Studio, error) AddedPerformers(ctx context.Context, obj *SceneEdit) ([]*PerformerAppearance, error) RemovedPerformers(ctx context.Context, obj *SceneEdit) ([]*PerformerAppearance, error) @@ -17258,7 +17256,7 @@ func (ec *executionContext) _PerformerEdit_birthdate(ctx context.Context, field }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.PerformerEdit().Birthdate(rctx, obj) + return obj.Birthdate, nil }) if err != nil { ec.Error(ctx, err) @@ -17276,8 +17274,8 @@ func (ec *executionContext) fieldContext_PerformerEdit_birthdate(ctx context.Con fc = &graphql.FieldContext{ Object: "PerformerEdit", Field: field, - IsMethod: true, - IsResolver: true, + IsMethod: false, + IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { return nil, errors.New("field of type String does not have child fields") }, @@ -24239,7 +24237,7 @@ func (ec *executionContext) _SceneEdit_date(ctx context.Context, field graphql.C }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.SceneEdit().Date(rctx, obj) + return obj.Date, nil }) if err != nil { ec.Error(ctx, err) @@ -24257,8 +24255,8 @@ func (ec *executionContext) fieldContext_SceneEdit_date(ctx context.Context, fie fc = &graphql.FieldContext{ Object: "SceneEdit", Field: field, - IsMethod: true, - IsResolver: true, + IsMethod: false, + IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { return nil, errors.New("field of type String does not have child fields") }, @@ -38754,38 +38752,7 @@ func (ec *executionContext) _PerformerEdit(ctx context.Context, sel ast.Selectio case "removed_urls": out.Values[i] = ec._PerformerEdit_removed_urls(ctx, field, obj) case "birthdate": - field := field - - innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - } - }() - res = ec._PerformerEdit_birthdate(ctx, field, obj) - return res - } - - if field.Deferrable != nil { - dfs, ok := deferred[field.Deferrable.Label] - di := 0 - if ok { - dfs.AddField(field) - di = len(dfs.Values) - 1 - } else { - dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) - deferred[field.Deferrable.Label] = dfs - } - dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { - return innerFunc(ctx, dfs) - }) - - // don't run the out.Concurrently() call below - out.Values[i] = graphql.Null - continue - } - - out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + out.Values[i] = ec._PerformerEdit_birthdate(ctx, field, obj) case "ethnicity": field := field @@ -41438,38 +41405,7 @@ func (ec *executionContext) _SceneEdit(ctx context.Context, sel ast.SelectionSet case "removed_urls": out.Values[i] = ec._SceneEdit_removed_urls(ctx, field, obj) case "date": - field := field - - innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - } - }() - res = ec._SceneEdit_date(ctx, field, obj) - return res - } - - if field.Deferrable != nil { - dfs, ok := deferred[field.Deferrable.Label] - di := 0 - if ok { - dfs.AddField(field) - di = len(dfs.Values) - 1 - } else { - dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) - deferred[field.Deferrable.Label] = dfs - } - dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { - return innerFunc(ctx, dfs) - }) - - // don't run the out.Concurrently() call below - out.Values[i] = graphql.Null - continue - } - - out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + out.Values[i] = ec._SceneEdit_date(ctx, field, obj) case "studio": field := field diff --git a/pkg/models/model_edit.go b/pkg/models/model_edit.go index 79c4560a0..2aebfa593 100644 --- a/pkg/models/model_edit.go +++ b/pkg/models/model_edit.go @@ -302,35 +302,34 @@ type TagEditData struct { func (PerformerEdit) IsEditDetails() {} type PerformerEdit struct { - EditID uuid.UUID `json:"-"` - Name *string `json:"name,omitempty"` - Disambiguation *string `json:"disambiguation,omitempty"` - AddedAliases []string `json:"added_aliases,omitempty"` - RemovedAliases []string `json:"removed_aliases,omitempty"` - Gender *string `json:"gender,omitempty"` - AddedUrls []*URL `json:"added_urls,omitempty"` - RemovedUrls []*URL `json:"removed_urls,omitempty"` - Birthdate *string `json:"birthdate,omitempty"` - BirthdateAccuracy *string `json:"birthdate_accuracy,omitempty"` - Ethnicity *string `json:"ethnicity,omitempty"` - Country *string `json:"country,omitempty"` - EyeColor *string `json:"eye_color,omitempty"` - HairColor *string `json:"hair_color,omitempty"` - Height *int64 `json:"height,omitempty"` - CupSize *string `json:"cup_size,omitempty"` - BandSize *int64 `json:"band_size,omitempty"` - WaistSize *int64 `json:"waist_size,omitempty"` - HipSize *int64 `json:"hip_size,omitempty"` - BreastType *string `json:"breast_type,omitempty"` - CareerStartYear *int64 `json:"career_start_year,omitempty"` - CareerEndYear *int64 `json:"career_end_year,omitempty"` - AddedTattoos []*BodyModification `json:"added_tattoos,omitempty"` - RemovedTattoos []*BodyModification `json:"removed_tattoos,omitempty"` - AddedPiercings []*BodyModification `json:"added_piercings,omitempty"` - RemovedPiercings []*BodyModification `json:"removed_piercings,omitempty"` - AddedImages []uuid.UUID `json:"added_images,omitempty"` - RemovedImages []uuid.UUID `json:"removed_images,omitempty"` - DraftID *uuid.UUID `json:"draft_id,omitempty"` + EditID uuid.UUID `json:"-"` + Name *string `json:"name,omitempty"` + Disambiguation *string `json:"disambiguation,omitempty"` + AddedAliases []string `json:"added_aliases,omitempty"` + RemovedAliases []string `json:"removed_aliases,omitempty"` + Gender *string `json:"gender,omitempty"` + AddedUrls []*URL `json:"added_urls,omitempty"` + RemovedUrls []*URL `json:"removed_urls,omitempty"` + Birthdate *string `json:"birthdate,omitempty"` + Ethnicity *string `json:"ethnicity,omitempty"` + Country *string `json:"country,omitempty"` + EyeColor *string `json:"eye_color,omitempty"` + HairColor *string `json:"hair_color,omitempty"` + Height *int64 `json:"height,omitempty"` + CupSize *string `json:"cup_size,omitempty"` + BandSize *int64 `json:"band_size,omitempty"` + WaistSize *int64 `json:"waist_size,omitempty"` + HipSize *int64 `json:"hip_size,omitempty"` + BreastType *string `json:"breast_type,omitempty"` + CareerStartYear *int64 `json:"career_start_year,omitempty"` + CareerEndYear *int64 `json:"career_end_year,omitempty"` + AddedTattoos []*BodyModification `json:"added_tattoos,omitempty"` + RemovedTattoos []*BodyModification `json:"removed_tattoos,omitempty"` + AddedPiercings []*BodyModification `json:"added_piercings,omitempty"` + RemovedPiercings []*BodyModification `json:"removed_piercings,omitempty"` + AddedImages []uuid.UUID `json:"added_images,omitempty"` + RemovedImages []uuid.UUID `json:"removed_images,omitempty"` + DraftID *uuid.UUID `json:"draft_id,omitempty"` } type PerformerEditData struct { @@ -367,7 +366,6 @@ type SceneEdit struct { AddedUrls []*URL `json:"added_urls,omitempty"` RemovedUrls []*URL `json:"removed_urls,omitempty"` Date *string `json:"date,omitempty"` - DateAccuracy *string `json:"date_accuracy,omitempty"` StudioID *uuid.UUID `json:"studio_id,omitempty"` AddedPerformers []*PerformerAppearanceInput `json:"added_performers,omitempty"` RemovedPerformers []*PerformerAppearanceInput `json:"removed_performers,omitempty"` diff --git a/pkg/models/model_performer.go b/pkg/models/model_performer.go index e067be128..01303bf65 100644 --- a/pkg/models/model_performer.go +++ b/pkg/models/model_performer.go @@ -9,27 +9,26 @@ import ( ) type Performer struct { - ID uuid.UUID `db:"id" json:"id"` - Name string `db:"name" json:"name"` - Disambiguation sql.NullString `db:"disambiguation" json:"disambiguation"` - Gender sql.NullString `db:"gender" json:"gender"` - Birthdate SQLDate `db:"birthdate" json:"birthdate"` - BirthdateAccuracy sql.NullString `db:"birthdate_accuracy" json:"birthdate_accuracy"` - Ethnicity sql.NullString `db:"ethnicity" json:"ethnicity"` - Country sql.NullString `db:"country" json:"country"` - EyeColor sql.NullString `db:"eye_color" json:"eye_color"` - HairColor sql.NullString `db:"hair_color" json:"hair_color"` - Height sql.NullInt64 `db:"height" json:"height"` - CupSize sql.NullString `db:"cup_size" json:"cup_size"` - BandSize sql.NullInt64 `db:"band_size" json:"band_size"` - WaistSize sql.NullInt64 `db:"waist_size" json:"waist_size"` - HipSize sql.NullInt64 `db:"hip_size" json:"hip_size"` - BreastType sql.NullString `db:"breast_type" json:"breast_type"` - CareerStartYear sql.NullInt64 `db:"career_start_year" json:"career_start_year"` - CareerEndYear sql.NullInt64 `db:"career_end_year" json:"career_end_year"` - CreatedAt time.Time `db:"created_at" json:"created_at"` - UpdatedAt time.Time `db:"updated_at" json:"updated_at"` - Deleted bool `db:"deleted" json:"deleted"` + ID uuid.UUID `db:"id" json:"id"` + Name string `db:"name" json:"name"` + Disambiguation sql.NullString `db:"disambiguation" json:"disambiguation"` + Gender sql.NullString `db:"gender" json:"gender"` + Birthdate sql.NullString `db:"birthdate" json:"birthdate"` + Ethnicity sql.NullString `db:"ethnicity" json:"ethnicity"` + Country sql.NullString `db:"country" json:"country"` + EyeColor sql.NullString `db:"eye_color" json:"eye_color"` + HairColor sql.NullString `db:"hair_color" json:"hair_color"` + Height sql.NullInt64 `db:"height" json:"height"` + CupSize sql.NullString `db:"cup_size" json:"cup_size"` + BandSize sql.NullInt64 `db:"band_size" json:"band_size"` + WaistSize sql.NullInt64 `db:"waist_size" json:"waist_size"` + HipSize sql.NullInt64 `db:"hip_size" json:"hip_size"` + BreastType sql.NullString `db:"breast_type" json:"breast_type"` + CareerStartYear sql.NullInt64 `db:"career_start_year" json:"career_start_year"` + CareerEndYear sql.NullInt64 `db:"career_end_year" json:"career_end_year"` + CreatedAt time.Time `db:"created_at" json:"created_at"` + UpdatedAt time.Time `db:"updated_at" json:"updated_at"` + Deleted bool `db:"deleted" json:"deleted"` } func (Performer) IsSceneDraftPerformer() {} @@ -286,22 +285,6 @@ func CreatePerformerBodyMods(performerID uuid.UUID, urls []*BodyModification) Pe func (p *Performer) IsEditTarget() { } -func (p Performer) ResolveBirthdate() FuzzyDate { - ret := FuzzyDate{} - - if p.Birthdate.Valid { - ret.Date = p.Birthdate.String - } - if p.BirthdateAccuracy.Valid { - ret.Accuracy = DateAccuracyEnum(p.BirthdateAccuracy.String) - if !ret.Accuracy.IsValid() { - ret.Accuracy = "" - } - } - - return ret -} - func (p Performer) ResolveMeasurements() Measurements { ret := Measurements{} @@ -327,30 +310,12 @@ func (p Performer) ResolveMeasurements() Measurements { func (p *Performer) CopyFromCreateInput(input PerformerCreateInput) error { CopyFull(p, input) - if input.Birthdate != nil { - date, accuracy, err := ParseFuzzyString(input.Birthdate) - if err != nil { - return err - } - p.Birthdate = date - p.BirthdateAccuracy = accuracy - } - return nil } func (p *Performer) CopyFromUpdateInput(input PerformerUpdateInput) error { CopyFull(p, input) - if input.Birthdate != nil { - date, accuracy, err := ParseFuzzyString(input.Birthdate) - if err != nil { - return err - } - p.Birthdate = date - p.BirthdateAccuracy = accuracy - } - return nil } @@ -384,8 +349,7 @@ func (p *Performer) CopyFromPerformerEdit(input PerformerEdit, old PerformerEdit fe.nullInt64(&p.BandSize, input.BandSize, old.BandSize) fe.nullInt64(&p.HipSize, input.HipSize, old.HipSize) fe.nullInt64(&p.WaistSize, input.WaistSize, old.WaistSize) - fe.sqlDate(&p.Birthdate, input.Birthdate, old.Birthdate) - fe.nullString(&p.BirthdateAccuracy, input.BirthdateAccuracy, old.BirthdateAccuracy) + fe.nullString(&p.Birthdate, input.Birthdate, old.Birthdate) p.UpdatedAt = time.Now() } @@ -409,7 +373,6 @@ func (p *Performer) ValidateModifyEdit(edit PerformerEditData) error { v.int64("hip size", edit.Old.HipSize, p.HipSize.Int64) v.int64("waist size", edit.Old.WaistSize, p.WaistSize.Int64) v.string("birthdate", edit.Old.Birthdate, p.Birthdate.String) - v.string("birthdate accuracy", edit.Old.BirthdateAccuracy, p.BirthdateAccuracy.String) return v.err } diff --git a/pkg/models/model_performer_test.go b/pkg/models/model_performer_test.go index 2d34b9391..4a208fa1c 100644 --- a/pkg/models/model_performer_test.go +++ b/pkg/models/model_performer_test.go @@ -9,87 +9,83 @@ import ( func TestCopyFromPerformerEdit(t *testing.T) { input := PerformerEdit{ - Name: &bName, - Disambiguation: &bDisambiguation, - Gender: &bGenderStr, - Birthdate: &bDate, - BirthdateAccuracy: &bDateAccStr, - Ethnicity: &bEthnicityStr, - Country: &bCountry, - EyeColor: &bEyeColorStr, - HairColor: &bHairColorStr, - Height: &bHeight64, - CupSize: &bCupSize, - BandSize: &bBandSize64, - WaistSize: &bWaistSize64, - HipSize: &bHipSize64, - BreastType: &bBreastTypeStr, - CareerStartYear: &bStartYear64, - CareerEndYear: &bEndYear64, + Name: &bName, + Disambiguation: &bDisambiguation, + Gender: &bGenderStr, + Birthdate: &bDate, + Ethnicity: &bEthnicityStr, + Country: &bCountry, + EyeColor: &bEyeColorStr, + HairColor: &bHairColorStr, + Height: &bHeight64, + CupSize: &bCupSize, + BandSize: &bBandSize64, + WaistSize: &bWaistSize64, + HipSize: &bHipSize64, + BreastType: &bBreastTypeStr, + CareerStartYear: &bStartYear64, + CareerEndYear: &bEndYear64, } old := PerformerEdit{ - Name: &aName, - Disambiguation: &aDisambiguation, - Gender: &aGenderStr, - Birthdate: &aDate, - BirthdateAccuracy: &aDateAccStr, - Ethnicity: &aEthnicityStr, - Country: &aCountry, - EyeColor: &aEyeColorStr, - HairColor: &aHairColorStr, - Height: &aHeight64, - CupSize: &aCupSize, - BandSize: &aBandSize64, - WaistSize: &aWaistSize64, - HipSize: &aHipSize64, - BreastType: &aBreastTypeStr, - CareerStartYear: &aStartYear64, - CareerEndYear: &aEndYear64, + Name: &aName, + Disambiguation: &aDisambiguation, + Gender: &aGenderStr, + Birthdate: &aDate, + Ethnicity: &aEthnicityStr, + Country: &aCountry, + EyeColor: &aEyeColorStr, + HairColor: &aHairColorStr, + Height: &aHeight64, + CupSize: &aCupSize, + BandSize: &aBandSize64, + WaistSize: &aWaistSize64, + HipSize: &aHipSize64, + BreastType: &aBreastTypeStr, + CareerStartYear: &aStartYear64, + CareerEndYear: &aEndYear64, } orig := Performer{ - Name: aName, - Disambiguation: sql.NullString{String: aDisambiguation, Valid: true}, - Gender: sql.NullString{String: aGender.String(), Valid: true}, - Birthdate: SQLDate{String: aDate, Valid: true}, - BirthdateAccuracy: sql.NullString{String: aDateAcc.String(), Valid: true}, - Ethnicity: sql.NullString{String: aEthnicityStr, Valid: true}, - Country: sql.NullString{String: aCountry, Valid: true}, - EyeColor: sql.NullString{String: aEyeColorStr, Valid: true}, - HairColor: sql.NullString{String: aHairColorStr, Valid: true}, - Height: sql.NullInt64{Int64: int64(aHeight), Valid: true}, - CupSize: sql.NullString{String: aCupSize, Valid: true}, - BandSize: sql.NullInt64{Int64: int64(aBandSize), Valid: true}, - WaistSize: sql.NullInt64{Int64: int64(aWaistSize), Valid: true}, - HipSize: sql.NullInt64{Int64: int64(aHipSize), Valid: true}, - BreastType: sql.NullString{String: aBreastType.String(), Valid: true}, - CareerStartYear: sql.NullInt64{Int64: int64(aStartYear), Valid: true}, - CareerEndYear: sql.NullInt64{Int64: int64(aEndYear), Valid: true}, + Name: aName, + Disambiguation: sql.NullString{String: aDisambiguation, Valid: true}, + Gender: sql.NullString{String: aGender.String(), Valid: true}, + Birthdate: sql.NullString{String: aDate, Valid: true}, + Ethnicity: sql.NullString{String: aEthnicityStr, Valid: true}, + Country: sql.NullString{String: aCountry, Valid: true}, + EyeColor: sql.NullString{String: aEyeColorStr, Valid: true}, + HairColor: sql.NullString{String: aHairColorStr, Valid: true}, + Height: sql.NullInt64{Int64: int64(aHeight), Valid: true}, + CupSize: sql.NullString{String: aCupSize, Valid: true}, + BandSize: sql.NullInt64{Int64: int64(aBandSize), Valid: true}, + WaistSize: sql.NullInt64{Int64: int64(aWaistSize), Valid: true}, + HipSize: sql.NullInt64{Int64: int64(aHipSize), Valid: true}, + BreastType: sql.NullString{String: aBreastType.String(), Valid: true}, + CareerStartYear: sql.NullInt64{Int64: int64(aStartYear), Valid: true}, + CareerEndYear: sql.NullInt64{Int64: int64(aEndYear), Valid: true}, } origCopy := orig origCopy.CopyFromPerformerEdit(input, old) assert.DeepEqual(t, Performer{ - Name: bName, - Disambiguation: sql.NullString{String: bDisambiguation, Valid: true}, - Gender: sql.NullString{String: bGender.String(), Valid: true}, - Birthdate: SQLDate{String: bDate, Valid: true}, - BirthdateAccuracy: sql.NullString{String: bDateAcc.String(), Valid: true}, - Ethnicity: sql.NullString{String: bEthnicityStr, Valid: true}, - Country: sql.NullString{String: bCountry, Valid: true}, - EyeColor: sql.NullString{String: bEyeColorStr, Valid: true}, - HairColor: sql.NullString{String: bHairColorStr, Valid: true}, - Height: sql.NullInt64{Int64: int64(bHeight), Valid: true}, - CupSize: sql.NullString{String: bCupSize, Valid: true}, - BandSize: sql.NullInt64{Int64: int64(bBandSize), Valid: true}, - WaistSize: sql.NullInt64{Int64: int64(bWaistSize), Valid: true}, - HipSize: sql.NullInt64{Int64: int64(bHipSize), Valid: true}, - BreastType: sql.NullString{String: bBreastType.String(), Valid: true}, - CareerStartYear: sql.NullInt64{Int64: int64(bStartYear), Valid: true}, - CareerEndYear: sql.NullInt64{Int64: int64(bEndYear), Valid: true}, - UpdatedAt: origCopy.UpdatedAt, + Name: bName, + Disambiguation: sql.NullString{String: bDisambiguation, Valid: true}, + Gender: sql.NullString{String: bGender.String(), Valid: true}, + Birthdate: sql.NullString{String: bDate, Valid: true}, + Ethnicity: sql.NullString{String: bEthnicityStr, Valid: true}, + Country: sql.NullString{String: bCountry, Valid: true}, + EyeColor: sql.NullString{String: bEyeColorStr, Valid: true}, + HairColor: sql.NullString{String: bHairColorStr, Valid: true}, + Height: sql.NullInt64{Int64: int64(bHeight), Valid: true}, + CupSize: sql.NullString{String: bCupSize, Valid: true}, + BandSize: sql.NullInt64{Int64: int64(bBandSize), Valid: true}, + WaistSize: sql.NullInt64{Int64: int64(bWaistSize), Valid: true}, + HipSize: sql.NullInt64{Int64: int64(bHipSize), Valid: true}, + BreastType: sql.NullString{String: bBreastType.String(), Valid: true}, + CareerStartYear: sql.NullInt64{Int64: int64(bStartYear), Valid: true}, + CareerEndYear: sql.NullInt64{Int64: int64(bEndYear), Valid: true}, + UpdatedAt: origCopy.UpdatedAt, }, origCopy) origCopy = orig diff --git a/pkg/models/model_scene.go b/pkg/models/model_scene.go index 1467172ca..04289a870 100644 --- a/pkg/models/model_scene.go +++ b/pkg/models/model_scene.go @@ -8,18 +8,17 @@ import ( ) type Scene struct { - ID uuid.UUID `db:"id" json:"id"` - Title sql.NullString `db:"title" json:"title"` - Details sql.NullString `db:"details" json:"details"` - Date SQLDate `db:"date" json:"date"` - DateAccuracy sql.NullString `db:"date_accuracy" json:"date_accuracy"` - StudioID uuid.NullUUID `db:"studio_id,omitempty" json:"studio_id"` - CreatedAt time.Time `db:"created_at" json:"created_at"` - UpdatedAt time.Time `db:"updated_at" json:"updated_at"` - Duration sql.NullInt64 `db:"duration" json:"duration"` - Director sql.NullString `db:"director" json:"director"` - Code sql.NullString `db:"code" json:"code"` - Deleted bool `db:"deleted" json:"deleted"` + ID uuid.UUID `db:"id" json:"id"` + Title sql.NullString `db:"title" json:"title"` + Details sql.NullString `db:"details" json:"details"` + Date sql.NullString `db:"date" json:"date"` + StudioID uuid.NullUUID `db:"studio_id,omitempty" json:"studio_id"` + CreatedAt time.Time `db:"created_at" json:"created_at"` + UpdatedAt time.Time `db:"updated_at" json:"updated_at"` + Duration sql.NullInt64 `db:"duration" json:"duration"` + Director sql.NullString `db:"director" json:"director"` + Code sql.NullString `db:"code" json:"code"` + Deleted bool `db:"deleted" json:"deleted"` } func (p Scene) GetID() uuid.UUID { @@ -239,46 +238,15 @@ func CreateScenePerformers(sceneID uuid.UUID, appearances []*PerformerAppearance func (p *Scene) IsEditTarget() { } -func (p Scene) ResolveDate() *FuzzyDate { - if !p.Date.Valid { - return nil - } - - ret := FuzzyDate{Date: p.Date.String} - - if p.DateAccuracy.Valid { - ret.Accuracy = DateAccuracyEnum(p.DateAccuracy.String) - if !ret.Accuracy.IsValid() { - ret.Accuracy = "" - } - } - - return &ret -} - func (p *Scene) CopyFromCreateInput(input SceneCreateInput) error { CopyFull(p, input) - date, accuracy, err := ParseFuzzyString(&input.Date) - if err != nil { - return err - } - p.Date = date - p.DateAccuracy = accuracy - return nil } func (p *Scene) CopyFromUpdateInput(input SceneUpdateInput) error { CopyFull(p, input) - date, accuracy, err := ParseFuzzyString(input.Date) - if err != nil { - return err - } - p.Date = date - p.DateAccuracy = accuracy - return nil } @@ -290,11 +258,7 @@ func (p *Scene) CopyFromSceneEdit(input SceneEdit, old *SceneEdit) { fe.nullInt64(&p.Duration, input.Duration, old.Duration) fe.nullString(&p.Director, input.Director, old.Director) fe.nullString(&p.Code, input.Code, old.Code) - fe.sqlDate(&p.Date, input.Date, old.Date) - fe.nullString(&p.DateAccuracy, input.DateAccuracy, old.DateAccuracy) - if input.DateAccuracy == nil && input.Date != nil { - p.DateAccuracy = sql.NullString{String: DateAccuracyEnumDay.String(), Valid: true} - } + fe.nullString(&p.Date, input.Date, old.Date) } func (p *Scene) ValidateModifyEdit(edit SceneEditData) error { @@ -303,7 +267,6 @@ func (p *Scene) ValidateModifyEdit(edit SceneEditData) error { v.string("Title", edit.Old.Title, p.Title.String) v.string("Details", edit.Old.Details, p.Details.String) v.string("Date", edit.Old.Date, p.Date.String) - v.string("Date Accuracy", edit.Old.DateAccuracy, p.DateAccuracy.String) v.uuid("StudioID", edit.Old.StudioID, p.StudioID) v.int64("Duration", edit.Old.Duration, p.Duration.Int64) v.string("Director", edit.Old.Director, p.Director.String) diff --git a/pkg/models/translate.go b/pkg/models/translate.go index cba9f3c20..07f2b364d 100644 --- a/pkg/models/translate.go +++ b/pkg/models/translate.go @@ -153,30 +153,6 @@ func (d *editDiff) nullStringEnum(old sql.NullString, new stringEnum) (oldOut *s return } -func (d *editDiff) fuzzyDate(oldDate SQLDate, oldAcc sql.NullString, new *string) (outOldDate, outOldAcc, outNewDate, outNewAcc *string) { - if new == nil && oldDate.Valid { - outOldDate = &oldDate.String - if oldAcc.Valid { - outOldAcc = &oldAcc.String - } - } else if new != nil { - newDate, newAccuracy, _ := ParseFuzzyString(new) - if !oldDate.Valid || newDate.String != oldDate.String || newAccuracy.String != oldAcc.String { - outNewDate = &newDate.String - newAccuracy := newAccuracy.String - outNewAcc = &newAccuracy - if oldDate.Valid { - outOldDate = &oldDate.String - } - if oldAcc.Valid { - outOldAcc = &oldAcc.String - } - } - } - - return -} - //nolint:unused func (d *editDiff) sqlDate(old SQLDate, new *string) (oldOut *string, newOut *string) { if old.Valid && (new == nil || *new != old.String) { From a8408acb962f206a35d7b67eba8e199053dc0ecc Mon Sep 17 00:00:00 2001 From: InfiniteStash <117855276+InfiniteStash@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:11:40 +0000 Subject: [PATCH 2/3] Linting --- pkg/models/translate.go | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/pkg/models/translate.go b/pkg/models/translate.go index 07f2b364d..cb97a3386 100644 --- a/pkg/models/translate.go +++ b/pkg/models/translate.go @@ -56,15 +56,6 @@ func (c *fromEdit) nullInt64(out *sql.NullInt64, in *int64, old *int64) { } } -func (c *fromEdit) sqlDate(out *SQLDate, in *string, old *string) { - if in != nil { - out.String = *in - out.Valid = true - } else if old != nil { - *out = SQLDate{} - } -} - func (c *fromEdit) nullUUID(out *uuid.NullUUID, in *uuid.UUID, old *uuid.UUID) { if in != nil { out.UUID = *in @@ -153,21 +144,6 @@ func (d *editDiff) nullStringEnum(old sql.NullString, new stringEnum) (oldOut *s return } -//nolint:unused -func (d *editDiff) sqlDate(old SQLDate, new *string) (oldOut *string, newOut *string) { - if old.Valid && (new == nil || *new != old.String) { - oldVal := old.String - oldOut = &oldVal - } - - if new != nil && (!old.Valid || *new != old.String) { - newVal := *new - newOut = &newVal - } - - return -} - type editValidator struct { err error } From 71b4aa6956d1f4fc9a97fda19c8ff3b7c8e61a76 Mon Sep 17 00:00:00 2001 From: InfiniteStash <117855276+InfiniteStash@users.noreply.github.com> Date: Sat, 31 Aug 2024 11:13:59 +0000 Subject: [PATCH 3/3] Lint --- pkg/models/sql_translate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/models/sql_translate.go b/pkg/models/sql_translate.go index 870721869..289eb3220 100644 --- a/pkg/models/sql_translate.go +++ b/pkg/models/sql_translate.go @@ -49,7 +49,7 @@ func CopyFull(target interface{}, source interface{}) { case field.Type == sourceField.Type: // direct copy targetFieldValue.Set(sourceFieldValue) - case reflect.PtrTo(field.Type) == sourceField.Type: + case reflect.PointerTo(field.Type) == sourceField.Type: // source field is pointer, target field is value // if nil, then set to zero value, otherwise copy if sourceFieldValue.IsNil() {