From d06b8f794960095deaab949fc6823979e8b6c1e0 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Mon, 9 Feb 2026 19:03:27 +0000 Subject: [PATCH] Add mode data to pool upload rows, move to fileupload schema This allows users to review the data before committing it to the database --- .../{pool.bob.go => fileupload.pool.bob.go} | 6 +- .../{pool.bob.go => fileupload.pool.bob.go} | 132 +- db/enums/enums.bob.go | 158 +- db/factory/bobfactory_context.bob.go | 16 +- db/factory/bobfactory_main.bob.go | 135 +- db/factory/bobfactory_random.bob.go | 20 +- db/factory/fileupload.csv.bob.go | 86 + db/factory/fileupload.pool.bob.go | 1441 ++++++++++++++++ db/factory/organization.bob.go | 190 +-- db/factory/pool.bob.go | 1121 ------------- db/factory/user_.bob.go | 194 +-- db/migrations/00057_csv_pool_upload.sql | 17 +- db/models/bob_joins.bob.go | 4 +- db/models/bob_loaders.bob.go | 8 +- db/models/bob_where.bob.go | 6 +- db/models/fileupload.csv.bob.go | 254 +++ db/models/fileupload.pool.bob.go | 1443 +++++++++++++++++ db/models/organization.bob.go | 508 +++--- db/models/pool.bob.go | 1142 ------------- db/models/user_.bob.go | 508 +++--- platform/csv/pool.go | 17 +- platform/pool.go | 39 + sync/pool.go | 22 +- 23 files changed, 4285 insertions(+), 3182 deletions(-) rename db/dberrors/{pool.bob.go => fileupload.pool.bob.go} (74%) rename db/dbinfo/{pool.bob.go => fileupload.pool.bob.go} (61%) create mode 100644 db/factory/fileupload.pool.bob.go delete mode 100644 db/factory/pool.bob.go create mode 100644 db/models/fileupload.pool.bob.go delete mode 100644 db/models/pool.bob.go diff --git a/db/dberrors/pool.bob.go b/db/dberrors/fileupload.pool.bob.go similarity index 74% rename from db/dberrors/pool.bob.go rename to db/dberrors/fileupload.pool.bob.go index b6b447da..457407fa 100644 --- a/db/dberrors/pool.bob.go +++ b/db/dberrors/fileupload.pool.bob.go @@ -3,15 +3,15 @@ package dberrors -var PoolErrors = &poolErrors{ +var FileuploadPoolErrors = &fileuploadPoolErrors{ ErrUniquePoolPkey: &UniqueConstraintError{ - schema: "", + schema: "fileupload", table: "pool", columns: []string{"id", "version"}, s: "pool_pkey", }, } -type poolErrors struct { +type fileuploadPoolErrors struct { ErrUniquePoolPkey *UniqueConstraintError } diff --git a/db/dbinfo/pool.bob.go b/db/dbinfo/fileupload.pool.bob.go similarity index 61% rename from db/dbinfo/pool.bob.go rename to db/dbinfo/fileupload.pool.bob.go index 9b59edcf..4b7a6635 100644 --- a/db/dbinfo/pool.bob.go +++ b/db/dbinfo/fileupload.pool.bob.go @@ -5,16 +5,16 @@ package dbinfo import "github.com/aarondl/opt/null" -var Pools = Table[ - poolColumns, - poolIndexes, - poolForeignKeys, - poolUniques, - poolChecks, +var FileuploadPools = Table[ + fileuploadPoolColumns, + fileuploadPoolIndexes, + fileuploadPoolForeignKeys, + fileuploadPoolUniques, + fileuploadPoolChecks, ]{ - Schema: "", + Schema: "fileupload", Name: "pool", - Columns: poolColumns{ + Columns: fileuploadPoolColumns{ AddressCity: column{ Name: "address_city", DBType: "text", @@ -42,9 +42,18 @@ var Pools = Table[ Generated: false, AutoIncr: false, }, + Committed: column{ + Name: "committed", + DBType: "boolean", + Default: "", + Comment: "", + Nullable: false, + Generated: false, + AutoIncr: false, + }, Condition: column{ Name: "condition", - DBType: "public.poolconditiontype", + DBType: "fileupload.poolconditiontype", Default: "", Comment: "", Nullable: false, @@ -69,6 +78,15 @@ var Pools = Table[ Generated: false, AutoIncr: false, }, + CSVFile: column{ + Name: "csv_file", + DBType: "integer", + Default: "", + Comment: "", + Nullable: false, + Generated: false, + AutoIncr: false, + }, Deleted: column{ Name: "deleted", DBType: "timestamp without time zone", @@ -78,8 +96,35 @@ var Pools = Table[ Generated: false, AutoIncr: false, }, - Committed: column{ - Name: "committed", + Geom: column{ + Name: "geom", + DBType: "geometry", + Default: "NULL", + Comment: "", + Nullable: true, + Generated: false, + AutoIncr: false, + }, + H3cell: column{ + Name: "h3cell", + DBType: "h3index", + Default: "NULL", + Comment: "", + Nullable: true, + Generated: false, + AutoIncr: false, + }, + ID: column{ + Name: "id", + DBType: "integer", + Default: "nextval('fileupload.pool_id_seq'::regclass)", + Comment: "", + Nullable: false, + Generated: false, + AutoIncr: false, + }, + IsInDistrict: column{ + Name: "is_in_district", DBType: "boolean", Default: "", Comment: "", @@ -87,10 +132,10 @@ var Pools = Table[ Generated: false, AutoIncr: false, }, - ID: column{ - Name: "id", - DBType: "integer", - Default: "nextval('pool_id_seq'::regclass)", + IsNew: column{ + Name: "is_new", + DBType: "boolean", + Default: "", Comment: "", Nullable: false, Generated: false, @@ -160,7 +205,7 @@ var Pools = Table[ AutoIncr: false, }, }, - Indexes: poolIndexes{ + Indexes: fileuploadPoolIndexes{ PoolPkey: index{ Type: "btree", Name: "pool_pkey", @@ -189,19 +234,28 @@ var Pools = Table[ Columns: []string{"id", "version"}, Comment: "", }, - ForeignKeys: poolForeignKeys{ - PoolPoolCreatorIDFkey: foreignKey{ + ForeignKeys: fileuploadPoolForeignKeys{ + FileuploadPoolPoolCreatorIDFkey: foreignKey{ constraint: constraint{ - Name: "pool.pool_creator_id_fkey", + Name: "fileupload.pool.pool_creator_id_fkey", Columns: []string{"creator_id"}, Comment: "", }, ForeignTable: "user_", ForeignColumns: []string{"id"}, }, - PoolPoolOrganizationIDFkey: foreignKey{ + FileuploadPoolPoolCSVFileFkey: foreignKey{ constraint: constraint{ - Name: "pool.pool_organization_id_fkey", + Name: "fileupload.pool.pool_csv_file_fkey", + Columns: []string{"csv_file"}, + Comment: "", + }, + ForeignTable: "fileupload.csv", + ForeignColumns: []string{"file_id"}, + }, + FileuploadPoolPoolOrganizationIDFkey: foreignKey{ + constraint: constraint{ + Name: "fileupload.pool.pool_organization_id_fkey", Columns: []string{"organization_id"}, Comment: "", }, @@ -213,16 +267,21 @@ var Pools = Table[ Comment: "", } -type poolColumns struct { +type fileuploadPoolColumns struct { AddressCity column AddressPostalCode column AddressStreet column + Committed column Condition column Created column CreatorID column + CSVFile column Deleted column - Committed column + Geom column + H3cell column ID column + IsInDistrict column + IsNew column Notes column OrganizationID column PropertyOwnerName column @@ -232,41 +291,42 @@ type poolColumns struct { Version column } -func (c poolColumns) AsSlice() []column { +func (c fileuploadPoolColumns) AsSlice() []column { return []column{ - c.AddressCity, c.AddressPostalCode, c.AddressStreet, c.Condition, c.Created, c.CreatorID, c.Deleted, c.Committed, c.ID, c.Notes, c.OrganizationID, c.PropertyOwnerName, c.PropertyOwnerPhone, c.ResidentOwned, c.ResidentPhone, c.Version, + c.AddressCity, c.AddressPostalCode, c.AddressStreet, c.Committed, c.Condition, c.Created, c.CreatorID, c.CSVFile, c.Deleted, c.Geom, c.H3cell, c.ID, c.IsInDistrict, c.IsNew, c.Notes, c.OrganizationID, c.PropertyOwnerName, c.PropertyOwnerPhone, c.ResidentOwned, c.ResidentPhone, c.Version, } } -type poolIndexes struct { +type fileuploadPoolIndexes struct { PoolPkey index } -func (i poolIndexes) AsSlice() []index { +func (i fileuploadPoolIndexes) AsSlice() []index { return []index{ i.PoolPkey, } } -type poolForeignKeys struct { - PoolPoolCreatorIDFkey foreignKey - PoolPoolOrganizationIDFkey foreignKey +type fileuploadPoolForeignKeys struct { + FileuploadPoolPoolCreatorIDFkey foreignKey + FileuploadPoolPoolCSVFileFkey foreignKey + FileuploadPoolPoolOrganizationIDFkey foreignKey } -func (f poolForeignKeys) AsSlice() []foreignKey { +func (f fileuploadPoolForeignKeys) AsSlice() []foreignKey { return []foreignKey{ - f.PoolPoolCreatorIDFkey, f.PoolPoolOrganizationIDFkey, + f.FileuploadPoolPoolCreatorIDFkey, f.FileuploadPoolPoolCSVFileFkey, f.FileuploadPoolPoolOrganizationIDFkey, } } -type poolUniques struct{} +type fileuploadPoolUniques struct{} -func (u poolUniques) AsSlice() []constraint { +func (u fileuploadPoolUniques) AsSlice() []constraint { return []constraint{} } -type poolChecks struct{} +type fileuploadPoolChecks struct{} -func (c poolChecks) AsSlice() []check { +func (c fileuploadPoolChecks) AsSlice() []check { return []check{} } diff --git a/db/enums/enums.bob.go b/db/enums/enums.bob.go index 0205ef1c..3eb8ce64 100644 --- a/db/enums/enums.bob.go +++ b/db/enums/enums.bob.go @@ -725,6 +725,85 @@ func (e *FileuploadFilestatustype) Scan(value any) error { return nil } +// Enum values for FileuploadPoolconditiontype +const ( + FileuploadPoolconditiontypeGreen FileuploadPoolconditiontype = "green" + FileuploadPoolconditiontypeMurky FileuploadPoolconditiontype = "murky" + FileuploadPoolconditiontypeBlue FileuploadPoolconditiontype = "blue" + FileuploadPoolconditiontypeUnknown FileuploadPoolconditiontype = "unknown" +) + +func AllFileuploadPoolconditiontype() []FileuploadPoolconditiontype { + return []FileuploadPoolconditiontype{ + FileuploadPoolconditiontypeGreen, + FileuploadPoolconditiontypeMurky, + FileuploadPoolconditiontypeBlue, + FileuploadPoolconditiontypeUnknown, + } +} + +type FileuploadPoolconditiontype string + +func (e FileuploadPoolconditiontype) String() string { + return string(e) +} + +func (e FileuploadPoolconditiontype) Valid() bool { + switch e { + case FileuploadPoolconditiontypeGreen, + FileuploadPoolconditiontypeMurky, + FileuploadPoolconditiontypeBlue, + FileuploadPoolconditiontypeUnknown: + return true + default: + return false + } +} + +// useful when testing in other packages +func (e FileuploadPoolconditiontype) All() []FileuploadPoolconditiontype { + return AllFileuploadPoolconditiontype() +} + +func (e FileuploadPoolconditiontype) MarshalText() ([]byte, error) { + return []byte(e), nil +} + +func (e *FileuploadPoolconditiontype) UnmarshalText(text []byte) error { + return e.Scan(text) +} + +func (e FileuploadPoolconditiontype) MarshalBinary() ([]byte, error) { + return []byte(e), nil +} + +func (e *FileuploadPoolconditiontype) UnmarshalBinary(data []byte) error { + return e.Scan(data) +} + +func (e FileuploadPoolconditiontype) Value() (driver.Value, error) { + return string(e), nil +} + +func (e *FileuploadPoolconditiontype) Scan(value any) error { + switch x := value.(type) { + case string: + *e = FileuploadPoolconditiontype(x) + case []byte: + *e = FileuploadPoolconditiontype(x) + case nil: + return fmt.Errorf("cannot nil into FileuploadPoolconditiontype") + default: + return fmt.Errorf("cannot scan type %T: %v", value, value) + } + + if !e.Valid() { + return fmt.Errorf("invalid FileuploadPoolconditiontype value: %s", *e) + } + + return nil +} + // Enum values for H3aggregationtype const ( H3aggregationtypeMosquitosource H3aggregationtype = "MosquitoSource" @@ -1013,85 +1092,6 @@ func (e *Notificationtype) Scan(value any) error { return nil } -// Enum values for Poolconditiontype -const ( - PoolconditiontypeGreen Poolconditiontype = "green" - PoolconditiontypeMurky Poolconditiontype = "murky" - PoolconditiontypeBlue Poolconditiontype = "blue" - PoolconditiontypeUnknown Poolconditiontype = "unknown" -) - -func AllPoolconditiontype() []Poolconditiontype { - return []Poolconditiontype{ - PoolconditiontypeGreen, - PoolconditiontypeMurky, - PoolconditiontypeBlue, - PoolconditiontypeUnknown, - } -} - -type Poolconditiontype string - -func (e Poolconditiontype) String() string { - return string(e) -} - -func (e Poolconditiontype) Valid() bool { - switch e { - case PoolconditiontypeGreen, - PoolconditiontypeMurky, - PoolconditiontypeBlue, - PoolconditiontypeUnknown: - return true - default: - return false - } -} - -// useful when testing in other packages -func (e Poolconditiontype) All() []Poolconditiontype { - return AllPoolconditiontype() -} - -func (e Poolconditiontype) MarshalText() ([]byte, error) { - return []byte(e), nil -} - -func (e *Poolconditiontype) UnmarshalText(text []byte) error { - return e.Scan(text) -} - -func (e Poolconditiontype) MarshalBinary() ([]byte, error) { - return []byte(e), nil -} - -func (e *Poolconditiontype) UnmarshalBinary(data []byte) error { - return e.Scan(data) -} - -func (e Poolconditiontype) Value() (driver.Value, error) { - return string(e), nil -} - -func (e *Poolconditiontype) Scan(value any) error { - switch x := value.(type) { - case string: - *e = Poolconditiontype(x) - case []byte: - *e = Poolconditiontype(x) - case nil: - return fmt.Errorf("cannot nil into Poolconditiontype") - default: - return fmt.Errorf("cannot scan type %T: %v", value, value) - } - - if !e.Valid() { - return fmt.Errorf("invalid Poolconditiontype value: %s", *e) - } - - return nil -} - // Enum values for PublicreportAccuracytype const ( PublicreportAccuracytypeRooftop PublicreportAccuracytype = "rooftop" diff --git a/db/factory/bobfactory_context.bob.go b/db/factory/bobfactory_context.bob.go index bcb3a306..05a6e922 100644 --- a/db/factory/bobfactory_context.bob.go +++ b/db/factory/bobfactory_context.bob.go @@ -177,6 +177,7 @@ var ( fileuploadCSVWithParentsCascadingCtx = newContextual[bool]("fileuploadCSVWithParentsCascading") fileuploadCSVRelFileCtx = newContextual[bool]("fileupload.csv.fileupload.file.fileupload.csv.csv_file_id_fkey") fileuploadCSVRelCSVFileErrorCSVSCtx = newContextual[bool]("fileupload.csv.fileupload.error_csv.fileupload.error_csv.error_csv_csv_file_id_fkey") + fileuploadCSVRelCSVFilePoolsCtx = newContextual[bool]("fileupload.csv.fileupload.pool.fileupload.pool.pool_csv_file_fkey") // Relationship Contexts for fileupload.error_csv fileuploadErrorCSVWithParentsCascadingCtx = newContextual[bool]("fileuploadErrorCSVWithParentsCascading") @@ -193,6 +194,12 @@ var ( fileuploadFileRelCreatorUserCtx = newContextual[bool]("fileupload.file.user_.fileupload.file.file_creator_id_fkey") fileuploadFileRelOrganizationCtx = newContextual[bool]("fileupload.file.organization.fileupload.file.file_organization_id_fkey") + // Relationship Contexts for fileupload.pool + fileuploadPoolWithParentsCascadingCtx = newContextual[bool]("fileuploadPoolWithParentsCascading") + fileuploadPoolRelCreatorUserCtx = newContextual[bool]("fileupload.pool.user_.fileupload.pool.pool_creator_id_fkey") + fileuploadPoolRelCSVFileCSVCtx = newContextual[bool]("fileupload.csv.fileupload.pool.fileupload.pool.pool_csv_file_fkey") + fileuploadPoolRelOrganizationCtx = newContextual[bool]("fileupload.pool.organization.fileupload.pool.pool_organization_id_fkey") + // Relationship Contexts for geography_columns geographyColumnWithParentsCascadingCtx = newContextual[bool]("geographyColumnWithParentsCascading") @@ -283,21 +290,16 @@ var ( organizationRelZones2sCtx = newContextual[bool]("fieldseeker.zones2.organization.fieldseeker.zones2.zones2_organization_id_fkey") organizationRelFieldseekerSyncsCtx = newContextual[bool]("fieldseeker_sync.organization.fieldseeker_sync.fieldseeker_sync_organization_id_fkey") organizationRelFilesCtx = newContextual[bool]("fileupload.file.organization.fileupload.file.file_organization_id_fkey") + organizationRelPoolsCtx = newContextual[bool]("fileupload.pool.organization.fileupload.pool.pool_organization_id_fkey") organizationRelH3AggregationsCtx = newContextual[bool]("h3_aggregation.organization.h3_aggregation.h3_aggregation_organization_id_fkey") organizationRelNoteAudiosCtx = newContextual[bool]("note_audio.organization.note_audio.note_audio_organization_id_fkey") organizationRelNoteImagesCtx = newContextual[bool]("note_image.organization.note_image.note_image_organization_id_fkey") organizationRelImportDistrictGidDistrictCtx = newContextual[bool]("import.district.organization.organization.organization_import_district_gid_fkey") - organizationRelPoolsCtx = newContextual[bool]("organization.pool.pool.pool_organization_id_fkey") organizationRelNuisancesCtx = newContextual[bool]("organization.publicreport.nuisance.publicreport.nuisance.nuisance_organization_id_fkey") organizationRelPublicreportPoolCtx = newContextual[bool]("organization.publicreport.pool.publicreport.pool.pool_organization_id_fkey") organizationRelQuicksCtx = newContextual[bool]("organization.publicreport.quick.publicreport.quick.quick_organization_id_fkey") organizationRelUserCtx = newContextual[bool]("organization.user_.user_.user__organization_id_fkey") - // Relationship Contexts for pool - poolWithParentsCascadingCtx = newContextual[bool]("poolWithParentsCascading") - poolRelCreatorUserCtx = newContextual[bool]("pool.user_.pool.pool_creator_id_fkey") - poolRelOrganizationCtx = newContextual[bool]("organization.pool.pool.pool_organization_id_fkey") - // Relationship Contexts for publicreport.image publicreportImageWithParentsCascadingCtx = newContextual[bool]("publicreportImageWithParentsCascading") publicreportImageRelImageExifsCtx = newContextual[bool]("publicreport.image.publicreport.image_exif.publicreport.image_exif.image_exif_image_id_fkey") @@ -382,13 +384,13 @@ var ( userWithParentsCascadingCtx = newContextual[bool]("userWithParentsCascading") userRelPublicUserUserCtx = newContextual[bool]("arcgis.user_.user_.arcgis.user_.user__public_user_id_fkey") userRelCreatorFilesCtx = newContextual[bool]("fileupload.file.user_.fileupload.file.file_creator_id_fkey") + userRelCreatorPoolsCtx = newContextual[bool]("fileupload.pool.user_.fileupload.pool.pool_creator_id_fkey") userRelCreatorNoteAudiosCtx = newContextual[bool]("note_audio.user_.note_audio.note_audio_creator_id_fkey") userRelDeletorNoteAudiosCtx = newContextual[bool]("note_audio.user_.note_audio.note_audio_deletor_id_fkey") userRelCreatorNoteImagesCtx = newContextual[bool]("note_image.user_.note_image.note_image_creator_id_fkey") userRelDeletorNoteImagesCtx = newContextual[bool]("note_image.user_.note_image.note_image_deletor_id_fkey") userRelUserNotificationsCtx = newContextual[bool]("notification.user_.notification.notification_user_id_fkey") userRelUserOauthTokensCtx = newContextual[bool]("oauth_token.user_.oauth_token.oauth_token_user_id_fkey") - userRelCreatorPoolsCtx = newContextual[bool]("pool.user_.pool.pool_creator_id_fkey") userRelOrganizationCtx = newContextual[bool]("organization.user_.user_.user__organization_id_fkey") ) diff --git a/db/factory/bobfactory_main.bob.go b/db/factory/bobfactory_main.bob.go index fb3538e2..3d71b0bb 100644 --- a/db/factory/bobfactory_main.bob.go +++ b/db/factory/bobfactory_main.bob.go @@ -61,6 +61,7 @@ type Factory struct { baseFileuploadErrorCSVMods FileuploadErrorCSVModSlice baseFileuploadErrorFileMods FileuploadErrorFileModSlice baseFileuploadFileMods FileuploadFileModSlice + baseFileuploadPoolMods FileuploadPoolModSlice baseGeographyColumnMods GeographyColumnModSlice baseGeometryColumnMods GeometryColumnModSlice baseGooseDBVersionMods GooseDBVersionModSlice @@ -75,7 +76,6 @@ type Factory struct { baseNotificationMods NotificationModSlice baseOauthTokenMods OauthTokenModSlice baseOrganizationMods OrganizationModSlice - basePoolMods PoolModSlice basePublicreportImageMods PublicreportImageModSlice basePublicreportImageExifMods PublicreportImageExifModSlice basePublicreportNotifyEmailNuisanceMods PublicreportNotifyEmailNuisanceModSlice @@ -2265,6 +2265,9 @@ func (f *Factory) FromExistingFileuploadCSV(m *models.FileuploadCSV) *Fileupload if len(m.R.CSVFileErrorCSVS) > 0 { FileuploadCSVMods.AddExistingCSVFileErrorCSVS(m.R.CSVFileErrorCSVS...).Apply(ctx, o) } + if len(m.R.CSVFilePools) > 0 { + FileuploadCSVMods.AddExistingCSVFilePools(m.R.CSVFilePools...).Apply(ctx, o) + } return o } @@ -2380,6 +2383,61 @@ func (f *Factory) FromExistingFileuploadFile(m *models.FileuploadFile) *Fileuplo return o } +func (f *Factory) NewFileuploadPool(mods ...FileuploadPoolMod) *FileuploadPoolTemplate { + return f.NewFileuploadPoolWithContext(context.Background(), mods...) +} + +func (f *Factory) NewFileuploadPoolWithContext(ctx context.Context, mods ...FileuploadPoolMod) *FileuploadPoolTemplate { + o := &FileuploadPoolTemplate{f: f} + + if f != nil { + f.baseFileuploadPoolMods.Apply(ctx, o) + } + + FileuploadPoolModSlice(mods).Apply(ctx, o) + + return o +} + +func (f *Factory) FromExistingFileuploadPool(m *models.FileuploadPool) *FileuploadPoolTemplate { + o := &FileuploadPoolTemplate{f: f, alreadyPersisted: true} + + o.AddressCity = func() string { return m.AddressCity } + o.AddressPostalCode = func() string { return m.AddressPostalCode } + o.AddressStreet = func() string { return m.AddressStreet } + o.Committed = func() bool { return m.Committed } + o.Condition = func() enums.FileuploadPoolconditiontype { return m.Condition } + o.Created = func() time.Time { return m.Created } + o.CreatorID = func() int32 { return m.CreatorID } + o.CSVFile = func() int32 { return m.CSVFile } + o.Deleted = func() null.Val[time.Time] { return m.Deleted } + o.Geom = func() null.Val[string] { return m.Geom } + o.H3cell = func() null.Val[string] { return m.H3cell } + o.ID = func() int32 { return m.ID } + o.IsInDistrict = func() bool { return m.IsInDistrict } + o.IsNew = func() bool { return m.IsNew } + o.Notes = func() string { return m.Notes } + o.OrganizationID = func() int32 { return m.OrganizationID } + o.PropertyOwnerName = func() string { return m.PropertyOwnerName } + o.PropertyOwnerPhone = func() null.Val[string] { return m.PropertyOwnerPhone } + o.ResidentOwned = func() null.Val[bool] { return m.ResidentOwned } + o.ResidentPhone = func() null.Val[string] { return m.ResidentPhone } + o.Version = func() int32 { return m.Version } + + ctx := context.Background() + if m.R.CreatorUser != nil { + FileuploadPoolMods.WithExistingCreatorUser(m.R.CreatorUser).Apply(ctx, o) + } + if m.R.CSVFileCSV != nil { + FileuploadPoolMods.WithExistingCSVFileCSV(m.R.CSVFileCSV).Apply(ctx, o) + } + if m.R.Organization != nil { + FileuploadPoolMods.WithExistingOrganization(m.R.Organization).Apply(ctx, o) + } + + return o +} + func (f *Factory) NewGeographyColumn(mods ...GeographyColumnMod) *GeographyColumnTemplate { return f.NewGeographyColumnWithContext(context.Background(), mods...) } @@ -2978,6 +3036,9 @@ func (f *Factory) FromExistingOrganization(m *models.Organization) *Organization if len(m.R.Files) > 0 { OrganizationMods.AddExistingFiles(m.R.Files...).Apply(ctx, o) } + if len(m.R.Pools) > 0 { + OrganizationMods.AddExistingPools(m.R.Pools...).Apply(ctx, o) + } if len(m.R.H3Aggregations) > 0 { OrganizationMods.AddExistingH3Aggregations(m.R.H3Aggregations...).Apply(ctx, o) } @@ -2990,9 +3051,6 @@ func (f *Factory) FromExistingOrganization(m *models.Organization) *Organization if m.R.ImportDistrictGidDistrict != nil { OrganizationMods.WithExistingImportDistrictGidDistrict(m.R.ImportDistrictGidDistrict).Apply(ctx, o) } - if len(m.R.Pools) > 0 { - OrganizationMods.AddExistingPools(m.R.Pools...).Apply(ctx, o) - } if len(m.R.Nuisances) > 0 { OrganizationMods.AddExistingNuisances(m.R.Nuisances...).Apply(ctx, o) } @@ -3009,53 +3067,6 @@ func (f *Factory) FromExistingOrganization(m *models.Organization) *Organization return o } -func (f *Factory) NewPool(mods ...PoolMod) *PoolTemplate { - return f.NewPoolWithContext(context.Background(), mods...) -} - -func (f *Factory) NewPoolWithContext(ctx context.Context, mods ...PoolMod) *PoolTemplate { - o := &PoolTemplate{f: f} - - if f != nil { - f.basePoolMods.Apply(ctx, o) - } - - PoolModSlice(mods).Apply(ctx, o) - - return o -} - -func (f *Factory) FromExistingPool(m *models.Pool) *PoolTemplate { - o := &PoolTemplate{f: f, alreadyPersisted: true} - - o.AddressCity = func() string { return m.AddressCity } - o.AddressPostalCode = func() string { return m.AddressPostalCode } - o.AddressStreet = func() string { return m.AddressStreet } - o.Condition = func() enums.Poolconditiontype { return m.Condition } - o.Created = func() time.Time { return m.Created } - o.CreatorID = func() int32 { return m.CreatorID } - o.Deleted = func() null.Val[time.Time] { return m.Deleted } - o.Committed = func() bool { return m.Committed } - o.ID = func() int32 { return m.ID } - o.Notes = func() string { return m.Notes } - o.OrganizationID = func() int32 { return m.OrganizationID } - o.PropertyOwnerName = func() string { return m.PropertyOwnerName } - o.PropertyOwnerPhone = func() null.Val[string] { return m.PropertyOwnerPhone } - o.ResidentOwned = func() null.Val[bool] { return m.ResidentOwned } - o.ResidentPhone = func() null.Val[string] { return m.ResidentPhone } - o.Version = func() int32 { return m.Version } - - ctx := context.Background() - if m.R.CreatorUser != nil { - PoolMods.WithExistingCreatorUser(m.R.CreatorUser).Apply(ctx, o) - } - if m.R.Organization != nil { - PoolMods.WithExistingOrganization(m.R.Organization).Apply(ctx, o) - } - - return o -} - func (f *Factory) NewPublicreportImage(mods ...PublicreportImageMod) *PublicreportImageTemplate { return f.NewPublicreportImageWithContext(context.Background(), mods...) } @@ -3752,6 +3763,9 @@ func (f *Factory) FromExistingUser(m *models.User) *UserTemplate { if len(m.R.CreatorFiles) > 0 { UserMods.AddExistingCreatorFiles(m.R.CreatorFiles...).Apply(ctx, o) } + if len(m.R.CreatorPools) > 0 { + UserMods.AddExistingCreatorPools(m.R.CreatorPools...).Apply(ctx, o) + } if len(m.R.CreatorNoteAudios) > 0 { UserMods.AddExistingCreatorNoteAudios(m.R.CreatorNoteAudios...).Apply(ctx, o) } @@ -3770,9 +3784,6 @@ func (f *Factory) FromExistingUser(m *models.User) *UserTemplate { if len(m.R.UserOauthTokens) > 0 { UserMods.AddExistingUserOauthTokens(m.R.UserOauthTokens...).Apply(ctx, o) } - if len(m.R.CreatorPools) > 0 { - UserMods.AddExistingCreatorPools(m.R.CreatorPools...).Apply(ctx, o) - } if m.R.Organization != nil { UserMods.WithExistingOrganization(m.R.Organization).Apply(ctx, o) } @@ -4116,6 +4127,14 @@ func (f *Factory) AddBaseFileuploadFileMod(mods ...FileuploadFileMod) { f.baseFileuploadFileMods = append(f.baseFileuploadFileMods, mods...) } +func (f *Factory) ClearBaseFileuploadPoolMods() { + f.baseFileuploadPoolMods = nil +} + +func (f *Factory) AddBaseFileuploadPoolMod(mods ...FileuploadPoolMod) { + f.baseFileuploadPoolMods = append(f.baseFileuploadPoolMods, mods...) +} + func (f *Factory) ClearBaseGeographyColumnMods() { f.baseGeographyColumnMods = nil } @@ -4228,14 +4247,6 @@ func (f *Factory) AddBaseOrganizationMod(mods ...OrganizationMod) { f.baseOrganizationMods = append(f.baseOrganizationMods, mods...) } -func (f *Factory) ClearBasePoolMods() { - f.basePoolMods = nil -} - -func (f *Factory) AddBasePoolMod(mods ...PoolMod) { - f.basePoolMods = append(f.basePoolMods, mods...) -} - func (f *Factory) ClearBasePublicreportImageMods() { f.basePublicreportImageMods = nil } diff --git a/db/factory/bobfactory_random.bob.go b/db/factory/bobfactory_random.bob.go index ea5bdf42..d95a2459 100644 --- a/db/factory/bobfactory_random.bob.go +++ b/db/factory/bobfactory_random.bob.go @@ -161,6 +161,16 @@ func random_enums_FileuploadFilestatustype(f *faker.Faker, limits ...string) enu return all[f.IntBetween(0, len(all)-1)] } +func random_enums_FileuploadPoolconditiontype(f *faker.Faker, limits ...string) enums.FileuploadPoolconditiontype { + if f == nil { + f = &defaultFaker + } + + var e enums.FileuploadPoolconditiontype + all := e.All() + return all[f.IntBetween(0, len(all)-1)] +} + func random_enums_H3aggregationtype(f *faker.Faker, limits ...string) enums.H3aggregationtype { if f == nil { f = &defaultFaker @@ -191,16 +201,6 @@ func random_enums_Notificationtype(f *faker.Faker, limits ...string) enums.Notif return all[f.IntBetween(0, len(all)-1)] } -func random_enums_Poolconditiontype(f *faker.Faker, limits ...string) enums.Poolconditiontype { - if f == nil { - f = &defaultFaker - } - - var e enums.Poolconditiontype - all := e.All() - return all[f.IntBetween(0, len(all)-1)] -} - func random_enums_PublicreportAccuracytype(f *faker.Faker, limits ...string) enums.PublicreportAccuracytype { if f == nil { f = &defaultFaker diff --git a/db/factory/fileupload.csv.bob.go b/db/factory/fileupload.csv.bob.go index d218a9a4..0cf7aca2 100644 --- a/db/factory/fileupload.csv.bob.go +++ b/db/factory/fileupload.csv.bob.go @@ -52,6 +52,7 @@ type FileuploadCSVTemplate struct { type fileuploadCSVR struct { File *fileuploadCSVRFileR CSVFileErrorCSVS []*fileuploadCSVRCSVFileErrorCSVSR + CSVFilePools []*fileuploadCSVRCSVFilePoolsR } type fileuploadCSVRFileR struct { @@ -61,6 +62,10 @@ type fileuploadCSVRCSVFileErrorCSVSR struct { number int o *FileuploadErrorCSVTemplate } +type fileuploadCSVRCSVFilePoolsR struct { + number int + o *FileuploadPoolTemplate +} // Apply mods to the FileuploadCSVTemplate func (o *FileuploadCSVTemplate) Apply(ctx context.Context, mods ...FileuploadCSVMod) { @@ -91,6 +96,19 @@ func (t FileuploadCSVTemplate) setModelRels(o *models.FileuploadCSV) { } o.R.CSVFileErrorCSVS = rel } + + if t.r.CSVFilePools != nil { + rel := models.FileuploadPoolSlice{} + for _, r := range t.r.CSVFilePools { + related := r.o.BuildMany(r.number) + for _, rel := range related { + rel.CSVFile = o.FileID // h2 + rel.R.CSVFileCSV = o + } + rel = append(rel, related...) + } + o.R.CSVFilePools = rel + } } // BuildSetter returns an *models.FileuploadCSVSetter @@ -208,6 +226,26 @@ func (o *FileuploadCSVTemplate) insertOptRels(ctx context.Context, exec bob.Exec } } + isCSVFilePoolsDone, _ := fileuploadCSVRelCSVFilePoolsCtx.Value(ctx) + if !isCSVFilePoolsDone && o.r.CSVFilePools != nil { + ctx = fileuploadCSVRelCSVFilePoolsCtx.WithValue(ctx, true) + for _, r := range o.r.CSVFilePools { + if r.o.alreadyPersisted { + m.R.CSVFilePools = append(m.R.CSVFilePools, r.o.Build()) + } else { + rel2, err := r.o.CreateMany(ctx, exec, r.number) + if err != nil { + return err + } + + err = m.AttachCSVFilePools(ctx, exec, rel2...) + if err != nil { + return err + } + } + } + } + return err } @@ -563,3 +601,51 @@ func (m fileuploadCSVMods) WithoutCSVFileErrorCSVS() FileuploadCSVMod { o.r.CSVFileErrorCSVS = nil }) } + +func (m fileuploadCSVMods) WithCSVFilePools(number int, related *FileuploadPoolTemplate) FileuploadCSVMod { + return FileuploadCSVModFunc(func(ctx context.Context, o *FileuploadCSVTemplate) { + o.r.CSVFilePools = []*fileuploadCSVRCSVFilePoolsR{{ + number: number, + o: related, + }} + }) +} + +func (m fileuploadCSVMods) WithNewCSVFilePools(number int, mods ...FileuploadPoolMod) FileuploadCSVMod { + return FileuploadCSVModFunc(func(ctx context.Context, o *FileuploadCSVTemplate) { + related := o.f.NewFileuploadPoolWithContext(ctx, mods...) + m.WithCSVFilePools(number, related).Apply(ctx, o) + }) +} + +func (m fileuploadCSVMods) AddCSVFilePools(number int, related *FileuploadPoolTemplate) FileuploadCSVMod { + return FileuploadCSVModFunc(func(ctx context.Context, o *FileuploadCSVTemplate) { + o.r.CSVFilePools = append(o.r.CSVFilePools, &fileuploadCSVRCSVFilePoolsR{ + number: number, + o: related, + }) + }) +} + +func (m fileuploadCSVMods) AddNewCSVFilePools(number int, mods ...FileuploadPoolMod) FileuploadCSVMod { + return FileuploadCSVModFunc(func(ctx context.Context, o *FileuploadCSVTemplate) { + related := o.f.NewFileuploadPoolWithContext(ctx, mods...) + m.AddCSVFilePools(number, related).Apply(ctx, o) + }) +} + +func (m fileuploadCSVMods) AddExistingCSVFilePools(existingModels ...*models.FileuploadPool) FileuploadCSVMod { + return FileuploadCSVModFunc(func(ctx context.Context, o *FileuploadCSVTemplate) { + for _, em := range existingModels { + o.r.CSVFilePools = append(o.r.CSVFilePools, &fileuploadCSVRCSVFilePoolsR{ + o: o.f.FromExistingFileuploadPool(em), + }) + } + }) +} + +func (m fileuploadCSVMods) WithoutCSVFilePools() FileuploadCSVMod { + return FileuploadCSVModFunc(func(ctx context.Context, o *FileuploadCSVTemplate) { + o.r.CSVFilePools = nil + }) +} diff --git a/db/factory/fileupload.pool.bob.go b/db/factory/fileupload.pool.bob.go new file mode 100644 index 00000000..058ef448 --- /dev/null +++ b/db/factory/fileupload.pool.bob.go @@ -0,0 +1,1441 @@ +// Code generated by BobGen psql v0.42.5. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package factory + +import ( + "context" + "testing" + "time" + + "github.com/Gleipnir-Technology/bob" + enums "github.com/Gleipnir-Technology/nidus-sync/db/enums" + models "github.com/Gleipnir-Technology/nidus-sync/db/models" + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" + "github.com/jaswdr/faker/v2" +) + +type FileuploadPoolMod interface { + Apply(context.Context, *FileuploadPoolTemplate) +} + +type FileuploadPoolModFunc func(context.Context, *FileuploadPoolTemplate) + +func (f FileuploadPoolModFunc) Apply(ctx context.Context, n *FileuploadPoolTemplate) { + f(ctx, n) +} + +type FileuploadPoolModSlice []FileuploadPoolMod + +func (mods FileuploadPoolModSlice) Apply(ctx context.Context, n *FileuploadPoolTemplate) { + for _, f := range mods { + f.Apply(ctx, n) + } +} + +// FileuploadPoolTemplate is an object representing the database table. +// all columns are optional and should be set by mods +type FileuploadPoolTemplate struct { + AddressCity func() string + AddressPostalCode func() string + AddressStreet func() string + Committed func() bool + Condition func() enums.FileuploadPoolconditiontype + Created func() time.Time + CreatorID func() int32 + CSVFile func() int32 + Deleted func() null.Val[time.Time] + Geom func() null.Val[string] + H3cell func() null.Val[string] + ID func() int32 + IsInDistrict func() bool + IsNew func() bool + Notes func() string + OrganizationID func() int32 + PropertyOwnerName func() string + PropertyOwnerPhone func() null.Val[string] + ResidentOwned func() null.Val[bool] + ResidentPhone func() null.Val[string] + Version func() int32 + + r fileuploadPoolR + f *Factory + + alreadyPersisted bool +} + +type fileuploadPoolR struct { + CreatorUser *fileuploadPoolRCreatorUserR + CSVFileCSV *fileuploadPoolRCSVFileCSVR + Organization *fileuploadPoolROrganizationR +} + +type fileuploadPoolRCreatorUserR struct { + o *UserTemplate +} +type fileuploadPoolRCSVFileCSVR struct { + o *FileuploadCSVTemplate +} +type fileuploadPoolROrganizationR struct { + o *OrganizationTemplate +} + +// Apply mods to the FileuploadPoolTemplate +func (o *FileuploadPoolTemplate) Apply(ctx context.Context, mods ...FileuploadPoolMod) { + for _, mod := range mods { + mod.Apply(ctx, o) + } +} + +// setModelRels creates and sets the relationships on *models.FileuploadPool +// according to the relationships in the template. Nothing is inserted into the db +func (t FileuploadPoolTemplate) setModelRels(o *models.FileuploadPool) { + if t.r.CreatorUser != nil { + rel := t.r.CreatorUser.o.Build() + rel.R.CreatorPools = append(rel.R.CreatorPools, o) + o.CreatorID = rel.ID // h2 + o.R.CreatorUser = rel + } + + if t.r.CSVFileCSV != nil { + rel := t.r.CSVFileCSV.o.Build() + rel.R.CSVFilePools = append(rel.R.CSVFilePools, o) + o.CSVFile = rel.FileID // h2 + o.R.CSVFileCSV = rel + } + + if t.r.Organization != nil { + rel := t.r.Organization.o.Build() + rel.R.Pools = append(rel.R.Pools, o) + o.OrganizationID = rel.ID // h2 + o.R.Organization = rel + } +} + +// BuildSetter returns an *models.FileuploadPoolSetter +// this does nothing with the relationship templates +func (o FileuploadPoolTemplate) BuildSetter() *models.FileuploadPoolSetter { + m := &models.FileuploadPoolSetter{} + + if o.AddressCity != nil { + val := o.AddressCity() + m.AddressCity = omit.From(val) + } + if o.AddressPostalCode != nil { + val := o.AddressPostalCode() + m.AddressPostalCode = omit.From(val) + } + if o.AddressStreet != nil { + val := o.AddressStreet() + m.AddressStreet = omit.From(val) + } + if o.Committed != nil { + val := o.Committed() + m.Committed = omit.From(val) + } + if o.Condition != nil { + val := o.Condition() + m.Condition = omit.From(val) + } + if o.Created != nil { + val := o.Created() + m.Created = omit.From(val) + } + if o.CreatorID != nil { + val := o.CreatorID() + m.CreatorID = omit.From(val) + } + if o.CSVFile != nil { + val := o.CSVFile() + m.CSVFile = omit.From(val) + } + if o.Deleted != nil { + val := o.Deleted() + m.Deleted = omitnull.FromNull(val) + } + if o.Geom != nil { + val := o.Geom() + m.Geom = omitnull.FromNull(val) + } + if o.H3cell != nil { + val := o.H3cell() + m.H3cell = omitnull.FromNull(val) + } + if o.ID != nil { + val := o.ID() + m.ID = omit.From(val) + } + if o.IsInDistrict != nil { + val := o.IsInDistrict() + m.IsInDistrict = omit.From(val) + } + if o.IsNew != nil { + val := o.IsNew() + m.IsNew = omit.From(val) + } + if o.Notes != nil { + val := o.Notes() + m.Notes = omit.From(val) + } + if o.OrganizationID != nil { + val := o.OrganizationID() + m.OrganizationID = omit.From(val) + } + if o.PropertyOwnerName != nil { + val := o.PropertyOwnerName() + m.PropertyOwnerName = omit.From(val) + } + if o.PropertyOwnerPhone != nil { + val := o.PropertyOwnerPhone() + m.PropertyOwnerPhone = omitnull.FromNull(val) + } + if o.ResidentOwned != nil { + val := o.ResidentOwned() + m.ResidentOwned = omitnull.FromNull(val) + } + if o.ResidentPhone != nil { + val := o.ResidentPhone() + m.ResidentPhone = omitnull.FromNull(val) + } + if o.Version != nil { + val := o.Version() + m.Version = omit.From(val) + } + + return m +} + +// BuildManySetter returns an []*models.FileuploadPoolSetter +// this does nothing with the relationship templates +func (o FileuploadPoolTemplate) BuildManySetter(number int) []*models.FileuploadPoolSetter { + m := make([]*models.FileuploadPoolSetter, number) + + for i := range m { + m[i] = o.BuildSetter() + } + + return m +} + +// Build returns an *models.FileuploadPool +// Related objects are also created and placed in the .R field +// NOTE: Objects are not inserted into the database. Use FileuploadPoolTemplate.Create +func (o FileuploadPoolTemplate) Build() *models.FileuploadPool { + m := &models.FileuploadPool{} + + if o.AddressCity != nil { + m.AddressCity = o.AddressCity() + } + if o.AddressPostalCode != nil { + m.AddressPostalCode = o.AddressPostalCode() + } + if o.AddressStreet != nil { + m.AddressStreet = o.AddressStreet() + } + if o.Committed != nil { + m.Committed = o.Committed() + } + if o.Condition != nil { + m.Condition = o.Condition() + } + if o.Created != nil { + m.Created = o.Created() + } + if o.CreatorID != nil { + m.CreatorID = o.CreatorID() + } + if o.CSVFile != nil { + m.CSVFile = o.CSVFile() + } + if o.Deleted != nil { + m.Deleted = o.Deleted() + } + if o.Geom != nil { + m.Geom = o.Geom() + } + if o.H3cell != nil { + m.H3cell = o.H3cell() + } + if o.ID != nil { + m.ID = o.ID() + } + if o.IsInDistrict != nil { + m.IsInDistrict = o.IsInDistrict() + } + if o.IsNew != nil { + m.IsNew = o.IsNew() + } + if o.Notes != nil { + m.Notes = o.Notes() + } + if o.OrganizationID != nil { + m.OrganizationID = o.OrganizationID() + } + if o.PropertyOwnerName != nil { + m.PropertyOwnerName = o.PropertyOwnerName() + } + if o.PropertyOwnerPhone != nil { + m.PropertyOwnerPhone = o.PropertyOwnerPhone() + } + if o.ResidentOwned != nil { + m.ResidentOwned = o.ResidentOwned() + } + if o.ResidentPhone != nil { + m.ResidentPhone = o.ResidentPhone() + } + if o.Version != nil { + m.Version = o.Version() + } + + o.setModelRels(m) + + return m +} + +// BuildMany returns an models.FileuploadPoolSlice +// Related objects are also created and placed in the .R field +// NOTE: Objects are not inserted into the database. Use FileuploadPoolTemplate.CreateMany +func (o FileuploadPoolTemplate) BuildMany(number int) models.FileuploadPoolSlice { + m := make(models.FileuploadPoolSlice, number) + + for i := range m { + m[i] = o.Build() + } + + return m +} + +func ensureCreatableFileuploadPool(m *models.FileuploadPoolSetter) { + if !(m.AddressCity.IsValue()) { + val := random_string(nil) + m.AddressCity = omit.From(val) + } + if !(m.AddressPostalCode.IsValue()) { + val := random_string(nil) + m.AddressPostalCode = omit.From(val) + } + if !(m.AddressStreet.IsValue()) { + val := random_string(nil) + m.AddressStreet = omit.From(val) + } + if !(m.Committed.IsValue()) { + val := random_bool(nil) + m.Committed = omit.From(val) + } + if !(m.Condition.IsValue()) { + val := random_enums_FileuploadPoolconditiontype(nil) + m.Condition = omit.From(val) + } + if !(m.Created.IsValue()) { + val := random_time_Time(nil) + m.Created = omit.From(val) + } + if !(m.CreatorID.IsValue()) { + val := random_int32(nil) + m.CreatorID = omit.From(val) + } + if !(m.CSVFile.IsValue()) { + val := random_int32(nil) + m.CSVFile = omit.From(val) + } + if !(m.IsInDistrict.IsValue()) { + val := random_bool(nil) + m.IsInDistrict = omit.From(val) + } + if !(m.IsNew.IsValue()) { + val := random_bool(nil) + m.IsNew = omit.From(val) + } + if !(m.Notes.IsValue()) { + val := random_string(nil) + m.Notes = omit.From(val) + } + if !(m.OrganizationID.IsValue()) { + val := random_int32(nil) + m.OrganizationID = omit.From(val) + } + if !(m.PropertyOwnerName.IsValue()) { + val := random_string(nil) + m.PropertyOwnerName = omit.From(val) + } + if !(m.Version.IsValue()) { + val := random_int32(nil) + m.Version = omit.From(val) + } +} + +// insertOptRels creates and inserts any optional the relationships on *models.FileuploadPool +// according to the relationships in the template. +// any required relationship should have already exist on the model +func (o *FileuploadPoolTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.FileuploadPool) error { + var err error + + return err +} + +// Create builds a fileuploadPool and inserts it into the database +// Relations objects are also inserted and placed in the .R field +func (o *FileuploadPoolTemplate) Create(ctx context.Context, exec bob.Executor) (*models.FileuploadPool, error) { + var err error + opt := o.BuildSetter() + ensureCreatableFileuploadPool(opt) + + if o.r.CreatorUser == nil { + FileuploadPoolMods.WithNewCreatorUser().Apply(ctx, o) + } + + var rel0 *models.User + + if o.r.CreatorUser.o.alreadyPersisted { + rel0 = o.r.CreatorUser.o.Build() + } else { + rel0, err = o.r.CreatorUser.o.Create(ctx, exec) + if err != nil { + return nil, err + } + } + + opt.CreatorID = omit.From(rel0.ID) + + if o.r.CSVFileCSV == nil { + FileuploadPoolMods.WithNewCSVFileCSV().Apply(ctx, o) + } + + var rel1 *models.FileuploadCSV + + if o.r.CSVFileCSV.o.alreadyPersisted { + rel1 = o.r.CSVFileCSV.o.Build() + } else { + rel1, err = o.r.CSVFileCSV.o.Create(ctx, exec) + if err != nil { + return nil, err + } + } + + opt.CSVFile = omit.From(rel1.FileID) + + if o.r.Organization == nil { + FileuploadPoolMods.WithNewOrganization().Apply(ctx, o) + } + + var rel2 *models.Organization + + if o.r.Organization.o.alreadyPersisted { + rel2 = o.r.Organization.o.Build() + } else { + rel2, err = o.r.Organization.o.Create(ctx, exec) + if err != nil { + return nil, err + } + } + + opt.OrganizationID = omit.From(rel2.ID) + + m, err := models.FileuploadPools.Insert(opt).One(ctx, exec) + if err != nil { + return nil, err + } + + m.R.CreatorUser = rel0 + m.R.CSVFileCSV = rel1 + m.R.Organization = rel2 + + if err := o.insertOptRels(ctx, exec, m); err != nil { + return nil, err + } + return m, err +} + +// MustCreate builds a fileuploadPool and inserts it into the database +// Relations objects are also inserted and placed in the .R field +// panics if an error occurs +func (o *FileuploadPoolTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.FileuploadPool { + m, err := o.Create(ctx, exec) + if err != nil { + panic(err) + } + return m +} + +// CreateOrFail builds a fileuploadPool and inserts it into the database +// Relations objects are also inserted and placed in the .R field +// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs +func (o *FileuploadPoolTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.FileuploadPool { + tb.Helper() + m, err := o.Create(ctx, exec) + if err != nil { + tb.Fatal(err) + return nil + } + return m +} + +// CreateMany builds multiple fileuploadPools and inserts them into the database +// Relations objects are also inserted and placed in the .R field +func (o FileuploadPoolTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.FileuploadPoolSlice, error) { + var err error + m := make(models.FileuploadPoolSlice, number) + + for i := range m { + m[i], err = o.Create(ctx, exec) + if err != nil { + return nil, err + } + } + + return m, nil +} + +// MustCreateMany builds multiple fileuploadPools and inserts them into the database +// Relations objects are also inserted and placed in the .R field +// panics if an error occurs +func (o FileuploadPoolTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.FileuploadPoolSlice { + m, err := o.CreateMany(ctx, exec, number) + if err != nil { + panic(err) + } + return m +} + +// CreateManyOrFail builds multiple fileuploadPools and inserts them into the database +// Relations objects are also inserted and placed in the .R field +// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs +func (o FileuploadPoolTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.FileuploadPoolSlice { + tb.Helper() + m, err := o.CreateMany(ctx, exec, number) + if err != nil { + tb.Fatal(err) + return nil + } + return m +} + +// FileuploadPool has methods that act as mods for the FileuploadPoolTemplate +var FileuploadPoolMods fileuploadPoolMods + +type fileuploadPoolMods struct{} + +func (m fileuploadPoolMods) RandomizeAllColumns(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModSlice{ + FileuploadPoolMods.RandomAddressCity(f), + FileuploadPoolMods.RandomAddressPostalCode(f), + FileuploadPoolMods.RandomAddressStreet(f), + FileuploadPoolMods.RandomCommitted(f), + FileuploadPoolMods.RandomCondition(f), + FileuploadPoolMods.RandomCreated(f), + FileuploadPoolMods.RandomCreatorID(f), + FileuploadPoolMods.RandomCSVFile(f), + FileuploadPoolMods.RandomDeleted(f), + FileuploadPoolMods.RandomGeom(f), + FileuploadPoolMods.RandomH3cell(f), + FileuploadPoolMods.RandomID(f), + FileuploadPoolMods.RandomIsInDistrict(f), + FileuploadPoolMods.RandomIsNew(f), + FileuploadPoolMods.RandomNotes(f), + FileuploadPoolMods.RandomOrganizationID(f), + FileuploadPoolMods.RandomPropertyOwnerName(f), + FileuploadPoolMods.RandomPropertyOwnerPhone(f), + FileuploadPoolMods.RandomResidentOwned(f), + FileuploadPoolMods.RandomResidentPhone(f), + FileuploadPoolMods.RandomVersion(f), + } +} + +// Set the model columns to this value +func (m fileuploadPoolMods) AddressCity(val string) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.AddressCity = func() string { return val } + }) +} + +// Set the Column from the function +func (m fileuploadPoolMods) AddressCityFunc(f func() string) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.AddressCity = f + }) +} + +// Clear any values for the column +func (m fileuploadPoolMods) UnsetAddressCity() FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.AddressCity = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +func (m fileuploadPoolMods) RandomAddressCity(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.AddressCity = func() string { + return random_string(f) + } + }) +} + +// Set the model columns to this value +func (m fileuploadPoolMods) AddressPostalCode(val string) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.AddressPostalCode = func() string { return val } + }) +} + +// Set the Column from the function +func (m fileuploadPoolMods) AddressPostalCodeFunc(f func() string) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.AddressPostalCode = f + }) +} + +// Clear any values for the column +func (m fileuploadPoolMods) UnsetAddressPostalCode() FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.AddressPostalCode = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +func (m fileuploadPoolMods) RandomAddressPostalCode(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.AddressPostalCode = func() string { + return random_string(f) + } + }) +} + +// Set the model columns to this value +func (m fileuploadPoolMods) AddressStreet(val string) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.AddressStreet = func() string { return val } + }) +} + +// Set the Column from the function +func (m fileuploadPoolMods) AddressStreetFunc(f func() string) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.AddressStreet = f + }) +} + +// Clear any values for the column +func (m fileuploadPoolMods) UnsetAddressStreet() FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.AddressStreet = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +func (m fileuploadPoolMods) RandomAddressStreet(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.AddressStreet = func() string { + return random_string(f) + } + }) +} + +// Set the model columns to this value +func (m fileuploadPoolMods) Committed(val bool) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Committed = func() bool { return val } + }) +} + +// Set the Column from the function +func (m fileuploadPoolMods) CommittedFunc(f func() bool) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Committed = f + }) +} + +// Clear any values for the column +func (m fileuploadPoolMods) UnsetCommitted() FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Committed = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +func (m fileuploadPoolMods) RandomCommitted(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Committed = func() bool { + return random_bool(f) + } + }) +} + +// Set the model columns to this value +func (m fileuploadPoolMods) Condition(val enums.FileuploadPoolconditiontype) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Condition = func() enums.FileuploadPoolconditiontype { return val } + }) +} + +// Set the Column from the function +func (m fileuploadPoolMods) ConditionFunc(f func() enums.FileuploadPoolconditiontype) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Condition = f + }) +} + +// Clear any values for the column +func (m fileuploadPoolMods) UnsetCondition() FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Condition = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +func (m fileuploadPoolMods) RandomCondition(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Condition = func() enums.FileuploadPoolconditiontype { + return random_enums_FileuploadPoolconditiontype(f) + } + }) +} + +// Set the model columns to this value +func (m fileuploadPoolMods) Created(val time.Time) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Created = func() time.Time { return val } + }) +} + +// Set the Column from the function +func (m fileuploadPoolMods) CreatedFunc(f func() time.Time) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Created = f + }) +} + +// Clear any values for the column +func (m fileuploadPoolMods) UnsetCreated() FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Created = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +func (m fileuploadPoolMods) RandomCreated(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Created = func() time.Time { + return random_time_Time(f) + } + }) +} + +// Set the model columns to this value +func (m fileuploadPoolMods) CreatorID(val int32) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.CreatorID = func() int32 { return val } + }) +} + +// Set the Column from the function +func (m fileuploadPoolMods) CreatorIDFunc(f func() int32) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.CreatorID = f + }) +} + +// Clear any values for the column +func (m fileuploadPoolMods) UnsetCreatorID() FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.CreatorID = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +func (m fileuploadPoolMods) RandomCreatorID(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.CreatorID = func() int32 { + return random_int32(f) + } + }) +} + +// Set the model columns to this value +func (m fileuploadPoolMods) CSVFile(val int32) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.CSVFile = func() int32 { return val } + }) +} + +// Set the Column from the function +func (m fileuploadPoolMods) CSVFileFunc(f func() int32) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.CSVFile = f + }) +} + +// Clear any values for the column +func (m fileuploadPoolMods) UnsetCSVFile() FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.CSVFile = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +func (m fileuploadPoolMods) RandomCSVFile(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.CSVFile = func() int32 { + return random_int32(f) + } + }) +} + +// Set the model columns to this value +func (m fileuploadPoolMods) Deleted(val null.Val[time.Time]) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Deleted = func() null.Val[time.Time] { return val } + }) +} + +// Set the Column from the function +func (m fileuploadPoolMods) DeletedFunc(f func() null.Val[time.Time]) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Deleted = f + }) +} + +// Clear any values for the column +func (m fileuploadPoolMods) UnsetDeleted() FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Deleted = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +// The generated value is sometimes null +func (m fileuploadPoolMods) RandomDeleted(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Deleted = func() null.Val[time.Time] { + if f == nil { + f = &defaultFaker + } + + val := random_time_Time(f) + return null.From(val) + } + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +// The generated value is never null +func (m fileuploadPoolMods) RandomDeletedNotNull(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Deleted = func() null.Val[time.Time] { + if f == nil { + f = &defaultFaker + } + + val := random_time_Time(f) + return null.From(val) + } + }) +} + +// Set the model columns to this value +func (m fileuploadPoolMods) Geom(val null.Val[string]) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Geom = func() null.Val[string] { return val } + }) +} + +// Set the Column from the function +func (m fileuploadPoolMods) GeomFunc(f func() null.Val[string]) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Geom = f + }) +} + +// Clear any values for the column +func (m fileuploadPoolMods) UnsetGeom() FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Geom = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +// The generated value is sometimes null +func (m fileuploadPoolMods) RandomGeom(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Geom = func() null.Val[string] { + if f == nil { + f = &defaultFaker + } + + val := random_string(f) + return null.From(val) + } + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +// The generated value is never null +func (m fileuploadPoolMods) RandomGeomNotNull(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Geom = func() null.Val[string] { + if f == nil { + f = &defaultFaker + } + + val := random_string(f) + return null.From(val) + } + }) +} + +// Set the model columns to this value +func (m fileuploadPoolMods) H3cell(val null.Val[string]) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.H3cell = func() null.Val[string] { return val } + }) +} + +// Set the Column from the function +func (m fileuploadPoolMods) H3cellFunc(f func() null.Val[string]) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.H3cell = f + }) +} + +// Clear any values for the column +func (m fileuploadPoolMods) UnsetH3cell() FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.H3cell = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +// The generated value is sometimes null +func (m fileuploadPoolMods) RandomH3cell(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.H3cell = func() null.Val[string] { + if f == nil { + f = &defaultFaker + } + + val := random_string(f) + return null.From(val) + } + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +// The generated value is never null +func (m fileuploadPoolMods) RandomH3cellNotNull(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.H3cell = func() null.Val[string] { + if f == nil { + f = &defaultFaker + } + + val := random_string(f) + return null.From(val) + } + }) +} + +// Set the model columns to this value +func (m fileuploadPoolMods) ID(val int32) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.ID = func() int32 { return val } + }) +} + +// Set the Column from the function +func (m fileuploadPoolMods) IDFunc(f func() int32) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.ID = f + }) +} + +// Clear any values for the column +func (m fileuploadPoolMods) UnsetID() FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.ID = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +func (m fileuploadPoolMods) RandomID(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.ID = func() int32 { + return random_int32(f) + } + }) +} + +// Set the model columns to this value +func (m fileuploadPoolMods) IsInDistrict(val bool) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.IsInDistrict = func() bool { return val } + }) +} + +// Set the Column from the function +func (m fileuploadPoolMods) IsInDistrictFunc(f func() bool) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.IsInDistrict = f + }) +} + +// Clear any values for the column +func (m fileuploadPoolMods) UnsetIsInDistrict() FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.IsInDistrict = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +func (m fileuploadPoolMods) RandomIsInDistrict(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.IsInDistrict = func() bool { + return random_bool(f) + } + }) +} + +// Set the model columns to this value +func (m fileuploadPoolMods) IsNew(val bool) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.IsNew = func() bool { return val } + }) +} + +// Set the Column from the function +func (m fileuploadPoolMods) IsNewFunc(f func() bool) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.IsNew = f + }) +} + +// Clear any values for the column +func (m fileuploadPoolMods) UnsetIsNew() FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.IsNew = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +func (m fileuploadPoolMods) RandomIsNew(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.IsNew = func() bool { + return random_bool(f) + } + }) +} + +// Set the model columns to this value +func (m fileuploadPoolMods) Notes(val string) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Notes = func() string { return val } + }) +} + +// Set the Column from the function +func (m fileuploadPoolMods) NotesFunc(f func() string) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Notes = f + }) +} + +// Clear any values for the column +func (m fileuploadPoolMods) UnsetNotes() FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Notes = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +func (m fileuploadPoolMods) RandomNotes(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Notes = func() string { + return random_string(f) + } + }) +} + +// Set the model columns to this value +func (m fileuploadPoolMods) OrganizationID(val int32) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.OrganizationID = func() int32 { return val } + }) +} + +// Set the Column from the function +func (m fileuploadPoolMods) OrganizationIDFunc(f func() int32) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.OrganizationID = f + }) +} + +// Clear any values for the column +func (m fileuploadPoolMods) UnsetOrganizationID() FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.OrganizationID = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +func (m fileuploadPoolMods) RandomOrganizationID(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.OrganizationID = func() int32 { + return random_int32(f) + } + }) +} + +// Set the model columns to this value +func (m fileuploadPoolMods) PropertyOwnerName(val string) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.PropertyOwnerName = func() string { return val } + }) +} + +// Set the Column from the function +func (m fileuploadPoolMods) PropertyOwnerNameFunc(f func() string) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.PropertyOwnerName = f + }) +} + +// Clear any values for the column +func (m fileuploadPoolMods) UnsetPropertyOwnerName() FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.PropertyOwnerName = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +func (m fileuploadPoolMods) RandomPropertyOwnerName(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.PropertyOwnerName = func() string { + return random_string(f) + } + }) +} + +// Set the model columns to this value +func (m fileuploadPoolMods) PropertyOwnerPhone(val null.Val[string]) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.PropertyOwnerPhone = func() null.Val[string] { return val } + }) +} + +// Set the Column from the function +func (m fileuploadPoolMods) PropertyOwnerPhoneFunc(f func() null.Val[string]) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.PropertyOwnerPhone = f + }) +} + +// Clear any values for the column +func (m fileuploadPoolMods) UnsetPropertyOwnerPhone() FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.PropertyOwnerPhone = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +// The generated value is sometimes null +func (m fileuploadPoolMods) RandomPropertyOwnerPhone(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.PropertyOwnerPhone = func() null.Val[string] { + if f == nil { + f = &defaultFaker + } + + val := random_string(f) + return null.From(val) + } + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +// The generated value is never null +func (m fileuploadPoolMods) RandomPropertyOwnerPhoneNotNull(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.PropertyOwnerPhone = func() null.Val[string] { + if f == nil { + f = &defaultFaker + } + + val := random_string(f) + return null.From(val) + } + }) +} + +// Set the model columns to this value +func (m fileuploadPoolMods) ResidentOwned(val null.Val[bool]) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.ResidentOwned = func() null.Val[bool] { return val } + }) +} + +// Set the Column from the function +func (m fileuploadPoolMods) ResidentOwnedFunc(f func() null.Val[bool]) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.ResidentOwned = f + }) +} + +// Clear any values for the column +func (m fileuploadPoolMods) UnsetResidentOwned() FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.ResidentOwned = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +// The generated value is sometimes null +func (m fileuploadPoolMods) RandomResidentOwned(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.ResidentOwned = func() null.Val[bool] { + if f == nil { + f = &defaultFaker + } + + val := random_bool(f) + return null.From(val) + } + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +// The generated value is never null +func (m fileuploadPoolMods) RandomResidentOwnedNotNull(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.ResidentOwned = func() null.Val[bool] { + if f == nil { + f = &defaultFaker + } + + val := random_bool(f) + return null.From(val) + } + }) +} + +// Set the model columns to this value +func (m fileuploadPoolMods) ResidentPhone(val null.Val[string]) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.ResidentPhone = func() null.Val[string] { return val } + }) +} + +// Set the Column from the function +func (m fileuploadPoolMods) ResidentPhoneFunc(f func() null.Val[string]) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.ResidentPhone = f + }) +} + +// Clear any values for the column +func (m fileuploadPoolMods) UnsetResidentPhone() FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.ResidentPhone = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +// The generated value is sometimes null +func (m fileuploadPoolMods) RandomResidentPhone(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.ResidentPhone = func() null.Val[string] { + if f == nil { + f = &defaultFaker + } + + val := random_string(f) + return null.From(val) + } + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +// The generated value is never null +func (m fileuploadPoolMods) RandomResidentPhoneNotNull(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.ResidentPhone = func() null.Val[string] { + if f == nil { + f = &defaultFaker + } + + val := random_string(f) + return null.From(val) + } + }) +} + +// Set the model columns to this value +func (m fileuploadPoolMods) Version(val int32) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Version = func() int32 { return val } + }) +} + +// Set the Column from the function +func (m fileuploadPoolMods) VersionFunc(f func() int32) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Version = f + }) +} + +// Clear any values for the column +func (m fileuploadPoolMods) UnsetVersion() FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Version = nil + }) +} + +// Generates a random value for the column using the given faker +// if faker is nil, a default faker is used +func (m fileuploadPoolMods) RandomVersion(f *faker.Faker) FileuploadPoolMod { + return FileuploadPoolModFunc(func(_ context.Context, o *FileuploadPoolTemplate) { + o.Version = func() int32 { + return random_int32(f) + } + }) +} + +func (m fileuploadPoolMods) WithParentsCascading() FileuploadPoolMod { + return FileuploadPoolModFunc(func(ctx context.Context, o *FileuploadPoolTemplate) { + if isDone, _ := fileuploadPoolWithParentsCascadingCtx.Value(ctx); isDone { + return + } + ctx = fileuploadPoolWithParentsCascadingCtx.WithValue(ctx, true) + { + + related := o.f.NewUserWithContext(ctx, UserMods.WithParentsCascading()) + m.WithCreatorUser(related).Apply(ctx, o) + } + { + + related := o.f.NewFileuploadCSVWithContext(ctx, FileuploadCSVMods.WithParentsCascading()) + m.WithCSVFileCSV(related).Apply(ctx, o) + } + { + + related := o.f.NewOrganizationWithContext(ctx, OrganizationMods.WithParentsCascading()) + m.WithOrganization(related).Apply(ctx, o) + } + }) +} + +func (m fileuploadPoolMods) WithCreatorUser(rel *UserTemplate) FileuploadPoolMod { + return FileuploadPoolModFunc(func(ctx context.Context, o *FileuploadPoolTemplate) { + o.r.CreatorUser = &fileuploadPoolRCreatorUserR{ + o: rel, + } + }) +} + +func (m fileuploadPoolMods) WithNewCreatorUser(mods ...UserMod) FileuploadPoolMod { + return FileuploadPoolModFunc(func(ctx context.Context, o *FileuploadPoolTemplate) { + related := o.f.NewUserWithContext(ctx, mods...) + + m.WithCreatorUser(related).Apply(ctx, o) + }) +} + +func (m fileuploadPoolMods) WithExistingCreatorUser(em *models.User) FileuploadPoolMod { + return FileuploadPoolModFunc(func(ctx context.Context, o *FileuploadPoolTemplate) { + o.r.CreatorUser = &fileuploadPoolRCreatorUserR{ + o: o.f.FromExistingUser(em), + } + }) +} + +func (m fileuploadPoolMods) WithoutCreatorUser() FileuploadPoolMod { + return FileuploadPoolModFunc(func(ctx context.Context, o *FileuploadPoolTemplate) { + o.r.CreatorUser = nil + }) +} + +func (m fileuploadPoolMods) WithCSVFileCSV(rel *FileuploadCSVTemplate) FileuploadPoolMod { + return FileuploadPoolModFunc(func(ctx context.Context, o *FileuploadPoolTemplate) { + o.r.CSVFileCSV = &fileuploadPoolRCSVFileCSVR{ + o: rel, + } + }) +} + +func (m fileuploadPoolMods) WithNewCSVFileCSV(mods ...FileuploadCSVMod) FileuploadPoolMod { + return FileuploadPoolModFunc(func(ctx context.Context, o *FileuploadPoolTemplate) { + related := o.f.NewFileuploadCSVWithContext(ctx, mods...) + + m.WithCSVFileCSV(related).Apply(ctx, o) + }) +} + +func (m fileuploadPoolMods) WithExistingCSVFileCSV(em *models.FileuploadCSV) FileuploadPoolMod { + return FileuploadPoolModFunc(func(ctx context.Context, o *FileuploadPoolTemplate) { + o.r.CSVFileCSV = &fileuploadPoolRCSVFileCSVR{ + o: o.f.FromExistingFileuploadCSV(em), + } + }) +} + +func (m fileuploadPoolMods) WithoutCSVFileCSV() FileuploadPoolMod { + return FileuploadPoolModFunc(func(ctx context.Context, o *FileuploadPoolTemplate) { + o.r.CSVFileCSV = nil + }) +} + +func (m fileuploadPoolMods) WithOrganization(rel *OrganizationTemplate) FileuploadPoolMod { + return FileuploadPoolModFunc(func(ctx context.Context, o *FileuploadPoolTemplate) { + o.r.Organization = &fileuploadPoolROrganizationR{ + o: rel, + } + }) +} + +func (m fileuploadPoolMods) WithNewOrganization(mods ...OrganizationMod) FileuploadPoolMod { + return FileuploadPoolModFunc(func(ctx context.Context, o *FileuploadPoolTemplate) { + related := o.f.NewOrganizationWithContext(ctx, mods...) + + m.WithOrganization(related).Apply(ctx, o) + }) +} + +func (m fileuploadPoolMods) WithExistingOrganization(em *models.Organization) FileuploadPoolMod { + return FileuploadPoolModFunc(func(ctx context.Context, o *FileuploadPoolTemplate) { + o.r.Organization = &fileuploadPoolROrganizationR{ + o: o.f.FromExistingOrganization(em), + } + }) +} + +func (m fileuploadPoolMods) WithoutOrganization() FileuploadPoolMod { + return FileuploadPoolModFunc(func(ctx context.Context, o *FileuploadPoolTemplate) { + o.r.Organization = nil + }) +} diff --git a/db/factory/organization.bob.go b/db/factory/organization.bob.go index 8f546500..5cc58818 100644 --- a/db/factory/organization.bob.go +++ b/db/factory/organization.bob.go @@ -85,11 +85,11 @@ type organizationR struct { Zones2s []*organizationRZones2sR FieldseekerSyncs []*organizationRFieldseekerSyncsR Files []*organizationRFilesR + Pools []*organizationRPoolsR H3Aggregations []*organizationRH3AggregationsR NoteAudios []*organizationRNoteAudiosR NoteImages []*organizationRNoteImagesR ImportDistrictGidDistrict *organizationRImportDistrictGidDistrictR - Pools []*organizationRPoolsR Nuisances []*organizationRNuisancesR PublicreportPool []*organizationRPublicreportPoolR Quicks []*organizationRQuicksR @@ -220,6 +220,10 @@ type organizationRFilesR struct { number int o *FileuploadFileTemplate } +type organizationRPoolsR struct { + number int + o *FileuploadPoolTemplate +} type organizationRH3AggregationsR struct { number int o *H3AggregationTemplate @@ -235,10 +239,6 @@ type organizationRNoteImagesR struct { type organizationRImportDistrictGidDistrictR struct { o *ImportDistrictTemplate } -type organizationRPoolsR struct { - number int - o *PoolTemplate -} type organizationRNuisancesR struct { number int o *PublicreportNuisanceTemplate @@ -667,6 +667,19 @@ func (t OrganizationTemplate) setModelRels(o *models.Organization) { o.R.Files = rel } + if t.r.Pools != nil { + rel := models.FileuploadPoolSlice{} + for _, r := range t.r.Pools { + related := r.o.BuildMany(r.number) + for _, rel := range related { + rel.OrganizationID = o.ID // h2 + rel.R.Organization = o + } + rel = append(rel, related...) + } + o.R.Pools = rel + } + if t.r.H3Aggregations != nil { rel := models.H3AggregationSlice{} for _, r := range t.r.H3Aggregations { @@ -713,19 +726,6 @@ func (t OrganizationTemplate) setModelRels(o *models.Organization) { o.R.ImportDistrictGidDistrict = rel } - if t.r.Pools != nil { - rel := models.PoolSlice{} - for _, r := range t.r.Pools { - related := r.o.BuildMany(r.number) - for _, rel := range related { - rel.OrganizationID = o.ID // h2 - rel.R.Organization = o - } - rel = append(rel, related...) - } - o.R.Pools = rel - } - if t.r.Nuisances != nil { rel := models.PublicreportNuisanceSlice{} for _, r := range t.r.Nuisances { @@ -1521,6 +1521,26 @@ func (o *OrganizationTemplate) insertOptRels(ctx context.Context, exec bob.Execu } } + isPoolsDone, _ := organizationRelPoolsCtx.Value(ctx) + if !isPoolsDone && o.r.Pools != nil { + ctx = organizationRelPoolsCtx.WithValue(ctx, true) + for _, r := range o.r.Pools { + if r.o.alreadyPersisted { + m.R.Pools = append(m.R.Pools, r.o.Build()) + } else { + rel31, err := r.o.CreateMany(ctx, exec, r.number) + if err != nil { + return err + } + + err = m.AttachPools(ctx, exec, rel31...) + if err != nil { + return err + } + } + } + } + isH3AggregationsDone, _ := organizationRelH3AggregationsCtx.Value(ctx) if !isH3AggregationsDone && o.r.H3Aggregations != nil { ctx = organizationRelH3AggregationsCtx.WithValue(ctx, true) @@ -1528,12 +1548,12 @@ func (o *OrganizationTemplate) insertOptRels(ctx context.Context, exec bob.Execu if r.o.alreadyPersisted { m.R.H3Aggregations = append(m.R.H3Aggregations, r.o.Build()) } else { - rel31, err := r.o.CreateMany(ctx, exec, r.number) + rel32, err := r.o.CreateMany(ctx, exec, r.number) if err != nil { return err } - err = m.AttachH3Aggregations(ctx, exec, rel31...) + err = m.AttachH3Aggregations(ctx, exec, rel32...) if err != nil { return err } @@ -1548,12 +1568,12 @@ func (o *OrganizationTemplate) insertOptRels(ctx context.Context, exec bob.Execu if r.o.alreadyPersisted { m.R.NoteAudios = append(m.R.NoteAudios, r.o.Build()) } else { - rel32, err := r.o.CreateMany(ctx, exec, r.number) + rel33, err := r.o.CreateMany(ctx, exec, r.number) if err != nil { return err } - err = m.AttachNoteAudios(ctx, exec, rel32...) + err = m.AttachNoteAudios(ctx, exec, rel33...) if err != nil { return err } @@ -1568,12 +1588,12 @@ func (o *OrganizationTemplate) insertOptRels(ctx context.Context, exec bob.Execu if r.o.alreadyPersisted { m.R.NoteImages = append(m.R.NoteImages, r.o.Build()) } else { - rel33, err := r.o.CreateMany(ctx, exec, r.number) + rel34, err := r.o.CreateMany(ctx, exec, r.number) if err != nil { return err } - err = m.AttachNoteImages(ctx, exec, rel33...) + err = m.AttachNoteImages(ctx, exec, rel34...) if err != nil { return err } @@ -1587,12 +1607,12 @@ func (o *OrganizationTemplate) insertOptRels(ctx context.Context, exec bob.Execu if o.r.ImportDistrictGidDistrict.o.alreadyPersisted { m.R.ImportDistrictGidDistrict = o.r.ImportDistrictGidDistrict.o.Build() } else { - var rel34 *models.ImportDistrict - rel34, err = o.r.ImportDistrictGidDistrict.o.Create(ctx, exec) + var rel35 *models.ImportDistrict + rel35, err = o.r.ImportDistrictGidDistrict.o.Create(ctx, exec) if err != nil { return err } - err = m.AttachImportDistrictGidDistrict(ctx, exec, rel34) + err = m.AttachImportDistrictGidDistrict(ctx, exec, rel35) if err != nil { return err } @@ -1600,26 +1620,6 @@ func (o *OrganizationTemplate) insertOptRels(ctx context.Context, exec bob.Execu } - isPoolsDone, _ := organizationRelPoolsCtx.Value(ctx) - if !isPoolsDone && o.r.Pools != nil { - ctx = organizationRelPoolsCtx.WithValue(ctx, true) - for _, r := range o.r.Pools { - if r.o.alreadyPersisted { - m.R.Pools = append(m.R.Pools, r.o.Build()) - } else { - rel35, err := r.o.CreateMany(ctx, exec, r.number) - if err != nil { - return err - } - - err = m.AttachPools(ctx, exec, rel35...) - if err != nil { - return err - } - } - } - } - isNuisancesDone, _ := organizationRelNuisancesCtx.Value(ctx) if !isNuisancesDone && o.r.Nuisances != nil { ctx = organizationRelNuisancesCtx.WithValue(ctx, true) @@ -3769,6 +3769,54 @@ func (m organizationMods) WithoutFiles() OrganizationMod { }) } +func (m organizationMods) WithPools(number int, related *FileuploadPoolTemplate) OrganizationMod { + return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) { + o.r.Pools = []*organizationRPoolsR{{ + number: number, + o: related, + }} + }) +} + +func (m organizationMods) WithNewPools(number int, mods ...FileuploadPoolMod) OrganizationMod { + return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) { + related := o.f.NewFileuploadPoolWithContext(ctx, mods...) + m.WithPools(number, related).Apply(ctx, o) + }) +} + +func (m organizationMods) AddPools(number int, related *FileuploadPoolTemplate) OrganizationMod { + return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) { + o.r.Pools = append(o.r.Pools, &organizationRPoolsR{ + number: number, + o: related, + }) + }) +} + +func (m organizationMods) AddNewPools(number int, mods ...FileuploadPoolMod) OrganizationMod { + return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) { + related := o.f.NewFileuploadPoolWithContext(ctx, mods...) + m.AddPools(number, related).Apply(ctx, o) + }) +} + +func (m organizationMods) AddExistingPools(existingModels ...*models.FileuploadPool) OrganizationMod { + return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) { + for _, em := range existingModels { + o.r.Pools = append(o.r.Pools, &organizationRPoolsR{ + o: o.f.FromExistingFileuploadPool(em), + }) + } + }) +} + +func (m organizationMods) WithoutPools() OrganizationMod { + return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) { + o.r.Pools = nil + }) +} + func (m organizationMods) WithH3Aggregations(number int, related *H3AggregationTemplate) OrganizationMod { return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) { o.r.H3Aggregations = []*organizationRH3AggregationsR{{ @@ -3913,54 +3961,6 @@ func (m organizationMods) WithoutNoteImages() OrganizationMod { }) } -func (m organizationMods) WithPools(number int, related *PoolTemplate) OrganizationMod { - return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) { - o.r.Pools = []*organizationRPoolsR{{ - number: number, - o: related, - }} - }) -} - -func (m organizationMods) WithNewPools(number int, mods ...PoolMod) OrganizationMod { - return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) { - related := o.f.NewPoolWithContext(ctx, mods...) - m.WithPools(number, related).Apply(ctx, o) - }) -} - -func (m organizationMods) AddPools(number int, related *PoolTemplate) OrganizationMod { - return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) { - o.r.Pools = append(o.r.Pools, &organizationRPoolsR{ - number: number, - o: related, - }) - }) -} - -func (m organizationMods) AddNewPools(number int, mods ...PoolMod) OrganizationMod { - return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) { - related := o.f.NewPoolWithContext(ctx, mods...) - m.AddPools(number, related).Apply(ctx, o) - }) -} - -func (m organizationMods) AddExistingPools(existingModels ...*models.Pool) OrganizationMod { - return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) { - for _, em := range existingModels { - o.r.Pools = append(o.r.Pools, &organizationRPoolsR{ - o: o.f.FromExistingPool(em), - }) - } - }) -} - -func (m organizationMods) WithoutPools() OrganizationMod { - return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) { - o.r.Pools = nil - }) -} - func (m organizationMods) WithNuisances(number int, related *PublicreportNuisanceTemplate) OrganizationMod { return OrganizationModFunc(func(ctx context.Context, o *OrganizationTemplate) { o.r.Nuisances = []*organizationRNuisancesR{{ diff --git a/db/factory/pool.bob.go b/db/factory/pool.bob.go deleted file mode 100644 index 2cb3fec0..00000000 --- a/db/factory/pool.bob.go +++ /dev/null @@ -1,1121 +0,0 @@ -// Code generated by BobGen psql v0.42.5. DO NOT EDIT. -// This file is meant to be re-generated in place and/or deleted at any time. - -package factory - -import ( - "context" - "testing" - "time" - - "github.com/Gleipnir-Technology/bob" - enums "github.com/Gleipnir-Technology/nidus-sync/db/enums" - models "github.com/Gleipnir-Technology/nidus-sync/db/models" - "github.com/aarondl/opt/null" - "github.com/aarondl/opt/omit" - "github.com/aarondl/opt/omitnull" - "github.com/jaswdr/faker/v2" -) - -type PoolMod interface { - Apply(context.Context, *PoolTemplate) -} - -type PoolModFunc func(context.Context, *PoolTemplate) - -func (f PoolModFunc) Apply(ctx context.Context, n *PoolTemplate) { - f(ctx, n) -} - -type PoolModSlice []PoolMod - -func (mods PoolModSlice) Apply(ctx context.Context, n *PoolTemplate) { - for _, f := range mods { - f.Apply(ctx, n) - } -} - -// PoolTemplate is an object representing the database table. -// all columns are optional and should be set by mods -type PoolTemplate struct { - AddressCity func() string - AddressPostalCode func() string - AddressStreet func() string - Condition func() enums.Poolconditiontype - Created func() time.Time - CreatorID func() int32 - Deleted func() null.Val[time.Time] - Committed func() bool - ID func() int32 - Notes func() string - OrganizationID func() int32 - PropertyOwnerName func() string - PropertyOwnerPhone func() null.Val[string] - ResidentOwned func() null.Val[bool] - ResidentPhone func() null.Val[string] - Version func() int32 - - r poolR - f *Factory - - alreadyPersisted bool -} - -type poolR struct { - CreatorUser *poolRCreatorUserR - Organization *poolROrganizationR -} - -type poolRCreatorUserR struct { - o *UserTemplate -} -type poolROrganizationR struct { - o *OrganizationTemplate -} - -// Apply mods to the PoolTemplate -func (o *PoolTemplate) Apply(ctx context.Context, mods ...PoolMod) { - for _, mod := range mods { - mod.Apply(ctx, o) - } -} - -// setModelRels creates and sets the relationships on *models.Pool -// according to the relationships in the template. Nothing is inserted into the db -func (t PoolTemplate) setModelRels(o *models.Pool) { - if t.r.CreatorUser != nil { - rel := t.r.CreatorUser.o.Build() - rel.R.CreatorPools = append(rel.R.CreatorPools, o) - o.CreatorID = rel.ID // h2 - o.R.CreatorUser = rel - } - - if t.r.Organization != nil { - rel := t.r.Organization.o.Build() - rel.R.Pools = append(rel.R.Pools, o) - o.OrganizationID = rel.ID // h2 - o.R.Organization = rel - } -} - -// BuildSetter returns an *models.PoolSetter -// this does nothing with the relationship templates -func (o PoolTemplate) BuildSetter() *models.PoolSetter { - m := &models.PoolSetter{} - - if o.AddressCity != nil { - val := o.AddressCity() - m.AddressCity = omit.From(val) - } - if o.AddressPostalCode != nil { - val := o.AddressPostalCode() - m.AddressPostalCode = omit.From(val) - } - if o.AddressStreet != nil { - val := o.AddressStreet() - m.AddressStreet = omit.From(val) - } - if o.Condition != nil { - val := o.Condition() - m.Condition = omit.From(val) - } - if o.Created != nil { - val := o.Created() - m.Created = omit.From(val) - } - if o.CreatorID != nil { - val := o.CreatorID() - m.CreatorID = omit.From(val) - } - if o.Deleted != nil { - val := o.Deleted() - m.Deleted = omitnull.FromNull(val) - } - if o.Committed != nil { - val := o.Committed() - m.Committed = omit.From(val) - } - if o.ID != nil { - val := o.ID() - m.ID = omit.From(val) - } - if o.Notes != nil { - val := o.Notes() - m.Notes = omit.From(val) - } - if o.OrganizationID != nil { - val := o.OrganizationID() - m.OrganizationID = omit.From(val) - } - if o.PropertyOwnerName != nil { - val := o.PropertyOwnerName() - m.PropertyOwnerName = omit.From(val) - } - if o.PropertyOwnerPhone != nil { - val := o.PropertyOwnerPhone() - m.PropertyOwnerPhone = omitnull.FromNull(val) - } - if o.ResidentOwned != nil { - val := o.ResidentOwned() - m.ResidentOwned = omitnull.FromNull(val) - } - if o.ResidentPhone != nil { - val := o.ResidentPhone() - m.ResidentPhone = omitnull.FromNull(val) - } - if o.Version != nil { - val := o.Version() - m.Version = omit.From(val) - } - - return m -} - -// BuildManySetter returns an []*models.PoolSetter -// this does nothing with the relationship templates -func (o PoolTemplate) BuildManySetter(number int) []*models.PoolSetter { - m := make([]*models.PoolSetter, number) - - for i := range m { - m[i] = o.BuildSetter() - } - - return m -} - -// Build returns an *models.Pool -// Related objects are also created and placed in the .R field -// NOTE: Objects are not inserted into the database. Use PoolTemplate.Create -func (o PoolTemplate) Build() *models.Pool { - m := &models.Pool{} - - if o.AddressCity != nil { - m.AddressCity = o.AddressCity() - } - if o.AddressPostalCode != nil { - m.AddressPostalCode = o.AddressPostalCode() - } - if o.AddressStreet != nil { - m.AddressStreet = o.AddressStreet() - } - if o.Condition != nil { - m.Condition = o.Condition() - } - if o.Created != nil { - m.Created = o.Created() - } - if o.CreatorID != nil { - m.CreatorID = o.CreatorID() - } - if o.Deleted != nil { - m.Deleted = o.Deleted() - } - if o.Committed != nil { - m.Committed = o.Committed() - } - if o.ID != nil { - m.ID = o.ID() - } - if o.Notes != nil { - m.Notes = o.Notes() - } - if o.OrganizationID != nil { - m.OrganizationID = o.OrganizationID() - } - if o.PropertyOwnerName != nil { - m.PropertyOwnerName = o.PropertyOwnerName() - } - if o.PropertyOwnerPhone != nil { - m.PropertyOwnerPhone = o.PropertyOwnerPhone() - } - if o.ResidentOwned != nil { - m.ResidentOwned = o.ResidentOwned() - } - if o.ResidentPhone != nil { - m.ResidentPhone = o.ResidentPhone() - } - if o.Version != nil { - m.Version = o.Version() - } - - o.setModelRels(m) - - return m -} - -// BuildMany returns an models.PoolSlice -// Related objects are also created and placed in the .R field -// NOTE: Objects are not inserted into the database. Use PoolTemplate.CreateMany -func (o PoolTemplate) BuildMany(number int) models.PoolSlice { - m := make(models.PoolSlice, number) - - for i := range m { - m[i] = o.Build() - } - - return m -} - -func ensureCreatablePool(m *models.PoolSetter) { - if !(m.AddressCity.IsValue()) { - val := random_string(nil) - m.AddressCity = omit.From(val) - } - if !(m.AddressPostalCode.IsValue()) { - val := random_string(nil) - m.AddressPostalCode = omit.From(val) - } - if !(m.AddressStreet.IsValue()) { - val := random_string(nil) - m.AddressStreet = omit.From(val) - } - if !(m.Condition.IsValue()) { - val := random_enums_Poolconditiontype(nil) - m.Condition = omit.From(val) - } - if !(m.Created.IsValue()) { - val := random_time_Time(nil) - m.Created = omit.From(val) - } - if !(m.CreatorID.IsValue()) { - val := random_int32(nil) - m.CreatorID = omit.From(val) - } - if !(m.Committed.IsValue()) { - val := random_bool(nil) - m.Committed = omit.From(val) - } - if !(m.Notes.IsValue()) { - val := random_string(nil) - m.Notes = omit.From(val) - } - if !(m.OrganizationID.IsValue()) { - val := random_int32(nil) - m.OrganizationID = omit.From(val) - } - if !(m.PropertyOwnerName.IsValue()) { - val := random_string(nil) - m.PropertyOwnerName = omit.From(val) - } - if !(m.Version.IsValue()) { - val := random_int32(nil) - m.Version = omit.From(val) - } -} - -// insertOptRels creates and inserts any optional the relationships on *models.Pool -// according to the relationships in the template. -// any required relationship should have already exist on the model -func (o *PoolTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.Pool) error { - var err error - - return err -} - -// Create builds a pool and inserts it into the database -// Relations objects are also inserted and placed in the .R field -func (o *PoolTemplate) Create(ctx context.Context, exec bob.Executor) (*models.Pool, error) { - var err error - opt := o.BuildSetter() - ensureCreatablePool(opt) - - if o.r.CreatorUser == nil { - PoolMods.WithNewCreatorUser().Apply(ctx, o) - } - - var rel0 *models.User - - if o.r.CreatorUser.o.alreadyPersisted { - rel0 = o.r.CreatorUser.o.Build() - } else { - rel0, err = o.r.CreatorUser.o.Create(ctx, exec) - if err != nil { - return nil, err - } - } - - opt.CreatorID = omit.From(rel0.ID) - - if o.r.Organization == nil { - PoolMods.WithNewOrganization().Apply(ctx, o) - } - - var rel1 *models.Organization - - if o.r.Organization.o.alreadyPersisted { - rel1 = o.r.Organization.o.Build() - } else { - rel1, err = o.r.Organization.o.Create(ctx, exec) - if err != nil { - return nil, err - } - } - - opt.OrganizationID = omit.From(rel1.ID) - - m, err := models.Pools.Insert(opt).One(ctx, exec) - if err != nil { - return nil, err - } - - m.R.CreatorUser = rel0 - m.R.Organization = rel1 - - if err := o.insertOptRels(ctx, exec, m); err != nil { - return nil, err - } - return m, err -} - -// MustCreate builds a pool and inserts it into the database -// Relations objects are also inserted and placed in the .R field -// panics if an error occurs -func (o *PoolTemplate) MustCreate(ctx context.Context, exec bob.Executor) *models.Pool { - m, err := o.Create(ctx, exec) - if err != nil { - panic(err) - } - return m -} - -// CreateOrFail builds a pool and inserts it into the database -// Relations objects are also inserted and placed in the .R field -// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs -func (o *PoolTemplate) CreateOrFail(ctx context.Context, tb testing.TB, exec bob.Executor) *models.Pool { - tb.Helper() - m, err := o.Create(ctx, exec) - if err != nil { - tb.Fatal(err) - return nil - } - return m -} - -// CreateMany builds multiple pools and inserts them into the database -// Relations objects are also inserted and placed in the .R field -func (o PoolTemplate) CreateMany(ctx context.Context, exec bob.Executor, number int) (models.PoolSlice, error) { - var err error - m := make(models.PoolSlice, number) - - for i := range m { - m[i], err = o.Create(ctx, exec) - if err != nil { - return nil, err - } - } - - return m, nil -} - -// MustCreateMany builds multiple pools and inserts them into the database -// Relations objects are also inserted and placed in the .R field -// panics if an error occurs -func (o PoolTemplate) MustCreateMany(ctx context.Context, exec bob.Executor, number int) models.PoolSlice { - m, err := o.CreateMany(ctx, exec, number) - if err != nil { - panic(err) - } - return m -} - -// CreateManyOrFail builds multiple pools and inserts them into the database -// Relations objects are also inserted and placed in the .R field -// It calls `tb.Fatal(err)` on the test/benchmark if an error occurs -func (o PoolTemplate) CreateManyOrFail(ctx context.Context, tb testing.TB, exec bob.Executor, number int) models.PoolSlice { - tb.Helper() - m, err := o.CreateMany(ctx, exec, number) - if err != nil { - tb.Fatal(err) - return nil - } - return m -} - -// Pool has methods that act as mods for the PoolTemplate -var PoolMods poolMods - -type poolMods struct{} - -func (m poolMods) RandomizeAllColumns(f *faker.Faker) PoolMod { - return PoolModSlice{ - PoolMods.RandomAddressCity(f), - PoolMods.RandomAddressPostalCode(f), - PoolMods.RandomAddressStreet(f), - PoolMods.RandomCondition(f), - PoolMods.RandomCreated(f), - PoolMods.RandomCreatorID(f), - PoolMods.RandomDeleted(f), - PoolMods.RandomCommitted(f), - PoolMods.RandomID(f), - PoolMods.RandomNotes(f), - PoolMods.RandomOrganizationID(f), - PoolMods.RandomPropertyOwnerName(f), - PoolMods.RandomPropertyOwnerPhone(f), - PoolMods.RandomResidentOwned(f), - PoolMods.RandomResidentPhone(f), - PoolMods.RandomVersion(f), - } -} - -// Set the model columns to this value -func (m poolMods) AddressCity(val string) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.AddressCity = func() string { return val } - }) -} - -// Set the Column from the function -func (m poolMods) AddressCityFunc(f func() string) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.AddressCity = f - }) -} - -// Clear any values for the column -func (m poolMods) UnsetAddressCity() PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.AddressCity = nil - }) -} - -// Generates a random value for the column using the given faker -// if faker is nil, a default faker is used -func (m poolMods) RandomAddressCity(f *faker.Faker) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.AddressCity = func() string { - return random_string(f) - } - }) -} - -// Set the model columns to this value -func (m poolMods) AddressPostalCode(val string) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.AddressPostalCode = func() string { return val } - }) -} - -// Set the Column from the function -func (m poolMods) AddressPostalCodeFunc(f func() string) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.AddressPostalCode = f - }) -} - -// Clear any values for the column -func (m poolMods) UnsetAddressPostalCode() PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.AddressPostalCode = nil - }) -} - -// Generates a random value for the column using the given faker -// if faker is nil, a default faker is used -func (m poolMods) RandomAddressPostalCode(f *faker.Faker) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.AddressPostalCode = func() string { - return random_string(f) - } - }) -} - -// Set the model columns to this value -func (m poolMods) AddressStreet(val string) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.AddressStreet = func() string { return val } - }) -} - -// Set the Column from the function -func (m poolMods) AddressStreetFunc(f func() string) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.AddressStreet = f - }) -} - -// Clear any values for the column -func (m poolMods) UnsetAddressStreet() PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.AddressStreet = nil - }) -} - -// Generates a random value for the column using the given faker -// if faker is nil, a default faker is used -func (m poolMods) RandomAddressStreet(f *faker.Faker) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.AddressStreet = func() string { - return random_string(f) - } - }) -} - -// Set the model columns to this value -func (m poolMods) Condition(val enums.Poolconditiontype) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.Condition = func() enums.Poolconditiontype { return val } - }) -} - -// Set the Column from the function -func (m poolMods) ConditionFunc(f func() enums.Poolconditiontype) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.Condition = f - }) -} - -// Clear any values for the column -func (m poolMods) UnsetCondition() PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.Condition = nil - }) -} - -// Generates a random value for the column using the given faker -// if faker is nil, a default faker is used -func (m poolMods) RandomCondition(f *faker.Faker) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.Condition = func() enums.Poolconditiontype { - return random_enums_Poolconditiontype(f) - } - }) -} - -// Set the model columns to this value -func (m poolMods) Created(val time.Time) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.Created = func() time.Time { return val } - }) -} - -// Set the Column from the function -func (m poolMods) CreatedFunc(f func() time.Time) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.Created = f - }) -} - -// Clear any values for the column -func (m poolMods) UnsetCreated() PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.Created = nil - }) -} - -// Generates a random value for the column using the given faker -// if faker is nil, a default faker is used -func (m poolMods) RandomCreated(f *faker.Faker) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.Created = func() time.Time { - return random_time_Time(f) - } - }) -} - -// Set the model columns to this value -func (m poolMods) CreatorID(val int32) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.CreatorID = func() int32 { return val } - }) -} - -// Set the Column from the function -func (m poolMods) CreatorIDFunc(f func() int32) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.CreatorID = f - }) -} - -// Clear any values for the column -func (m poolMods) UnsetCreatorID() PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.CreatorID = nil - }) -} - -// Generates a random value for the column using the given faker -// if faker is nil, a default faker is used -func (m poolMods) RandomCreatorID(f *faker.Faker) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.CreatorID = func() int32 { - return random_int32(f) - } - }) -} - -// Set the model columns to this value -func (m poolMods) Deleted(val null.Val[time.Time]) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.Deleted = func() null.Val[time.Time] { return val } - }) -} - -// Set the Column from the function -func (m poolMods) DeletedFunc(f func() null.Val[time.Time]) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.Deleted = f - }) -} - -// Clear any values for the column -func (m poolMods) UnsetDeleted() PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.Deleted = nil - }) -} - -// Generates a random value for the column using the given faker -// if faker is nil, a default faker is used -// The generated value is sometimes null -func (m poolMods) RandomDeleted(f *faker.Faker) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.Deleted = func() null.Val[time.Time] { - if f == nil { - f = &defaultFaker - } - - val := random_time_Time(f) - return null.From(val) - } - }) -} - -// Generates a random value for the column using the given faker -// if faker is nil, a default faker is used -// The generated value is never null -func (m poolMods) RandomDeletedNotNull(f *faker.Faker) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.Deleted = func() null.Val[time.Time] { - if f == nil { - f = &defaultFaker - } - - val := random_time_Time(f) - return null.From(val) - } - }) -} - -// Set the model columns to this value -func (m poolMods) Committed(val bool) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.Committed = func() bool { return val } - }) -} - -// Set the Column from the function -func (m poolMods) CommittedFunc(f func() bool) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.Committed = f - }) -} - -// Clear any values for the column -func (m poolMods) UnsetCommitted() PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.Committed = nil - }) -} - -// Generates a random value for the column using the given faker -// if faker is nil, a default faker is used -func (m poolMods) RandomCommitted(f *faker.Faker) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.Committed = func() bool { - return random_bool(f) - } - }) -} - -// Set the model columns to this value -func (m poolMods) ID(val int32) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.ID = func() int32 { return val } - }) -} - -// Set the Column from the function -func (m poolMods) IDFunc(f func() int32) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.ID = f - }) -} - -// Clear any values for the column -func (m poolMods) UnsetID() PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.ID = nil - }) -} - -// Generates a random value for the column using the given faker -// if faker is nil, a default faker is used -func (m poolMods) RandomID(f *faker.Faker) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.ID = func() int32 { - return random_int32(f) - } - }) -} - -// Set the model columns to this value -func (m poolMods) Notes(val string) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.Notes = func() string { return val } - }) -} - -// Set the Column from the function -func (m poolMods) NotesFunc(f func() string) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.Notes = f - }) -} - -// Clear any values for the column -func (m poolMods) UnsetNotes() PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.Notes = nil - }) -} - -// Generates a random value for the column using the given faker -// if faker is nil, a default faker is used -func (m poolMods) RandomNotes(f *faker.Faker) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.Notes = func() string { - return random_string(f) - } - }) -} - -// Set the model columns to this value -func (m poolMods) OrganizationID(val int32) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.OrganizationID = func() int32 { return val } - }) -} - -// Set the Column from the function -func (m poolMods) OrganizationIDFunc(f func() int32) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.OrganizationID = f - }) -} - -// Clear any values for the column -func (m poolMods) UnsetOrganizationID() PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.OrganizationID = nil - }) -} - -// Generates a random value for the column using the given faker -// if faker is nil, a default faker is used -func (m poolMods) RandomOrganizationID(f *faker.Faker) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.OrganizationID = func() int32 { - return random_int32(f) - } - }) -} - -// Set the model columns to this value -func (m poolMods) PropertyOwnerName(val string) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.PropertyOwnerName = func() string { return val } - }) -} - -// Set the Column from the function -func (m poolMods) PropertyOwnerNameFunc(f func() string) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.PropertyOwnerName = f - }) -} - -// Clear any values for the column -func (m poolMods) UnsetPropertyOwnerName() PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.PropertyOwnerName = nil - }) -} - -// Generates a random value for the column using the given faker -// if faker is nil, a default faker is used -func (m poolMods) RandomPropertyOwnerName(f *faker.Faker) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.PropertyOwnerName = func() string { - return random_string(f) - } - }) -} - -// Set the model columns to this value -func (m poolMods) PropertyOwnerPhone(val null.Val[string]) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.PropertyOwnerPhone = func() null.Val[string] { return val } - }) -} - -// Set the Column from the function -func (m poolMods) PropertyOwnerPhoneFunc(f func() null.Val[string]) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.PropertyOwnerPhone = f - }) -} - -// Clear any values for the column -func (m poolMods) UnsetPropertyOwnerPhone() PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.PropertyOwnerPhone = nil - }) -} - -// Generates a random value for the column using the given faker -// if faker is nil, a default faker is used -// The generated value is sometimes null -func (m poolMods) RandomPropertyOwnerPhone(f *faker.Faker) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.PropertyOwnerPhone = func() null.Val[string] { - if f == nil { - f = &defaultFaker - } - - val := random_string(f) - return null.From(val) - } - }) -} - -// Generates a random value for the column using the given faker -// if faker is nil, a default faker is used -// The generated value is never null -func (m poolMods) RandomPropertyOwnerPhoneNotNull(f *faker.Faker) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.PropertyOwnerPhone = func() null.Val[string] { - if f == nil { - f = &defaultFaker - } - - val := random_string(f) - return null.From(val) - } - }) -} - -// Set the model columns to this value -func (m poolMods) ResidentOwned(val null.Val[bool]) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.ResidentOwned = func() null.Val[bool] { return val } - }) -} - -// Set the Column from the function -func (m poolMods) ResidentOwnedFunc(f func() null.Val[bool]) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.ResidentOwned = f - }) -} - -// Clear any values for the column -func (m poolMods) UnsetResidentOwned() PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.ResidentOwned = nil - }) -} - -// Generates a random value for the column using the given faker -// if faker is nil, a default faker is used -// The generated value is sometimes null -func (m poolMods) RandomResidentOwned(f *faker.Faker) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.ResidentOwned = func() null.Val[bool] { - if f == nil { - f = &defaultFaker - } - - val := random_bool(f) - return null.From(val) - } - }) -} - -// Generates a random value for the column using the given faker -// if faker is nil, a default faker is used -// The generated value is never null -func (m poolMods) RandomResidentOwnedNotNull(f *faker.Faker) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.ResidentOwned = func() null.Val[bool] { - if f == nil { - f = &defaultFaker - } - - val := random_bool(f) - return null.From(val) - } - }) -} - -// Set the model columns to this value -func (m poolMods) ResidentPhone(val null.Val[string]) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.ResidentPhone = func() null.Val[string] { return val } - }) -} - -// Set the Column from the function -func (m poolMods) ResidentPhoneFunc(f func() null.Val[string]) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.ResidentPhone = f - }) -} - -// Clear any values for the column -func (m poolMods) UnsetResidentPhone() PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.ResidentPhone = nil - }) -} - -// Generates a random value for the column using the given faker -// if faker is nil, a default faker is used -// The generated value is sometimes null -func (m poolMods) RandomResidentPhone(f *faker.Faker) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.ResidentPhone = func() null.Val[string] { - if f == nil { - f = &defaultFaker - } - - val := random_string(f) - return null.From(val) - } - }) -} - -// Generates a random value for the column using the given faker -// if faker is nil, a default faker is used -// The generated value is never null -func (m poolMods) RandomResidentPhoneNotNull(f *faker.Faker) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.ResidentPhone = func() null.Val[string] { - if f == nil { - f = &defaultFaker - } - - val := random_string(f) - return null.From(val) - } - }) -} - -// Set the model columns to this value -func (m poolMods) Version(val int32) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.Version = func() int32 { return val } - }) -} - -// Set the Column from the function -func (m poolMods) VersionFunc(f func() int32) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.Version = f - }) -} - -// Clear any values for the column -func (m poolMods) UnsetVersion() PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.Version = nil - }) -} - -// Generates a random value for the column using the given faker -// if faker is nil, a default faker is used -func (m poolMods) RandomVersion(f *faker.Faker) PoolMod { - return PoolModFunc(func(_ context.Context, o *PoolTemplate) { - o.Version = func() int32 { - return random_int32(f) - } - }) -} - -func (m poolMods) WithParentsCascading() PoolMod { - return PoolModFunc(func(ctx context.Context, o *PoolTemplate) { - if isDone, _ := poolWithParentsCascadingCtx.Value(ctx); isDone { - return - } - ctx = poolWithParentsCascadingCtx.WithValue(ctx, true) - { - - related := o.f.NewUserWithContext(ctx, UserMods.WithParentsCascading()) - m.WithCreatorUser(related).Apply(ctx, o) - } - { - - related := o.f.NewOrganizationWithContext(ctx, OrganizationMods.WithParentsCascading()) - m.WithOrganization(related).Apply(ctx, o) - } - }) -} - -func (m poolMods) WithCreatorUser(rel *UserTemplate) PoolMod { - return PoolModFunc(func(ctx context.Context, o *PoolTemplate) { - o.r.CreatorUser = &poolRCreatorUserR{ - o: rel, - } - }) -} - -func (m poolMods) WithNewCreatorUser(mods ...UserMod) PoolMod { - return PoolModFunc(func(ctx context.Context, o *PoolTemplate) { - related := o.f.NewUserWithContext(ctx, mods...) - - m.WithCreatorUser(related).Apply(ctx, o) - }) -} - -func (m poolMods) WithExistingCreatorUser(em *models.User) PoolMod { - return PoolModFunc(func(ctx context.Context, o *PoolTemplate) { - o.r.CreatorUser = &poolRCreatorUserR{ - o: o.f.FromExistingUser(em), - } - }) -} - -func (m poolMods) WithoutCreatorUser() PoolMod { - return PoolModFunc(func(ctx context.Context, o *PoolTemplate) { - o.r.CreatorUser = nil - }) -} - -func (m poolMods) WithOrganization(rel *OrganizationTemplate) PoolMod { - return PoolModFunc(func(ctx context.Context, o *PoolTemplate) { - o.r.Organization = &poolROrganizationR{ - o: rel, - } - }) -} - -func (m poolMods) WithNewOrganization(mods ...OrganizationMod) PoolMod { - return PoolModFunc(func(ctx context.Context, o *PoolTemplate) { - related := o.f.NewOrganizationWithContext(ctx, mods...) - - m.WithOrganization(related).Apply(ctx, o) - }) -} - -func (m poolMods) WithExistingOrganization(em *models.Organization) PoolMod { - return PoolModFunc(func(ctx context.Context, o *PoolTemplate) { - o.r.Organization = &poolROrganizationR{ - o: o.f.FromExistingOrganization(em), - } - }) -} - -func (m poolMods) WithoutOrganization() PoolMod { - return PoolModFunc(func(ctx context.Context, o *PoolTemplate) { - o.r.Organization = nil - }) -} diff --git a/db/factory/user_.bob.go b/db/factory/user_.bob.go index 06ac5aed..35cad5d3 100644 --- a/db/factory/user_.bob.go +++ b/db/factory/user_.bob.go @@ -60,13 +60,13 @@ type UserTemplate struct { type userR struct { PublicUserUser []*userRPublicUserUserR CreatorFiles []*userRCreatorFilesR + CreatorPools []*userRCreatorPoolsR CreatorNoteAudios []*userRCreatorNoteAudiosR DeletorNoteAudios []*userRDeletorNoteAudiosR CreatorNoteImages []*userRCreatorNoteImagesR DeletorNoteImages []*userRDeletorNoteImagesR UserNotifications []*userRUserNotificationsR UserOauthTokens []*userRUserOauthTokensR - CreatorPools []*userRCreatorPoolsR Organization *userROrganizationR } @@ -78,6 +78,10 @@ type userRCreatorFilesR struct { number int o *FileuploadFileTemplate } +type userRCreatorPoolsR struct { + number int + o *FileuploadPoolTemplate +} type userRCreatorNoteAudiosR struct { number int o *NoteAudioTemplate @@ -102,10 +106,6 @@ type userRUserOauthTokensR struct { number int o *OauthTokenTemplate } -type userRCreatorPoolsR struct { - number int - o *PoolTemplate -} type userROrganizationR struct { o *OrganizationTemplate } @@ -146,6 +146,19 @@ func (t UserTemplate) setModelRels(o *models.User) { o.R.CreatorFiles = rel } + if t.r.CreatorPools != nil { + rel := models.FileuploadPoolSlice{} + for _, r := range t.r.CreatorPools { + related := r.o.BuildMany(r.number) + for _, rel := range related { + rel.CreatorID = o.ID // h2 + rel.R.CreatorUser = o + } + rel = append(rel, related...) + } + o.R.CreatorPools = rel + } + if t.r.CreatorNoteAudios != nil { rel := models.NoteAudioSlice{} for _, r := range t.r.CreatorNoteAudios { @@ -224,19 +237,6 @@ func (t UserTemplate) setModelRels(o *models.User) { o.R.UserOauthTokens = rel } - if t.r.CreatorPools != nil { - rel := models.PoolSlice{} - for _, r := range t.r.CreatorPools { - related := r.o.BuildMany(r.number) - for _, rel := range related { - rel.CreatorID = o.ID // h2 - rel.R.CreatorUser = o - } - rel = append(rel, related...) - } - o.R.CreatorPools = rel - } - if t.r.Organization != nil { rel := t.r.Organization.o.Build() rel.R.User = append(rel.R.User, o) @@ -444,6 +444,26 @@ func (o *UserTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m * } } + isCreatorPoolsDone, _ := userRelCreatorPoolsCtx.Value(ctx) + if !isCreatorPoolsDone && o.r.CreatorPools != nil { + ctx = userRelCreatorPoolsCtx.WithValue(ctx, true) + for _, r := range o.r.CreatorPools { + if r.o.alreadyPersisted { + m.R.CreatorPools = append(m.R.CreatorPools, r.o.Build()) + } else { + rel2, err := r.o.CreateMany(ctx, exec, r.number) + if err != nil { + return err + } + + err = m.AttachCreatorPools(ctx, exec, rel2...) + if err != nil { + return err + } + } + } + } + isCreatorNoteAudiosDone, _ := userRelCreatorNoteAudiosCtx.Value(ctx) if !isCreatorNoteAudiosDone && o.r.CreatorNoteAudios != nil { ctx = userRelCreatorNoteAudiosCtx.WithValue(ctx, true) @@ -451,12 +471,12 @@ func (o *UserTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m * if r.o.alreadyPersisted { m.R.CreatorNoteAudios = append(m.R.CreatorNoteAudios, r.o.Build()) } else { - rel2, err := r.o.CreateMany(ctx, exec, r.number) + rel3, err := r.o.CreateMany(ctx, exec, r.number) if err != nil { return err } - err = m.AttachCreatorNoteAudios(ctx, exec, rel2...) + err = m.AttachCreatorNoteAudios(ctx, exec, rel3...) if err != nil { return err } @@ -471,12 +491,12 @@ func (o *UserTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m * if r.o.alreadyPersisted { m.R.DeletorNoteAudios = append(m.R.DeletorNoteAudios, r.o.Build()) } else { - rel3, err := r.o.CreateMany(ctx, exec, r.number) + rel4, err := r.o.CreateMany(ctx, exec, r.number) if err != nil { return err } - err = m.AttachDeletorNoteAudios(ctx, exec, rel3...) + err = m.AttachDeletorNoteAudios(ctx, exec, rel4...) if err != nil { return err } @@ -491,12 +511,12 @@ func (o *UserTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m * if r.o.alreadyPersisted { m.R.CreatorNoteImages = append(m.R.CreatorNoteImages, r.o.Build()) } else { - rel4, err := r.o.CreateMany(ctx, exec, r.number) + rel5, err := r.o.CreateMany(ctx, exec, r.number) if err != nil { return err } - err = m.AttachCreatorNoteImages(ctx, exec, rel4...) + err = m.AttachCreatorNoteImages(ctx, exec, rel5...) if err != nil { return err } @@ -511,12 +531,12 @@ func (o *UserTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m * if r.o.alreadyPersisted { m.R.DeletorNoteImages = append(m.R.DeletorNoteImages, r.o.Build()) } else { - rel5, err := r.o.CreateMany(ctx, exec, r.number) + rel6, err := r.o.CreateMany(ctx, exec, r.number) if err != nil { return err } - err = m.AttachDeletorNoteImages(ctx, exec, rel5...) + err = m.AttachDeletorNoteImages(ctx, exec, rel6...) if err != nil { return err } @@ -531,12 +551,12 @@ func (o *UserTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m * if r.o.alreadyPersisted { m.R.UserNotifications = append(m.R.UserNotifications, r.o.Build()) } else { - rel6, err := r.o.CreateMany(ctx, exec, r.number) + rel7, err := r.o.CreateMany(ctx, exec, r.number) if err != nil { return err } - err = m.AttachUserNotifications(ctx, exec, rel6...) + err = m.AttachUserNotifications(ctx, exec, rel7...) if err != nil { return err } @@ -550,33 +570,13 @@ func (o *UserTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m * for _, r := range o.r.UserOauthTokens { if r.o.alreadyPersisted { m.R.UserOauthTokens = append(m.R.UserOauthTokens, r.o.Build()) - } else { - rel7, err := r.o.CreateMany(ctx, exec, r.number) - if err != nil { - return err - } - - err = m.AttachUserOauthTokens(ctx, exec, rel7...) - if err != nil { - return err - } - } - } - } - - isCreatorPoolsDone, _ := userRelCreatorPoolsCtx.Value(ctx) - if !isCreatorPoolsDone && o.r.CreatorPools != nil { - ctx = userRelCreatorPoolsCtx.WithValue(ctx, true) - for _, r := range o.r.CreatorPools { - if r.o.alreadyPersisted { - m.R.CreatorPools = append(m.R.CreatorPools, r.o.Build()) } else { rel8, err := r.o.CreateMany(ctx, exec, r.number) if err != nil { return err } - err = m.AttachCreatorPools(ctx, exec, rel8...) + err = m.AttachUserOauthTokens(ctx, exec, rel8...) if err != nil { return err } @@ -1354,6 +1354,54 @@ func (m userMods) WithoutCreatorFiles() UserMod { }) } +func (m userMods) WithCreatorPools(number int, related *FileuploadPoolTemplate) UserMod { + return UserModFunc(func(ctx context.Context, o *UserTemplate) { + o.r.CreatorPools = []*userRCreatorPoolsR{{ + number: number, + o: related, + }} + }) +} + +func (m userMods) WithNewCreatorPools(number int, mods ...FileuploadPoolMod) UserMod { + return UserModFunc(func(ctx context.Context, o *UserTemplate) { + related := o.f.NewFileuploadPoolWithContext(ctx, mods...) + m.WithCreatorPools(number, related).Apply(ctx, o) + }) +} + +func (m userMods) AddCreatorPools(number int, related *FileuploadPoolTemplate) UserMod { + return UserModFunc(func(ctx context.Context, o *UserTemplate) { + o.r.CreatorPools = append(o.r.CreatorPools, &userRCreatorPoolsR{ + number: number, + o: related, + }) + }) +} + +func (m userMods) AddNewCreatorPools(number int, mods ...FileuploadPoolMod) UserMod { + return UserModFunc(func(ctx context.Context, o *UserTemplate) { + related := o.f.NewFileuploadPoolWithContext(ctx, mods...) + m.AddCreatorPools(number, related).Apply(ctx, o) + }) +} + +func (m userMods) AddExistingCreatorPools(existingModels ...*models.FileuploadPool) UserMod { + return UserModFunc(func(ctx context.Context, o *UserTemplate) { + for _, em := range existingModels { + o.r.CreatorPools = append(o.r.CreatorPools, &userRCreatorPoolsR{ + o: o.f.FromExistingFileuploadPool(em), + }) + } + }) +} + +func (m userMods) WithoutCreatorPools() UserMod { + return UserModFunc(func(ctx context.Context, o *UserTemplate) { + o.r.CreatorPools = nil + }) +} + func (m userMods) WithCreatorNoteAudios(number int, related *NoteAudioTemplate) UserMod { return UserModFunc(func(ctx context.Context, o *UserTemplate) { o.r.CreatorNoteAudios = []*userRCreatorNoteAudiosR{{ @@ -1641,51 +1689,3 @@ func (m userMods) WithoutUserOauthTokens() UserMod { o.r.UserOauthTokens = nil }) } - -func (m userMods) WithCreatorPools(number int, related *PoolTemplate) UserMod { - return UserModFunc(func(ctx context.Context, o *UserTemplate) { - o.r.CreatorPools = []*userRCreatorPoolsR{{ - number: number, - o: related, - }} - }) -} - -func (m userMods) WithNewCreatorPools(number int, mods ...PoolMod) UserMod { - return UserModFunc(func(ctx context.Context, o *UserTemplate) { - related := o.f.NewPoolWithContext(ctx, mods...) - m.WithCreatorPools(number, related).Apply(ctx, o) - }) -} - -func (m userMods) AddCreatorPools(number int, related *PoolTemplate) UserMod { - return UserModFunc(func(ctx context.Context, o *UserTemplate) { - o.r.CreatorPools = append(o.r.CreatorPools, &userRCreatorPoolsR{ - number: number, - o: related, - }) - }) -} - -func (m userMods) AddNewCreatorPools(number int, mods ...PoolMod) UserMod { - return UserModFunc(func(ctx context.Context, o *UserTemplate) { - related := o.f.NewPoolWithContext(ctx, mods...) - m.AddCreatorPools(number, related).Apply(ctx, o) - }) -} - -func (m userMods) AddExistingCreatorPools(existingModels ...*models.Pool) UserMod { - return UserModFunc(func(ctx context.Context, o *UserTemplate) { - for _, em := range existingModels { - o.r.CreatorPools = append(o.r.CreatorPools, &userRCreatorPoolsR{ - o: o.f.FromExistingPool(em), - }) - } - }) -} - -func (m userMods) WithoutCreatorPools() UserMod { - return UserModFunc(func(ctx context.Context, o *UserTemplate) { - o.r.CreatorPools = nil - }) -} diff --git a/db/migrations/00057_csv_pool_upload.sql b/db/migrations/00057_csv_pool_upload.sql index da25b85e..da6b25d9 100644 --- a/db/migrations/00057_csv_pool_upload.sql +++ b/db/migrations/00057_csv_pool_upload.sql @@ -42,22 +42,27 @@ CREATE TABLE fileupload.error_csv ( message TEXT NOT NULL, PRIMARY KEY (id) ); -CREATE TYPE PoolConditionType AS ENUM ( +CREATE TYPE fileupload.PoolConditionType AS ENUM ( 'green', 'murky', 'blue', 'unknown' ); -CREATE TABLE pool ( +CREATE TABLE fileupload.pool ( address_city TEXT NOT NULL, address_postal_code TEXT NOT NULL, address_street TEXT NOT NULL, - condition PoolConditionType NOT NULL, + committed BOOLEAN NOT NULL, -- Whether or not its just proposed before a CSV file is committed + condition fileupload.PoolConditionType NOT NULL, created TIMESTAMP WITHOUT TIME ZONE NOT NULL, creator_id INTEGER REFERENCES user_(id) NOT NULL, + csv_file INTEGER REFERENCES fileupload.csv(file_id) NOT NULL, deleted TIMESTAMP WITHOUT TIME ZONE, - committed BOOLEAN NOT NULL, -- Whether or not its just proposed before a CSV file is committed + geom geometry(Point, 3857), + h3cell h3index, id SERIAL, + is_in_district BOOLEAN NOT NULL, -- Whether or not the pool is within the district + is_new BOOLEAN NOT NULL, -- Whether or not we already have a pool in the system for this row notes TEXT NOT NULL, organization_id INTEGER REFERENCES organization(id) NOT NULL, property_owner_name TEXT NOT NULL, @@ -68,8 +73,8 @@ CREATE TABLE pool ( PRIMARY KEY (id, version) ); -- +goose Down -DROP TABLE pool; -DROP TYPE poolconditiontype; +DROP TABLE fileupload.pool; +DROP TYPE fileupload.PoolConditionType; DROP TABLE fileupload.error_csv; DROP TABLE fileupload.error_file; DROP TABLE fileupload.csv; diff --git a/db/models/bob_joins.bob.go b/db/models/bob_joins.bob.go index 5dc4a169..d029bf20 100644 --- a/db/models/bob_joins.bob.go +++ b/db/models/bob_joins.bob.go @@ -74,6 +74,7 @@ type joins[Q dialect.Joinable] struct { FileuploadErrorCSVS joinSet[fileuploadErrorCSVJoins[Q]] FileuploadErrorFiles joinSet[fileuploadErrorFileJoins[Q]] FileuploadFiles joinSet[fileuploadFileJoins[Q]] + FileuploadPools joinSet[fileuploadPoolJoins[Q]] H3Aggregations joinSet[h3AggregationJoins[Q]] ImportDistricts joinSet[importDistrictJoins[Q]] NoteAudios joinSet[noteAudioJoins[Q]] @@ -85,7 +86,6 @@ type joins[Q dialect.Joinable] struct { Notifications joinSet[notificationJoins[Q]] OauthTokens joinSet[oauthTokenJoins[Q]] Organizations joinSet[organizationJoins[Q]] - Pools joinSet[poolJoins[Q]] PublicreportImages joinSet[publicreportImageJoins[Q]] PublicreportImageExifs joinSet[publicreportImageExifJoins[Q]] PublicreportNotifyEmailNuisances joinSet[publicreportNotifyEmailNuisanceJoins[Q]] @@ -153,6 +153,7 @@ func getJoins[Q dialect.Joinable]() joins[Q] { FileuploadErrorCSVS: buildJoinSet[fileuploadErrorCSVJoins[Q]](FileuploadErrorCSVS.Columns, buildFileuploadErrorCSVJoins), FileuploadErrorFiles: buildJoinSet[fileuploadErrorFileJoins[Q]](FileuploadErrorFiles.Columns, buildFileuploadErrorFileJoins), FileuploadFiles: buildJoinSet[fileuploadFileJoins[Q]](FileuploadFiles.Columns, buildFileuploadFileJoins), + FileuploadPools: buildJoinSet[fileuploadPoolJoins[Q]](FileuploadPools.Columns, buildFileuploadPoolJoins), H3Aggregations: buildJoinSet[h3AggregationJoins[Q]](H3Aggregations.Columns, buildH3AggregationJoins), ImportDistricts: buildJoinSet[importDistrictJoins[Q]](ImportDistricts.Columns, buildImportDistrictJoins), NoteAudios: buildJoinSet[noteAudioJoins[Q]](NoteAudios.Columns, buildNoteAudioJoins), @@ -164,7 +165,6 @@ func getJoins[Q dialect.Joinable]() joins[Q] { Notifications: buildJoinSet[notificationJoins[Q]](Notifications.Columns, buildNotificationJoins), OauthTokens: buildJoinSet[oauthTokenJoins[Q]](OauthTokens.Columns, buildOauthTokenJoins), Organizations: buildJoinSet[organizationJoins[Q]](Organizations.Columns, buildOrganizationJoins), - Pools: buildJoinSet[poolJoins[Q]](Pools.Columns, buildPoolJoins), PublicreportImages: buildJoinSet[publicreportImageJoins[Q]](PublicreportImages.Columns, buildPublicreportImageJoins), PublicreportImageExifs: buildJoinSet[publicreportImageExifJoins[Q]](PublicreportImageExifs.Columns, buildPublicreportImageExifJoins), PublicreportNotifyEmailNuisances: buildJoinSet[publicreportNotifyEmailNuisanceJoins[Q]](PublicreportNotifyEmailNuisances.Columns, buildPublicreportNotifyEmailNuisanceJoins), diff --git a/db/models/bob_loaders.bob.go b/db/models/bob_loaders.bob.go index 3e90e0fb..caacacd9 100644 --- a/db/models/bob_loaders.bob.go +++ b/db/models/bob_loaders.bob.go @@ -59,6 +59,7 @@ type preloaders struct { FileuploadErrorCSV fileuploadErrorCSVPreloader FileuploadErrorFile fileuploadErrorFilePreloader FileuploadFile fileuploadFilePreloader + FileuploadPool fileuploadPoolPreloader H3Aggregation h3AggregationPreloader ImportDistrict importDistrictPreloader NoteAudio noteAudioPreloader @@ -70,7 +71,6 @@ type preloaders struct { Notification notificationPreloader OauthToken oauthTokenPreloader Organization organizationPreloader - Pool poolPreloader PublicreportImage publicreportImagePreloader PublicreportImageExif publicreportImageExifPreloader PublicreportNotifyEmailNuisance publicreportNotifyEmailNuisancePreloader @@ -130,6 +130,7 @@ func getPreloaders() preloaders { FileuploadErrorCSV: buildFileuploadErrorCSVPreloader(), FileuploadErrorFile: buildFileuploadErrorFilePreloader(), FileuploadFile: buildFileuploadFilePreloader(), + FileuploadPool: buildFileuploadPoolPreloader(), H3Aggregation: buildH3AggregationPreloader(), ImportDistrict: buildImportDistrictPreloader(), NoteAudio: buildNoteAudioPreloader(), @@ -141,7 +142,6 @@ func getPreloaders() preloaders { Notification: buildNotificationPreloader(), OauthToken: buildOauthTokenPreloader(), Organization: buildOrganizationPreloader(), - Pool: buildPoolPreloader(), PublicreportImage: buildPublicreportImagePreloader(), PublicreportImageExif: buildPublicreportImageExifPreloader(), PublicreportNotifyEmailNuisance: buildPublicreportNotifyEmailNuisancePreloader(), @@ -207,6 +207,7 @@ type thenLoaders[Q orm.Loadable] struct { FileuploadErrorCSV fileuploadErrorCSVThenLoader[Q] FileuploadErrorFile fileuploadErrorFileThenLoader[Q] FileuploadFile fileuploadFileThenLoader[Q] + FileuploadPool fileuploadPoolThenLoader[Q] H3Aggregation h3AggregationThenLoader[Q] ImportDistrict importDistrictThenLoader[Q] NoteAudio noteAudioThenLoader[Q] @@ -218,7 +219,6 @@ type thenLoaders[Q orm.Loadable] struct { Notification notificationThenLoader[Q] OauthToken oauthTokenThenLoader[Q] Organization organizationThenLoader[Q] - Pool poolThenLoader[Q] PublicreportImage publicreportImageThenLoader[Q] PublicreportImageExif publicreportImageExifThenLoader[Q] PublicreportNotifyEmailNuisance publicreportNotifyEmailNuisanceThenLoader[Q] @@ -278,6 +278,7 @@ func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] { FileuploadErrorCSV: buildFileuploadErrorCSVThenLoader[Q](), FileuploadErrorFile: buildFileuploadErrorFileThenLoader[Q](), FileuploadFile: buildFileuploadFileThenLoader[Q](), + FileuploadPool: buildFileuploadPoolThenLoader[Q](), H3Aggregation: buildH3AggregationThenLoader[Q](), ImportDistrict: buildImportDistrictThenLoader[Q](), NoteAudio: buildNoteAudioThenLoader[Q](), @@ -289,7 +290,6 @@ func getThenLoaders[Q orm.Loadable]() thenLoaders[Q] { Notification: buildNotificationThenLoader[Q](), OauthToken: buildOauthTokenThenLoader[Q](), Organization: buildOrganizationThenLoader[Q](), - Pool: buildPoolThenLoader[Q](), PublicreportImage: buildPublicreportImageThenLoader[Q](), PublicreportImageExif: buildPublicreportImageExifThenLoader[Q](), PublicreportNotifyEmailNuisance: buildPublicreportNotifyEmailNuisanceThenLoader[Q](), diff --git a/db/models/bob_where.bob.go b/db/models/bob_where.bob.go index 8709e115..e6785af6 100644 --- a/db/models/bob_where.bob.go +++ b/db/models/bob_where.bob.go @@ -59,6 +59,7 @@ func Where[Q psql.Filterable]() struct { FileuploadErrorCSVS fileuploadErrorCSVWhere[Q] FileuploadErrorFiles fileuploadErrorFileWhere[Q] FileuploadFiles fileuploadFileWhere[Q] + FileuploadPools fileuploadPoolWhere[Q] GeographyColumns geographyColumnWhere[Q] GeometryColumns geometryColumnWhere[Q] GooseDBVersions gooseDBVersionWhere[Q] @@ -73,7 +74,6 @@ func Where[Q psql.Filterable]() struct { Notifications notificationWhere[Q] OauthTokens oauthTokenWhere[Q] Organizations organizationWhere[Q] - Pools poolWhere[Q] PublicreportImages publicreportImageWhere[Q] PublicreportImageExifs publicreportImageExifWhere[Q] PublicreportNotifyEmailNuisances publicreportNotifyEmailNuisanceWhere[Q] @@ -136,6 +136,7 @@ func Where[Q psql.Filterable]() struct { FileuploadErrorCSVS fileuploadErrorCSVWhere[Q] FileuploadErrorFiles fileuploadErrorFileWhere[Q] FileuploadFiles fileuploadFileWhere[Q] + FileuploadPools fileuploadPoolWhere[Q] GeographyColumns geographyColumnWhere[Q] GeometryColumns geometryColumnWhere[Q] GooseDBVersions gooseDBVersionWhere[Q] @@ -150,7 +151,6 @@ func Where[Q psql.Filterable]() struct { Notifications notificationWhere[Q] OauthTokens oauthTokenWhere[Q] Organizations organizationWhere[Q] - Pools poolWhere[Q] PublicreportImages publicreportImageWhere[Q] PublicreportImageExifs publicreportImageExifWhere[Q] PublicreportNotifyEmailNuisances publicreportNotifyEmailNuisanceWhere[Q] @@ -212,6 +212,7 @@ func Where[Q psql.Filterable]() struct { FileuploadErrorCSVS: buildFileuploadErrorCSVWhere[Q](FileuploadErrorCSVS.Columns), FileuploadErrorFiles: buildFileuploadErrorFileWhere[Q](FileuploadErrorFiles.Columns), FileuploadFiles: buildFileuploadFileWhere[Q](FileuploadFiles.Columns), + FileuploadPools: buildFileuploadPoolWhere[Q](FileuploadPools.Columns), GeographyColumns: buildGeographyColumnWhere[Q](GeographyColumns.Columns), GeometryColumns: buildGeometryColumnWhere[Q](GeometryColumns.Columns), GooseDBVersions: buildGooseDBVersionWhere[Q](GooseDBVersions.Columns), @@ -226,7 +227,6 @@ func Where[Q psql.Filterable]() struct { Notifications: buildNotificationWhere[Q](Notifications.Columns), OauthTokens: buildOauthTokenWhere[Q](OauthTokens.Columns), Organizations: buildOrganizationWhere[Q](Organizations.Columns), - Pools: buildPoolWhere[Q](Pools.Columns), PublicreportImages: buildPublicreportImageWhere[Q](PublicreportImages.Columns), PublicreportImageExifs: buildPublicreportImageExifWhere[Q](PublicreportImageExifs.Columns), PublicreportNotifyEmailNuisances: buildPublicreportNotifyEmailNuisanceWhere[Q](PublicreportNotifyEmailNuisances.Columns), diff --git a/db/models/fileupload.csv.bob.go b/db/models/fileupload.csv.bob.go index 44534cc6..5b1f151d 100644 --- a/db/models/fileupload.csv.bob.go +++ b/db/models/fileupload.csv.bob.go @@ -51,6 +51,7 @@ type FileuploadCSVSQuery = *psql.ViewQuery[*FileuploadCSV, FileuploadCSVSlice] type fileuploadCSVR struct { File *FileuploadFile // fileupload.csv.csv_file_id_fkey CSVFileErrorCSVS FileuploadErrorCSVSlice // fileupload.error_csv.error_csv_csv_file_id_fkey + CSVFilePools FileuploadPoolSlice // fileupload.pool.pool_csv_file_fkey } func buildFileuploadCSVColumns(alias string) fileuploadCSVColumns { @@ -469,6 +470,30 @@ func (os FileuploadCSVSlice) CSVFileErrorCSVS(mods ...bob.Mod[*dialect.SelectQue )...) } +// CSVFilePools starts a query for related objects on fileupload.pool +func (o *FileuploadCSV) CSVFilePools(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadPoolsQuery { + return FileuploadPools.Query(append(mods, + sm.Where(FileuploadPools.Columns.CSVFile.EQ(psql.Arg(o.FileID))), + )...) +} + +func (os FileuploadCSVSlice) CSVFilePools(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadPoolsQuery { + pkFileID := make(pgtypes.Array[int32], 0, len(os)) + for _, o := range os { + if o == nil { + continue + } + pkFileID = append(pkFileID, o.FileID) + } + PKArgExpr := psql.Select(sm.Columns( + psql.F("unnest", psql.Cast(psql.Arg(pkFileID), "integer[]")), + )) + + return FileuploadPools.Query(append(mods, + sm.Where(psql.Group(FileuploadPools.Columns.CSVFile).OP("IN", PKArgExpr)), + )...) +} + func attachFileuploadCSVFile0(ctx context.Context, exec bob.Executor, count int, fileuploadCSV0 *FileuploadCSV, fileuploadFile1 *FileuploadFile) (*FileuploadCSV, error) { setter := &FileuploadCSVSetter{ FileID: omit.From(fileuploadFile1.ID), @@ -585,6 +610,74 @@ func (fileuploadCSV0 *FileuploadCSV) AttachCSVFileErrorCSVS(ctx context.Context, return nil } +func insertFileuploadCSVCSVFilePools0(ctx context.Context, exec bob.Executor, fileuploadPools1 []*FileuploadPoolSetter, fileuploadCSV0 *FileuploadCSV) (FileuploadPoolSlice, error) { + for i := range fileuploadPools1 { + fileuploadPools1[i].CSVFile = omit.From(fileuploadCSV0.FileID) + } + + ret, err := FileuploadPools.Insert(bob.ToMods(fileuploadPools1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertFileuploadCSVCSVFilePools0: %w", err) + } + + return ret, nil +} + +func attachFileuploadCSVCSVFilePools0(ctx context.Context, exec bob.Executor, count int, fileuploadPools1 FileuploadPoolSlice, fileuploadCSV0 *FileuploadCSV) (FileuploadPoolSlice, error) { + setter := &FileuploadPoolSetter{ + CSVFile: omit.From(fileuploadCSV0.FileID), + } + + err := fileuploadPools1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachFileuploadCSVCSVFilePools0: %w", err) + } + + return fileuploadPools1, nil +} + +func (fileuploadCSV0 *FileuploadCSV) InsertCSVFilePools(ctx context.Context, exec bob.Executor, related ...*FileuploadPoolSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + fileuploadPools1, err := insertFileuploadCSVCSVFilePools0(ctx, exec, related, fileuploadCSV0) + if err != nil { + return err + } + + fileuploadCSV0.R.CSVFilePools = append(fileuploadCSV0.R.CSVFilePools, fileuploadPools1...) + + for _, rel := range fileuploadPools1 { + rel.R.CSVFileCSV = fileuploadCSV0 + } + return nil +} + +func (fileuploadCSV0 *FileuploadCSV) AttachCSVFilePools(ctx context.Context, exec bob.Executor, related ...*FileuploadPool) error { + if len(related) == 0 { + return nil + } + + var err error + fileuploadPools1 := FileuploadPoolSlice(related) + + _, err = attachFileuploadCSVCSVFilePools0(ctx, exec, len(related), fileuploadPools1, fileuploadCSV0) + if err != nil { + return err + } + + fileuploadCSV0.R.CSVFilePools = append(fileuploadCSV0.R.CSVFilePools, fileuploadPools1...) + + for _, rel := range related { + rel.R.CSVFileCSV = fileuploadCSV0 + } + + return nil +} + type fileuploadCSVWhere[Q psql.Filterable] struct { Committed psql.WhereNullMod[Q, time.Time] FileID psql.WhereMod[Q, int32] @@ -631,6 +724,20 @@ func (o *FileuploadCSV) Preload(name string, retrieved any) error { o.R.CSVFileErrorCSVS = rels + for _, rel := range rels { + if rel != nil { + rel.R.CSVFileCSV = o + } + } + return nil + case "CSVFilePools": + rels, ok := retrieved.(FileuploadPoolSlice) + if !ok { + return fmt.Errorf("fileuploadCSV cannot load %T as %q", retrieved, name) + } + + o.R.CSVFilePools = rels + for _, rel := range rels { if rel != nil { rel.R.CSVFileCSV = o @@ -667,6 +774,7 @@ func buildFileuploadCSVPreloader() fileuploadCSVPreloader { type fileuploadCSVThenLoader[Q orm.Loadable] struct { File func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] CSVFileErrorCSVS func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + CSVFilePools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] } func buildFileuploadCSVThenLoader[Q orm.Loadable]() fileuploadCSVThenLoader[Q] { @@ -676,6 +784,9 @@ func buildFileuploadCSVThenLoader[Q orm.Loadable]() fileuploadCSVThenLoader[Q] { type CSVFileErrorCSVSLoadInterface interface { LoadCSVFileErrorCSVS(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } + type CSVFilePoolsLoadInterface interface { + LoadCSVFilePools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } return fileuploadCSVThenLoader[Q]{ File: thenLoadBuilder[Q]( @@ -690,6 +801,12 @@ func buildFileuploadCSVThenLoader[Q orm.Loadable]() fileuploadCSVThenLoader[Q] { return retrieved.LoadCSVFileErrorCSVS(ctx, exec, mods...) }, ), + CSVFilePools: thenLoadBuilder[Q]( + "CSVFilePools", + func(ctx context.Context, exec bob.Executor, retrieved CSVFilePoolsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadCSVFilePools(ctx, exec, mods...) + }, + ), } } @@ -806,9 +923,71 @@ func (os FileuploadCSVSlice) LoadCSVFileErrorCSVS(ctx context.Context, exec bob. return nil } +// LoadCSVFilePools loads the fileuploadCSV's CSVFilePools into the .R struct +func (o *FileuploadCSV) LoadCSVFilePools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.CSVFilePools = nil + + related, err := o.CSVFilePools(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.CSVFileCSV = o + } + + o.R.CSVFilePools = related + return nil +} + +// LoadCSVFilePools loads the fileuploadCSV's CSVFilePools into the .R struct +func (os FileuploadCSVSlice) LoadCSVFilePools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + fileuploadPools, err := os.CSVFilePools(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.CSVFilePools = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range fileuploadPools { + + if !(o.FileID == rel.CSVFile) { + continue + } + + rel.R.CSVFileCSV = o + + o.R.CSVFilePools = append(o.R.CSVFilePools, rel) + } + } + + return nil +} + // fileuploadCSVC is where relationship counts are stored. type fileuploadCSVC struct { CSVFileErrorCSVS *int64 + CSVFilePools *int64 } // PreloadCount sets a count in the C struct by name @@ -820,12 +999,15 @@ func (o *FileuploadCSV) PreloadCount(name string, count int64) error { switch name { case "CSVFileErrorCSVS": o.C.CSVFileErrorCSVS = &count + case "CSVFilePools": + o.C.CSVFilePools = &count } return nil } type fileuploadCSVCountPreloader struct { CSVFileErrorCSVS func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader + CSVFilePools func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader } func buildFileuploadCSVCountPreloader() fileuploadCSVCountPreloader { @@ -847,17 +1029,38 @@ func buildFileuploadCSVCountPreloader() fileuploadCSVCountPreloader { return psql.Group(psql.Select(subqueryMods...).Expression) }) }, + CSVFilePools: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader { + return countPreloader[*FileuploadCSV]("CSVFilePools", func(parent string) bob.Expression { + // Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk) + if parent == "" { + parent = FileuploadCSVS.Alias() + } + + subqueryMods := []bob.Mod[*dialect.SelectQuery]{ + sm.Columns(psql.Raw("count(*)")), + + sm.From(FileuploadPools.Name()), + sm.Where(psql.Quote(FileuploadPools.Alias(), "csv_file").EQ(psql.Quote(parent, "file_id"))), + } + subqueryMods = append(subqueryMods, mods...) + return psql.Group(psql.Select(subqueryMods...).Expression) + }) + }, } } type fileuploadCSVCountThenLoader[Q orm.Loadable] struct { CSVFileErrorCSVS func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + CSVFilePools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] } func buildFileuploadCSVCountThenLoader[Q orm.Loadable]() fileuploadCSVCountThenLoader[Q] { type CSVFileErrorCSVSCountInterface interface { LoadCountCSVFileErrorCSVS(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } + type CSVFilePoolsCountInterface interface { + LoadCountCSVFilePools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } return fileuploadCSVCountThenLoader[Q]{ CSVFileErrorCSVS: countThenLoadBuilder[Q]( @@ -866,6 +1069,12 @@ func buildFileuploadCSVCountThenLoader[Q orm.Loadable]() fileuploadCSVCountThenL return retrieved.LoadCountCSVFileErrorCSVS(ctx, exec, mods...) }, ), + CSVFilePools: countThenLoadBuilder[Q]( + "CSVFilePools", + func(ctx context.Context, exec bob.Executor, retrieved CSVFilePoolsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadCountCSVFilePools(ctx, exec, mods...) + }, + ), } } @@ -899,10 +1108,41 @@ func (os FileuploadCSVSlice) LoadCountCSVFileErrorCSVS(ctx context.Context, exec return nil } +// LoadCountCSVFilePools loads the count of CSVFilePools into the C struct +func (o *FileuploadCSV) LoadCountCSVFilePools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + count, err := o.CSVFilePools(mods...).Count(ctx, exec) + if err != nil { + return err + } + + o.C.CSVFilePools = &count + return nil +} + +// LoadCountCSVFilePools loads the count of CSVFilePools for a slice +func (os FileuploadCSVSlice) LoadCountCSVFilePools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + for _, o := range os { + if err := o.LoadCountCSVFilePools(ctx, exec, mods...); err != nil { + return err + } + } + + return nil +} + type fileuploadCSVJoins[Q dialect.Joinable] struct { typ string File modAs[Q, fileuploadFileColumns] CSVFileErrorCSVS modAs[Q, fileuploadErrorCSVColumns] + CSVFilePools modAs[Q, fileuploadPoolColumns] } func (j fileuploadCSVJoins[Q]) aliasedAs(alias string) fileuploadCSVJoins[Q] { @@ -937,6 +1177,20 @@ func buildFileuploadCSVJoins[Q dialect.Joinable](cols fileuploadCSVColumns, typ )) } + return mods + }, + }, + CSVFilePools: modAs[Q, fileuploadPoolColumns]{ + c: FileuploadPools.Columns, + f: func(to fileuploadPoolColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, FileuploadPools.Name().As(to.Alias())).On( + to.CSVFile.EQ(cols.FileID), + )) + } + return mods }, }, diff --git a/db/models/fileupload.pool.bob.go b/db/models/fileupload.pool.bob.go new file mode 100644 index 00000000..483286d5 --- /dev/null +++ b/db/models/fileupload.pool.bob.go @@ -0,0 +1,1443 @@ +// Code generated by BobGen psql v0.42.5. DO NOT EDIT. +// This file is meant to be re-generated in place and/or deleted at any time. + +package models + +import ( + "context" + "fmt" + "io" + "time" + + "github.com/Gleipnir-Technology/bob" + "github.com/Gleipnir-Technology/bob/dialect/psql" + "github.com/Gleipnir-Technology/bob/dialect/psql/dialect" + "github.com/Gleipnir-Technology/bob/dialect/psql/dm" + "github.com/Gleipnir-Technology/bob/dialect/psql/sm" + "github.com/Gleipnir-Technology/bob/dialect/psql/um" + "github.com/Gleipnir-Technology/bob/expr" + "github.com/Gleipnir-Technology/bob/mods" + "github.com/Gleipnir-Technology/bob/orm" + "github.com/Gleipnir-Technology/bob/types/pgtypes" + enums "github.com/Gleipnir-Technology/nidus-sync/db/enums" + "github.com/aarondl/opt/null" + "github.com/aarondl/opt/omit" + "github.com/aarondl/opt/omitnull" +) + +// FileuploadPool is an object representing the database table. +type FileuploadPool struct { + AddressCity string `db:"address_city" ` + AddressPostalCode string `db:"address_postal_code" ` + AddressStreet string `db:"address_street" ` + Committed bool `db:"committed" ` + Condition enums.FileuploadPoolconditiontype `db:"condition" ` + Created time.Time `db:"created" ` + CreatorID int32 `db:"creator_id" ` + CSVFile int32 `db:"csv_file" ` + Deleted null.Val[time.Time] `db:"deleted" ` + Geom null.Val[string] `db:"geom" ` + H3cell null.Val[string] `db:"h3cell" ` + ID int32 `db:"id,pk" ` + IsInDistrict bool `db:"is_in_district" ` + IsNew bool `db:"is_new" ` + Notes string `db:"notes" ` + OrganizationID int32 `db:"organization_id" ` + PropertyOwnerName string `db:"property_owner_name" ` + PropertyOwnerPhone null.Val[string] `db:"property_owner_phone" ` + ResidentOwned null.Val[bool] `db:"resident_owned" ` + ResidentPhone null.Val[string] `db:"resident_phone" ` + Version int32 `db:"version,pk" ` + + R fileuploadPoolR `db:"-" ` +} + +// FileuploadPoolSlice is an alias for a slice of pointers to FileuploadPool. +// This should almost always be used instead of []*FileuploadPool. +type FileuploadPoolSlice []*FileuploadPool + +// FileuploadPools contains methods to work with the pool table +var FileuploadPools = psql.NewTablex[*FileuploadPool, FileuploadPoolSlice, *FileuploadPoolSetter]("fileupload", "pool", buildFileuploadPoolColumns("fileupload.pool")) + +// FileuploadPoolsQuery is a query on the pool table +type FileuploadPoolsQuery = *psql.ViewQuery[*FileuploadPool, FileuploadPoolSlice] + +// fileuploadPoolR is where relationships are stored. +type fileuploadPoolR struct { + CreatorUser *User // fileupload.pool.pool_creator_id_fkey + CSVFileCSV *FileuploadCSV // fileupload.pool.pool_csv_file_fkey + Organization *Organization // fileupload.pool.pool_organization_id_fkey +} + +func buildFileuploadPoolColumns(alias string) fileuploadPoolColumns { + return fileuploadPoolColumns{ + ColumnsExpr: expr.NewColumnsExpr( + "address_city", "address_postal_code", "address_street", "committed", "condition", "created", "creator_id", "csv_file", "deleted", "geom", "h3cell", "id", "is_in_district", "is_new", "notes", "organization_id", "property_owner_name", "property_owner_phone", "resident_owned", "resident_phone", "version", + ).WithParent("fileupload.pool"), + tableAlias: alias, + AddressCity: psql.Quote(alias, "address_city"), + AddressPostalCode: psql.Quote(alias, "address_postal_code"), + AddressStreet: psql.Quote(alias, "address_street"), + Committed: psql.Quote(alias, "committed"), + Condition: psql.Quote(alias, "condition"), + Created: psql.Quote(alias, "created"), + CreatorID: psql.Quote(alias, "creator_id"), + CSVFile: psql.Quote(alias, "csv_file"), + Deleted: psql.Quote(alias, "deleted"), + Geom: psql.Quote(alias, "geom"), + H3cell: psql.Quote(alias, "h3cell"), + ID: psql.Quote(alias, "id"), + IsInDistrict: psql.Quote(alias, "is_in_district"), + IsNew: psql.Quote(alias, "is_new"), + Notes: psql.Quote(alias, "notes"), + OrganizationID: psql.Quote(alias, "organization_id"), + PropertyOwnerName: psql.Quote(alias, "property_owner_name"), + PropertyOwnerPhone: psql.Quote(alias, "property_owner_phone"), + ResidentOwned: psql.Quote(alias, "resident_owned"), + ResidentPhone: psql.Quote(alias, "resident_phone"), + Version: psql.Quote(alias, "version"), + } +} + +type fileuploadPoolColumns struct { + expr.ColumnsExpr + tableAlias string + AddressCity psql.Expression + AddressPostalCode psql.Expression + AddressStreet psql.Expression + Committed psql.Expression + Condition psql.Expression + Created psql.Expression + CreatorID psql.Expression + CSVFile psql.Expression + Deleted psql.Expression + Geom psql.Expression + H3cell psql.Expression + ID psql.Expression + IsInDistrict psql.Expression + IsNew psql.Expression + Notes psql.Expression + OrganizationID psql.Expression + PropertyOwnerName psql.Expression + PropertyOwnerPhone psql.Expression + ResidentOwned psql.Expression + ResidentPhone psql.Expression + Version psql.Expression +} + +func (c fileuploadPoolColumns) Alias() string { + return c.tableAlias +} + +func (fileuploadPoolColumns) AliasedAs(alias string) fileuploadPoolColumns { + return buildFileuploadPoolColumns(alias) +} + +// FileuploadPoolSetter is used for insert/upsert/update operations +// All values are optional, and do not have to be set +// Generated columns are not included +type FileuploadPoolSetter struct { + AddressCity omit.Val[string] `db:"address_city" ` + AddressPostalCode omit.Val[string] `db:"address_postal_code" ` + AddressStreet omit.Val[string] `db:"address_street" ` + Committed omit.Val[bool] `db:"committed" ` + Condition omit.Val[enums.FileuploadPoolconditiontype] `db:"condition" ` + Created omit.Val[time.Time] `db:"created" ` + CreatorID omit.Val[int32] `db:"creator_id" ` + CSVFile omit.Val[int32] `db:"csv_file" ` + Deleted omitnull.Val[time.Time] `db:"deleted" ` + Geom omitnull.Val[string] `db:"geom" ` + H3cell omitnull.Val[string] `db:"h3cell" ` + ID omit.Val[int32] `db:"id,pk" ` + IsInDistrict omit.Val[bool] `db:"is_in_district" ` + IsNew omit.Val[bool] `db:"is_new" ` + Notes omit.Val[string] `db:"notes" ` + OrganizationID omit.Val[int32] `db:"organization_id" ` + PropertyOwnerName omit.Val[string] `db:"property_owner_name" ` + PropertyOwnerPhone omitnull.Val[string] `db:"property_owner_phone" ` + ResidentOwned omitnull.Val[bool] `db:"resident_owned" ` + ResidentPhone omitnull.Val[string] `db:"resident_phone" ` + Version omit.Val[int32] `db:"version,pk" ` +} + +func (s FileuploadPoolSetter) SetColumns() []string { + vals := make([]string, 0, 21) + if s.AddressCity.IsValue() { + vals = append(vals, "address_city") + } + if s.AddressPostalCode.IsValue() { + vals = append(vals, "address_postal_code") + } + if s.AddressStreet.IsValue() { + vals = append(vals, "address_street") + } + if s.Committed.IsValue() { + vals = append(vals, "committed") + } + if s.Condition.IsValue() { + vals = append(vals, "condition") + } + if s.Created.IsValue() { + vals = append(vals, "created") + } + if s.CreatorID.IsValue() { + vals = append(vals, "creator_id") + } + if s.CSVFile.IsValue() { + vals = append(vals, "csv_file") + } + if !s.Deleted.IsUnset() { + vals = append(vals, "deleted") + } + if !s.Geom.IsUnset() { + vals = append(vals, "geom") + } + if !s.H3cell.IsUnset() { + vals = append(vals, "h3cell") + } + if s.ID.IsValue() { + vals = append(vals, "id") + } + if s.IsInDistrict.IsValue() { + vals = append(vals, "is_in_district") + } + if s.IsNew.IsValue() { + vals = append(vals, "is_new") + } + if s.Notes.IsValue() { + vals = append(vals, "notes") + } + if s.OrganizationID.IsValue() { + vals = append(vals, "organization_id") + } + if s.PropertyOwnerName.IsValue() { + vals = append(vals, "property_owner_name") + } + if !s.PropertyOwnerPhone.IsUnset() { + vals = append(vals, "property_owner_phone") + } + if !s.ResidentOwned.IsUnset() { + vals = append(vals, "resident_owned") + } + if !s.ResidentPhone.IsUnset() { + vals = append(vals, "resident_phone") + } + if s.Version.IsValue() { + vals = append(vals, "version") + } + return vals +} + +func (s FileuploadPoolSetter) Overwrite(t *FileuploadPool) { + if s.AddressCity.IsValue() { + t.AddressCity = s.AddressCity.MustGet() + } + if s.AddressPostalCode.IsValue() { + t.AddressPostalCode = s.AddressPostalCode.MustGet() + } + if s.AddressStreet.IsValue() { + t.AddressStreet = s.AddressStreet.MustGet() + } + if s.Committed.IsValue() { + t.Committed = s.Committed.MustGet() + } + if s.Condition.IsValue() { + t.Condition = s.Condition.MustGet() + } + if s.Created.IsValue() { + t.Created = s.Created.MustGet() + } + if s.CreatorID.IsValue() { + t.CreatorID = s.CreatorID.MustGet() + } + if s.CSVFile.IsValue() { + t.CSVFile = s.CSVFile.MustGet() + } + if !s.Deleted.IsUnset() { + t.Deleted = s.Deleted.MustGetNull() + } + if !s.Geom.IsUnset() { + t.Geom = s.Geom.MustGetNull() + } + if !s.H3cell.IsUnset() { + t.H3cell = s.H3cell.MustGetNull() + } + if s.ID.IsValue() { + t.ID = s.ID.MustGet() + } + if s.IsInDistrict.IsValue() { + t.IsInDistrict = s.IsInDistrict.MustGet() + } + if s.IsNew.IsValue() { + t.IsNew = s.IsNew.MustGet() + } + if s.Notes.IsValue() { + t.Notes = s.Notes.MustGet() + } + if s.OrganizationID.IsValue() { + t.OrganizationID = s.OrganizationID.MustGet() + } + if s.PropertyOwnerName.IsValue() { + t.PropertyOwnerName = s.PropertyOwnerName.MustGet() + } + if !s.PropertyOwnerPhone.IsUnset() { + t.PropertyOwnerPhone = s.PropertyOwnerPhone.MustGetNull() + } + if !s.ResidentOwned.IsUnset() { + t.ResidentOwned = s.ResidentOwned.MustGetNull() + } + if !s.ResidentPhone.IsUnset() { + t.ResidentPhone = s.ResidentPhone.MustGetNull() + } + if s.Version.IsValue() { + t.Version = s.Version.MustGet() + } +} + +func (s *FileuploadPoolSetter) Apply(q *dialect.InsertQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return FileuploadPools.BeforeInsertHooks.RunHooks(ctx, exec, s) + }) + + q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + vals := make([]bob.Expression, 21) + if s.AddressCity.IsValue() { + vals[0] = psql.Arg(s.AddressCity.MustGet()) + } else { + vals[0] = psql.Raw("DEFAULT") + } + + if s.AddressPostalCode.IsValue() { + vals[1] = psql.Arg(s.AddressPostalCode.MustGet()) + } else { + vals[1] = psql.Raw("DEFAULT") + } + + if s.AddressStreet.IsValue() { + vals[2] = psql.Arg(s.AddressStreet.MustGet()) + } else { + vals[2] = psql.Raw("DEFAULT") + } + + if s.Committed.IsValue() { + vals[3] = psql.Arg(s.Committed.MustGet()) + } else { + vals[3] = psql.Raw("DEFAULT") + } + + if s.Condition.IsValue() { + vals[4] = psql.Arg(s.Condition.MustGet()) + } else { + vals[4] = psql.Raw("DEFAULT") + } + + if s.Created.IsValue() { + vals[5] = psql.Arg(s.Created.MustGet()) + } else { + vals[5] = psql.Raw("DEFAULT") + } + + if s.CreatorID.IsValue() { + vals[6] = psql.Arg(s.CreatorID.MustGet()) + } else { + vals[6] = psql.Raw("DEFAULT") + } + + if s.CSVFile.IsValue() { + vals[7] = psql.Arg(s.CSVFile.MustGet()) + } else { + vals[7] = psql.Raw("DEFAULT") + } + + if !s.Deleted.IsUnset() { + vals[8] = psql.Arg(s.Deleted.MustGetNull()) + } else { + vals[8] = psql.Raw("DEFAULT") + } + + if !s.Geom.IsUnset() { + vals[9] = psql.Arg(s.Geom.MustGetNull()) + } else { + vals[9] = psql.Raw("DEFAULT") + } + + if !s.H3cell.IsUnset() { + vals[10] = psql.Arg(s.H3cell.MustGetNull()) + } else { + vals[10] = psql.Raw("DEFAULT") + } + + if s.ID.IsValue() { + vals[11] = psql.Arg(s.ID.MustGet()) + } else { + vals[11] = psql.Raw("DEFAULT") + } + + if s.IsInDistrict.IsValue() { + vals[12] = psql.Arg(s.IsInDistrict.MustGet()) + } else { + vals[12] = psql.Raw("DEFAULT") + } + + if s.IsNew.IsValue() { + vals[13] = psql.Arg(s.IsNew.MustGet()) + } else { + vals[13] = psql.Raw("DEFAULT") + } + + if s.Notes.IsValue() { + vals[14] = psql.Arg(s.Notes.MustGet()) + } else { + vals[14] = psql.Raw("DEFAULT") + } + + if s.OrganizationID.IsValue() { + vals[15] = psql.Arg(s.OrganizationID.MustGet()) + } else { + vals[15] = psql.Raw("DEFAULT") + } + + if s.PropertyOwnerName.IsValue() { + vals[16] = psql.Arg(s.PropertyOwnerName.MustGet()) + } else { + vals[16] = psql.Raw("DEFAULT") + } + + if !s.PropertyOwnerPhone.IsUnset() { + vals[17] = psql.Arg(s.PropertyOwnerPhone.MustGetNull()) + } else { + vals[17] = psql.Raw("DEFAULT") + } + + if !s.ResidentOwned.IsUnset() { + vals[18] = psql.Arg(s.ResidentOwned.MustGetNull()) + } else { + vals[18] = psql.Raw("DEFAULT") + } + + if !s.ResidentPhone.IsUnset() { + vals[19] = psql.Arg(s.ResidentPhone.MustGetNull()) + } else { + vals[19] = psql.Raw("DEFAULT") + } + + if s.Version.IsValue() { + vals[20] = psql.Arg(s.Version.MustGet()) + } else { + vals[20] = psql.Raw("DEFAULT") + } + + return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "") + })) +} + +func (s FileuploadPoolSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return um.Set(s.Expressions()...) +} + +func (s FileuploadPoolSetter) Expressions(prefix ...string) []bob.Expression { + exprs := make([]bob.Expression, 0, 21) + + if s.AddressCity.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_city")...), + psql.Arg(s.AddressCity), + }}) + } + + if s.AddressPostalCode.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_postal_code")...), + psql.Arg(s.AddressPostalCode), + }}) + } + + if s.AddressStreet.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "address_street")...), + psql.Arg(s.AddressStreet), + }}) + } + + if s.Committed.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "committed")...), + psql.Arg(s.Committed), + }}) + } + + if s.Condition.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "condition")...), + psql.Arg(s.Condition), + }}) + } + + if s.Created.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "created")...), + psql.Arg(s.Created), + }}) + } + + if s.CreatorID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "creator_id")...), + psql.Arg(s.CreatorID), + }}) + } + + if s.CSVFile.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "csv_file")...), + psql.Arg(s.CSVFile), + }}) + } + + if !s.Deleted.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "deleted")...), + psql.Arg(s.Deleted), + }}) + } + + if !s.Geom.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "geom")...), + psql.Arg(s.Geom), + }}) + } + + if !s.H3cell.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "h3cell")...), + psql.Arg(s.H3cell), + }}) + } + + if s.ID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "id")...), + psql.Arg(s.ID), + }}) + } + + if s.IsInDistrict.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "is_in_district")...), + psql.Arg(s.IsInDistrict), + }}) + } + + if s.IsNew.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "is_new")...), + psql.Arg(s.IsNew), + }}) + } + + if s.Notes.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "notes")...), + psql.Arg(s.Notes), + }}) + } + + if s.OrganizationID.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "organization_id")...), + psql.Arg(s.OrganizationID), + }}) + } + + if s.PropertyOwnerName.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "property_owner_name")...), + psql.Arg(s.PropertyOwnerName), + }}) + } + + if !s.PropertyOwnerPhone.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "property_owner_phone")...), + psql.Arg(s.PropertyOwnerPhone), + }}) + } + + if !s.ResidentOwned.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "resident_owned")...), + psql.Arg(s.ResidentOwned), + }}) + } + + if !s.ResidentPhone.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "resident_phone")...), + psql.Arg(s.ResidentPhone), + }}) + } + + if s.Version.IsValue() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "version")...), + psql.Arg(s.Version), + }}) + } + + return exprs +} + +// FindFileuploadPool retrieves a single record by primary key +// If cols is empty Find will return all columns. +func FindFileuploadPool(ctx context.Context, exec bob.Executor, IDPK int32, VersionPK int32, cols ...string) (*FileuploadPool, error) { + if len(cols) == 0 { + return FileuploadPools.Query( + sm.Where(FileuploadPools.Columns.ID.EQ(psql.Arg(IDPK))), + sm.Where(FileuploadPools.Columns.Version.EQ(psql.Arg(VersionPK))), + ).One(ctx, exec) + } + + return FileuploadPools.Query( + sm.Where(FileuploadPools.Columns.ID.EQ(psql.Arg(IDPK))), + sm.Where(FileuploadPools.Columns.Version.EQ(psql.Arg(VersionPK))), + sm.Columns(FileuploadPools.Columns.Only(cols...)), + ).One(ctx, exec) +} + +// FileuploadPoolExists checks the presence of a single record by primary key +func FileuploadPoolExists(ctx context.Context, exec bob.Executor, IDPK int32, VersionPK int32) (bool, error) { + return FileuploadPools.Query( + sm.Where(FileuploadPools.Columns.ID.EQ(psql.Arg(IDPK))), + sm.Where(FileuploadPools.Columns.Version.EQ(psql.Arg(VersionPK))), + ).Exists(ctx, exec) +} + +// AfterQueryHook is called after FileuploadPool is retrieved from the database +func (o *FileuploadPool) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = FileuploadPools.AfterSelectHooks.RunHooks(ctx, exec, FileuploadPoolSlice{o}) + case bob.QueryTypeInsert: + ctx, err = FileuploadPools.AfterInsertHooks.RunHooks(ctx, exec, FileuploadPoolSlice{o}) + case bob.QueryTypeUpdate: + ctx, err = FileuploadPools.AfterUpdateHooks.RunHooks(ctx, exec, FileuploadPoolSlice{o}) + case bob.QueryTypeDelete: + ctx, err = FileuploadPools.AfterDeleteHooks.RunHooks(ctx, exec, FileuploadPoolSlice{o}) + } + + return err +} + +// primaryKeyVals returns the primary key values of the FileuploadPool +func (o *FileuploadPool) primaryKeyVals() bob.Expression { + return psql.ArgGroup( + o.ID, + o.Version, + ) +} + +func (o *FileuploadPool) pkEQ() dialect.Expression { + return psql.Group(psql.Quote("fileupload.pool", "id"), psql.Quote("fileupload.pool", "version")).EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + return o.primaryKeyVals().WriteSQL(ctx, w, d, start) + })) +} + +// Update uses an executor to update the FileuploadPool +func (o *FileuploadPool) Update(ctx context.Context, exec bob.Executor, s *FileuploadPoolSetter) error { + v, err := FileuploadPools.Update(s.UpdateMod(), um.Where(o.pkEQ())).One(ctx, exec) + if err != nil { + return err + } + + o.R = v.R + *o = *v + + return nil +} + +// Delete deletes a single FileuploadPool record with an executor +func (o *FileuploadPool) Delete(ctx context.Context, exec bob.Executor) error { + _, err := FileuploadPools.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) + return err +} + +// Reload refreshes the FileuploadPool using the executor +func (o *FileuploadPool) Reload(ctx context.Context, exec bob.Executor) error { + o2, err := FileuploadPools.Query( + sm.Where(FileuploadPools.Columns.ID.EQ(psql.Arg(o.ID))), + sm.Where(FileuploadPools.Columns.Version.EQ(psql.Arg(o.Version))), + ).One(ctx, exec) + if err != nil { + return err + } + o2.R = o.R + *o = *o2 + + return nil +} + +// AfterQueryHook is called after FileuploadPoolSlice is retrieved from the database +func (o FileuploadPoolSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { + var err error + + switch queryType { + case bob.QueryTypeSelect: + ctx, err = FileuploadPools.AfterSelectHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeInsert: + ctx, err = FileuploadPools.AfterInsertHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeUpdate: + ctx, err = FileuploadPools.AfterUpdateHooks.RunHooks(ctx, exec, o) + case bob.QueryTypeDelete: + ctx, err = FileuploadPools.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err +} + +func (o FileuploadPoolSlice) pkIN() dialect.Expression { + if len(o) == 0 { + return psql.Raw("NULL") + } + + return psql.Group(psql.Quote("fileupload.pool", "id"), psql.Quote("fileupload.pool", "version")).In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { + pkPairs := make([]bob.Expression, len(o)) + for i, row := range o { + pkPairs[i] = row.primaryKeyVals() + } + return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") + })) +} + +// copyMatchingRows finds models in the given slice that have the same primary key +// then it first copies the existing relationships from the old model to the new model +// and then replaces the old model in the slice with the new model +func (o FileuploadPoolSlice) copyMatchingRows(from ...*FileuploadPool) { + for i, old := range o { + for _, new := range from { + if new.ID != old.ID { + continue + } + if new.Version != old.Version { + continue + } + new.R = old.R + o[i] = new + break + } + } +} + +// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" +func (o FileuploadPoolSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { + return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return FileuploadPools.BeforeUpdateHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *FileuploadPool: + o.copyMatchingRows(retrieved) + case []*FileuploadPool: + o.copyMatchingRows(retrieved...) + case FileuploadPoolSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a FileuploadPool or a slice of FileuploadPool + // then run the AfterUpdateHooks on the slice + _, err = FileuploadPools.AfterUpdateHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" +func (o FileuploadPoolSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { + return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { + q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { + return FileuploadPools.BeforeDeleteHooks.RunHooks(ctx, exec, o) + }) + + q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { + var err error + switch retrieved := retrieved.(type) { + case *FileuploadPool: + o.copyMatchingRows(retrieved) + case []*FileuploadPool: + o.copyMatchingRows(retrieved...) + case FileuploadPoolSlice: + o.copyMatchingRows(retrieved...) + default: + // If the retrieved value is not a FileuploadPool or a slice of FileuploadPool + // then run the AfterDeleteHooks on the slice + _, err = FileuploadPools.AfterDeleteHooks.RunHooks(ctx, exec, o) + } + + return err + })) + + q.AppendWhere(o.pkIN()) + }) +} + +func (o FileuploadPoolSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals FileuploadPoolSetter) error { + if len(o) == 0 { + return nil + } + + _, err := FileuploadPools.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec) + return err +} + +func (o FileuploadPoolSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + _, err := FileuploadPools.Delete(o.DeleteMod()).Exec(ctx, exec) + return err +} + +func (o FileuploadPoolSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { + if len(o) == 0 { + return nil + } + + o2, err := FileuploadPools.Query(sm.Where(o.pkIN())).All(ctx, exec) + if err != nil { + return err + } + + o.copyMatchingRows(o2...) + + return nil +} + +// CreatorUser starts a query for related objects on user_ +func (o *FileuploadPool) CreatorUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery { + return Users.Query(append(mods, + sm.Where(Users.Columns.ID.EQ(psql.Arg(o.CreatorID))), + )...) +} + +func (os FileuploadPoolSlice) CreatorUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery { + pkCreatorID := make(pgtypes.Array[int32], 0, len(os)) + for _, o := range os { + if o == nil { + continue + } + pkCreatorID = append(pkCreatorID, o.CreatorID) + } + PKArgExpr := psql.Select(sm.Columns( + psql.F("unnest", psql.Cast(psql.Arg(pkCreatorID), "integer[]")), + )) + + return Users.Query(append(mods, + sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +// CSVFileCSV starts a query for related objects on fileupload.csv +func (o *FileuploadPool) CSVFileCSV(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadCSVSQuery { + return FileuploadCSVS.Query(append(mods, + sm.Where(FileuploadCSVS.Columns.FileID.EQ(psql.Arg(o.CSVFile))), + )...) +} + +func (os FileuploadPoolSlice) CSVFileCSV(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadCSVSQuery { + pkCSVFile := make(pgtypes.Array[int32], 0, len(os)) + for _, o := range os { + if o == nil { + continue + } + pkCSVFile = append(pkCSVFile, o.CSVFile) + } + PKArgExpr := psql.Select(sm.Columns( + psql.F("unnest", psql.Cast(psql.Arg(pkCSVFile), "integer[]")), + )) + + return FileuploadCSVS.Query(append(mods, + sm.Where(psql.Group(FileuploadCSVS.Columns.FileID).OP("IN", PKArgExpr)), + )...) +} + +// Organization starts a query for related objects on organization +func (o *FileuploadPool) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery { + return Organizations.Query(append(mods, + sm.Where(Organizations.Columns.ID.EQ(psql.Arg(o.OrganizationID))), + )...) +} + +func (os FileuploadPoolSlice) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery { + pkOrganizationID := make(pgtypes.Array[int32], 0, len(os)) + for _, o := range os { + if o == nil { + continue + } + pkOrganizationID = append(pkOrganizationID, o.OrganizationID) + } + PKArgExpr := psql.Select(sm.Columns( + psql.F("unnest", psql.Cast(psql.Arg(pkOrganizationID), "integer[]")), + )) + + return Organizations.Query(append(mods, + sm.Where(psql.Group(Organizations.Columns.ID).OP("IN", PKArgExpr)), + )...) +} + +func attachFileuploadPoolCreatorUser0(ctx context.Context, exec bob.Executor, count int, fileuploadPool0 *FileuploadPool, user1 *User) (*FileuploadPool, error) { + setter := &FileuploadPoolSetter{ + CreatorID: omit.From(user1.ID), + } + + err := fileuploadPool0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachFileuploadPoolCreatorUser0: %w", err) + } + + return fileuploadPool0, nil +} + +func (fileuploadPool0 *FileuploadPool) InsertCreatorUser(ctx context.Context, exec bob.Executor, related *UserSetter) error { + var err error + + user1, err := Users.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachFileuploadPoolCreatorUser0(ctx, exec, 1, fileuploadPool0, user1) + if err != nil { + return err + } + + fileuploadPool0.R.CreatorUser = user1 + + user1.R.CreatorPools = append(user1.R.CreatorPools, fileuploadPool0) + + return nil +} + +func (fileuploadPool0 *FileuploadPool) AttachCreatorUser(ctx context.Context, exec bob.Executor, user1 *User) error { + var err error + + _, err = attachFileuploadPoolCreatorUser0(ctx, exec, 1, fileuploadPool0, user1) + if err != nil { + return err + } + + fileuploadPool0.R.CreatorUser = user1 + + user1.R.CreatorPools = append(user1.R.CreatorPools, fileuploadPool0) + + return nil +} + +func attachFileuploadPoolCSVFileCSV0(ctx context.Context, exec bob.Executor, count int, fileuploadPool0 *FileuploadPool, fileuploadCSV1 *FileuploadCSV) (*FileuploadPool, error) { + setter := &FileuploadPoolSetter{ + CSVFile: omit.From(fileuploadCSV1.FileID), + } + + err := fileuploadPool0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachFileuploadPoolCSVFileCSV0: %w", err) + } + + return fileuploadPool0, nil +} + +func (fileuploadPool0 *FileuploadPool) InsertCSVFileCSV(ctx context.Context, exec bob.Executor, related *FileuploadCSVSetter) error { + var err error + + fileuploadCSV1, err := FileuploadCSVS.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachFileuploadPoolCSVFileCSV0(ctx, exec, 1, fileuploadPool0, fileuploadCSV1) + if err != nil { + return err + } + + fileuploadPool0.R.CSVFileCSV = fileuploadCSV1 + + fileuploadCSV1.R.CSVFilePools = append(fileuploadCSV1.R.CSVFilePools, fileuploadPool0) + + return nil +} + +func (fileuploadPool0 *FileuploadPool) AttachCSVFileCSV(ctx context.Context, exec bob.Executor, fileuploadCSV1 *FileuploadCSV) error { + var err error + + _, err = attachFileuploadPoolCSVFileCSV0(ctx, exec, 1, fileuploadPool0, fileuploadCSV1) + if err != nil { + return err + } + + fileuploadPool0.R.CSVFileCSV = fileuploadCSV1 + + fileuploadCSV1.R.CSVFilePools = append(fileuploadCSV1.R.CSVFilePools, fileuploadPool0) + + return nil +} + +func attachFileuploadPoolOrganization0(ctx context.Context, exec bob.Executor, count int, fileuploadPool0 *FileuploadPool, organization1 *Organization) (*FileuploadPool, error) { + setter := &FileuploadPoolSetter{ + OrganizationID: omit.From(organization1.ID), + } + + err := fileuploadPool0.Update(ctx, exec, setter) + if err != nil { + return nil, fmt.Errorf("attachFileuploadPoolOrganization0: %w", err) + } + + return fileuploadPool0, nil +} + +func (fileuploadPool0 *FileuploadPool) InsertOrganization(ctx context.Context, exec bob.Executor, related *OrganizationSetter) error { + var err error + + organization1, err := Organizations.Insert(related).One(ctx, exec) + if err != nil { + return fmt.Errorf("inserting related objects: %w", err) + } + + _, err = attachFileuploadPoolOrganization0(ctx, exec, 1, fileuploadPool0, organization1) + if err != nil { + return err + } + + fileuploadPool0.R.Organization = organization1 + + organization1.R.Pools = append(organization1.R.Pools, fileuploadPool0) + + return nil +} + +func (fileuploadPool0 *FileuploadPool) AttachOrganization(ctx context.Context, exec bob.Executor, organization1 *Organization) error { + var err error + + _, err = attachFileuploadPoolOrganization0(ctx, exec, 1, fileuploadPool0, organization1) + if err != nil { + return err + } + + fileuploadPool0.R.Organization = organization1 + + organization1.R.Pools = append(organization1.R.Pools, fileuploadPool0) + + return nil +} + +type fileuploadPoolWhere[Q psql.Filterable] struct { + AddressCity psql.WhereMod[Q, string] + AddressPostalCode psql.WhereMod[Q, string] + AddressStreet psql.WhereMod[Q, string] + Committed psql.WhereMod[Q, bool] + Condition psql.WhereMod[Q, enums.FileuploadPoolconditiontype] + Created psql.WhereMod[Q, time.Time] + CreatorID psql.WhereMod[Q, int32] + CSVFile psql.WhereMod[Q, int32] + Deleted psql.WhereNullMod[Q, time.Time] + Geom psql.WhereNullMod[Q, string] + H3cell psql.WhereNullMod[Q, string] + ID psql.WhereMod[Q, int32] + IsInDistrict psql.WhereMod[Q, bool] + IsNew psql.WhereMod[Q, bool] + Notes psql.WhereMod[Q, string] + OrganizationID psql.WhereMod[Q, int32] + PropertyOwnerName psql.WhereMod[Q, string] + PropertyOwnerPhone psql.WhereNullMod[Q, string] + ResidentOwned psql.WhereNullMod[Q, bool] + ResidentPhone psql.WhereNullMod[Q, string] + Version psql.WhereMod[Q, int32] +} + +func (fileuploadPoolWhere[Q]) AliasedAs(alias string) fileuploadPoolWhere[Q] { + return buildFileuploadPoolWhere[Q](buildFileuploadPoolColumns(alias)) +} + +func buildFileuploadPoolWhere[Q psql.Filterable](cols fileuploadPoolColumns) fileuploadPoolWhere[Q] { + return fileuploadPoolWhere[Q]{ + AddressCity: psql.Where[Q, string](cols.AddressCity), + AddressPostalCode: psql.Where[Q, string](cols.AddressPostalCode), + AddressStreet: psql.Where[Q, string](cols.AddressStreet), + Committed: psql.Where[Q, bool](cols.Committed), + Condition: psql.Where[Q, enums.FileuploadPoolconditiontype](cols.Condition), + Created: psql.Where[Q, time.Time](cols.Created), + CreatorID: psql.Where[Q, int32](cols.CreatorID), + CSVFile: psql.Where[Q, int32](cols.CSVFile), + Deleted: psql.WhereNull[Q, time.Time](cols.Deleted), + Geom: psql.WhereNull[Q, string](cols.Geom), + H3cell: psql.WhereNull[Q, string](cols.H3cell), + ID: psql.Where[Q, int32](cols.ID), + IsInDistrict: psql.Where[Q, bool](cols.IsInDistrict), + IsNew: psql.Where[Q, bool](cols.IsNew), + Notes: psql.Where[Q, string](cols.Notes), + OrganizationID: psql.Where[Q, int32](cols.OrganizationID), + PropertyOwnerName: psql.Where[Q, string](cols.PropertyOwnerName), + PropertyOwnerPhone: psql.WhereNull[Q, string](cols.PropertyOwnerPhone), + ResidentOwned: psql.WhereNull[Q, bool](cols.ResidentOwned), + ResidentPhone: psql.WhereNull[Q, string](cols.ResidentPhone), + Version: psql.Where[Q, int32](cols.Version), + } +} + +func (o *FileuploadPool) Preload(name string, retrieved any) error { + if o == nil { + return nil + } + + switch name { + case "CreatorUser": + rel, ok := retrieved.(*User) + if !ok { + return fmt.Errorf("fileuploadPool cannot load %T as %q", retrieved, name) + } + + o.R.CreatorUser = rel + + if rel != nil { + rel.R.CreatorPools = FileuploadPoolSlice{o} + } + return nil + case "CSVFileCSV": + rel, ok := retrieved.(*FileuploadCSV) + if !ok { + return fmt.Errorf("fileuploadPool cannot load %T as %q", retrieved, name) + } + + o.R.CSVFileCSV = rel + + if rel != nil { + rel.R.CSVFilePools = FileuploadPoolSlice{o} + } + return nil + case "Organization": + rel, ok := retrieved.(*Organization) + if !ok { + return fmt.Errorf("fileuploadPool cannot load %T as %q", retrieved, name) + } + + o.R.Organization = rel + + if rel != nil { + rel.R.Pools = FileuploadPoolSlice{o} + } + return nil + default: + return fmt.Errorf("fileuploadPool has no relationship %q", name) + } +} + +type fileuploadPoolPreloader struct { + CreatorUser func(...psql.PreloadOption) psql.Preloader + CSVFileCSV func(...psql.PreloadOption) psql.Preloader + Organization func(...psql.PreloadOption) psql.Preloader +} + +func buildFileuploadPoolPreloader() fileuploadPoolPreloader { + return fileuploadPoolPreloader{ + CreatorUser: func(opts ...psql.PreloadOption) psql.Preloader { + return psql.Preload[*User, UserSlice](psql.PreloadRel{ + Name: "CreatorUser", + Sides: []psql.PreloadSide{ + { + From: FileuploadPools, + To: Users, + FromColumns: []string{"creator_id"}, + ToColumns: []string{"id"}, + }, + }, + }, Users.Columns.Names(), opts...) + }, + CSVFileCSV: func(opts ...psql.PreloadOption) psql.Preloader { + return psql.Preload[*FileuploadCSV, FileuploadCSVSlice](psql.PreloadRel{ + Name: "CSVFileCSV", + Sides: []psql.PreloadSide{ + { + From: FileuploadPools, + To: FileuploadCSVS, + FromColumns: []string{"csv_file"}, + ToColumns: []string{"file_id"}, + }, + }, + }, FileuploadCSVS.Columns.Names(), opts...) + }, + Organization: func(opts ...psql.PreloadOption) psql.Preloader { + return psql.Preload[*Organization, OrganizationSlice](psql.PreloadRel{ + Name: "Organization", + Sides: []psql.PreloadSide{ + { + From: FileuploadPools, + To: Organizations, + FromColumns: []string{"organization_id"}, + ToColumns: []string{"id"}, + }, + }, + }, Organizations.Columns.Names(), opts...) + }, + } +} + +type fileuploadPoolThenLoader[Q orm.Loadable] struct { + CreatorUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + CSVFileCSV func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] +} + +func buildFileuploadPoolThenLoader[Q orm.Loadable]() fileuploadPoolThenLoader[Q] { + type CreatorUserLoadInterface interface { + LoadCreatorUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type CSVFileCSVLoadInterface interface { + LoadCSVFileCSV(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + type OrganizationLoadInterface interface { + LoadOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } + + return fileuploadPoolThenLoader[Q]{ + CreatorUser: thenLoadBuilder[Q]( + "CreatorUser", + func(ctx context.Context, exec bob.Executor, retrieved CreatorUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadCreatorUser(ctx, exec, mods...) + }, + ), + CSVFileCSV: thenLoadBuilder[Q]( + "CSVFileCSV", + func(ctx context.Context, exec bob.Executor, retrieved CSVFileCSVLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadCSVFileCSV(ctx, exec, mods...) + }, + ), + Organization: thenLoadBuilder[Q]( + "Organization", + func(ctx context.Context, exec bob.Executor, retrieved OrganizationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadOrganization(ctx, exec, mods...) + }, + ), + } +} + +// LoadCreatorUser loads the fileuploadPool's CreatorUser into the .R struct +func (o *FileuploadPool) LoadCreatorUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.CreatorUser = nil + + related, err := o.CreatorUser(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.CreatorPools = FileuploadPoolSlice{o} + + o.R.CreatorUser = related + return nil +} + +// LoadCreatorUser loads the fileuploadPool's CreatorUser into the .R struct +func (os FileuploadPoolSlice) LoadCreatorUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + users, err := os.CreatorUser(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range users { + + if !(o.CreatorID == rel.ID) { + continue + } + + rel.R.CreatorPools = append(rel.R.CreatorPools, o) + + o.R.CreatorUser = rel + break + } + } + + return nil +} + +// LoadCSVFileCSV loads the fileuploadPool's CSVFileCSV into the .R struct +func (o *FileuploadPool) LoadCSVFileCSV(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.CSVFileCSV = nil + + related, err := o.CSVFileCSV(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.CSVFilePools = FileuploadPoolSlice{o} + + o.R.CSVFileCSV = related + return nil +} + +// LoadCSVFileCSV loads the fileuploadPool's CSVFileCSV into the .R struct +func (os FileuploadPoolSlice) LoadCSVFileCSV(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + fileuploadCSVS, err := os.CSVFileCSV(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range fileuploadCSVS { + + if !(o.CSVFile == rel.FileID) { + continue + } + + rel.R.CSVFilePools = append(rel.R.CSVFilePools, o) + + o.R.CSVFileCSV = rel + break + } + } + + return nil +} + +// LoadOrganization loads the fileuploadPool's Organization into the .R struct +func (o *FileuploadPool) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.Organization = nil + + related, err := o.Organization(mods...).One(ctx, exec) + if err != nil { + return err + } + + related.R.Pools = FileuploadPoolSlice{o} + + o.R.Organization = related + return nil +} + +// LoadOrganization loads the fileuploadPool's Organization into the .R struct +func (os FileuploadPoolSlice) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + organizations, err := os.Organization(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range organizations { + + if !(o.OrganizationID == rel.ID) { + continue + } + + rel.R.Pools = append(rel.R.Pools, o) + + o.R.Organization = rel + break + } + } + + return nil +} + +type fileuploadPoolJoins[Q dialect.Joinable] struct { + typ string + CreatorUser modAs[Q, userColumns] + CSVFileCSV modAs[Q, fileuploadCSVColumns] + Organization modAs[Q, organizationColumns] +} + +func (j fileuploadPoolJoins[Q]) aliasedAs(alias string) fileuploadPoolJoins[Q] { + return buildFileuploadPoolJoins[Q](buildFileuploadPoolColumns(alias), j.typ) +} + +func buildFileuploadPoolJoins[Q dialect.Joinable](cols fileuploadPoolColumns, typ string) fileuploadPoolJoins[Q] { + return fileuploadPoolJoins[Q]{ + typ: typ, + CreatorUser: modAs[Q, userColumns]{ + c: Users.Columns, + f: func(to userColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, Users.Name().As(to.Alias())).On( + to.ID.EQ(cols.CreatorID), + )) + } + + return mods + }, + }, + CSVFileCSV: modAs[Q, fileuploadCSVColumns]{ + c: FileuploadCSVS.Columns, + f: func(to fileuploadCSVColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, FileuploadCSVS.Name().As(to.Alias())).On( + to.FileID.EQ(cols.CSVFile), + )) + } + + return mods + }, + }, + Organization: modAs[Q, organizationColumns]{ + c: Organizations.Columns, + f: func(to organizationColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, Organizations.Name().As(to.Alias())).On( + to.ID.EQ(cols.OrganizationID), + )) + } + + return mods + }, + }, + } +} diff --git a/db/models/organization.bob.go b/db/models/organization.bob.go index 2ee61d49..40f482ba 100644 --- a/db/models/organization.bob.go +++ b/db/models/organization.bob.go @@ -86,11 +86,11 @@ type organizationR struct { Zones2s FieldseekerZones2Slice // fieldseeker.zones2.zones2_organization_id_fkey FieldseekerSyncs FieldseekerSyncSlice // fieldseeker_sync.fieldseeker_sync_organization_id_fkey Files FileuploadFileSlice // fileupload.file.file_organization_id_fkey + Pools FileuploadPoolSlice // fileupload.pool.pool_organization_id_fkey H3Aggregations H3AggregationSlice // h3_aggregation.h3_aggregation_organization_id_fkey NoteAudios NoteAudioSlice // note_audio.note_audio_organization_id_fkey NoteImages NoteImageSlice // note_image.note_image_organization_id_fkey ImportDistrictGidDistrict *ImportDistrict // organization.organization_import_district_gid_fkey - Pools PoolSlice // pool.pool_organization_id_fkey Nuisances PublicreportNuisanceSlice // publicreport.nuisance.nuisance_organization_id_fkey PublicreportPool PublicreportPoolSlice // publicreport.pool.pool_organization_id_fkey Quicks PublicreportQuickSlice // publicreport.quick.quick_organization_id_fkey @@ -1329,6 +1329,30 @@ func (os OrganizationSlice) Files(mods ...bob.Mod[*dialect.SelectQuery]) Fileupl )...) } +// Pools starts a query for related objects on fileupload.pool +func (o *Organization) Pools(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadPoolsQuery { + return FileuploadPools.Query(append(mods, + sm.Where(FileuploadPools.Columns.OrganizationID.EQ(psql.Arg(o.ID))), + )...) +} + +func (os OrganizationSlice) Pools(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadPoolsQuery { + pkID := make(pgtypes.Array[int32], 0, len(os)) + for _, o := range os { + if o == nil { + continue + } + pkID = append(pkID, o.ID) + } + PKArgExpr := psql.Select(sm.Columns( + psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")), + )) + + return FileuploadPools.Query(append(mods, + sm.Where(psql.Group(FileuploadPools.Columns.OrganizationID).OP("IN", PKArgExpr)), + )...) +} + // H3Aggregations starts a query for related objects on h3_aggregation func (o *Organization) H3Aggregations(mods ...bob.Mod[*dialect.SelectQuery]) H3AggregationsQuery { return H3Aggregations.Query(append(mods, @@ -1425,30 +1449,6 @@ func (os OrganizationSlice) ImportDistrictGidDistrict(mods ...bob.Mod[*dialect.S )...) } -// Pools starts a query for related objects on pool -func (o *Organization) Pools(mods ...bob.Mod[*dialect.SelectQuery]) PoolsQuery { - return Pools.Query(append(mods, - sm.Where(Pools.Columns.OrganizationID.EQ(psql.Arg(o.ID))), - )...) -} - -func (os OrganizationSlice) Pools(mods ...bob.Mod[*dialect.SelectQuery]) PoolsQuery { - pkID := make(pgtypes.Array[int32], 0, len(os)) - for _, o := range os { - if o == nil { - continue - } - pkID = append(pkID, o.ID) - } - PKArgExpr := psql.Select(sm.Columns( - psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")), - )) - - return Pools.Query(append(mods, - sm.Where(psql.Group(Pools.Columns.OrganizationID).OP("IN", PKArgExpr)), - )...) -} - // Nuisances starts a query for related objects on publicreport.nuisance func (o *Organization) Nuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisancesQuery { return PublicreportNuisances.Query(append(mods, @@ -3647,6 +3647,74 @@ func (organization0 *Organization) AttachFiles(ctx context.Context, exec bob.Exe return nil } +func insertOrganizationPools0(ctx context.Context, exec bob.Executor, fileuploadPools1 []*FileuploadPoolSetter, organization0 *Organization) (FileuploadPoolSlice, error) { + for i := range fileuploadPools1 { + fileuploadPools1[i].OrganizationID = omit.From(organization0.ID) + } + + ret, err := FileuploadPools.Insert(bob.ToMods(fileuploadPools1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertOrganizationPools0: %w", err) + } + + return ret, nil +} + +func attachOrganizationPools0(ctx context.Context, exec bob.Executor, count int, fileuploadPools1 FileuploadPoolSlice, organization0 *Organization) (FileuploadPoolSlice, error) { + setter := &FileuploadPoolSetter{ + OrganizationID: omit.From(organization0.ID), + } + + err := fileuploadPools1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachOrganizationPools0: %w", err) + } + + return fileuploadPools1, nil +} + +func (organization0 *Organization) InsertPools(ctx context.Context, exec bob.Executor, related ...*FileuploadPoolSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + fileuploadPools1, err := insertOrganizationPools0(ctx, exec, related, organization0) + if err != nil { + return err + } + + organization0.R.Pools = append(organization0.R.Pools, fileuploadPools1...) + + for _, rel := range fileuploadPools1 { + rel.R.Organization = organization0 + } + return nil +} + +func (organization0 *Organization) AttachPools(ctx context.Context, exec bob.Executor, related ...*FileuploadPool) error { + if len(related) == 0 { + return nil + } + + var err error + fileuploadPools1 := FileuploadPoolSlice(related) + + _, err = attachOrganizationPools0(ctx, exec, len(related), fileuploadPools1, organization0) + if err != nil { + return err + } + + organization0.R.Pools = append(organization0.R.Pools, fileuploadPools1...) + + for _, rel := range related { + rel.R.Organization = organization0 + } + + return nil +} + func insertOrganizationH3Aggregations0(ctx context.Context, exec bob.Executor, h3Aggregations1 []*H3AggregationSetter, organization0 *Organization) (H3AggregationSlice, error) { for i := range h3Aggregations1 { h3Aggregations1[i].OrganizationID = omit.From(organization0.ID) @@ -3899,74 +3967,6 @@ func (organization0 *Organization) AttachImportDistrictGidDistrict(ctx context.C return nil } -func insertOrganizationPools0(ctx context.Context, exec bob.Executor, pools1 []*PoolSetter, organization0 *Organization) (PoolSlice, error) { - for i := range pools1 { - pools1[i].OrganizationID = omit.From(organization0.ID) - } - - ret, err := Pools.Insert(bob.ToMods(pools1...)).All(ctx, exec) - if err != nil { - return ret, fmt.Errorf("insertOrganizationPools0: %w", err) - } - - return ret, nil -} - -func attachOrganizationPools0(ctx context.Context, exec bob.Executor, count int, pools1 PoolSlice, organization0 *Organization) (PoolSlice, error) { - setter := &PoolSetter{ - OrganizationID: omit.From(organization0.ID), - } - - err := pools1.UpdateAll(ctx, exec, *setter) - if err != nil { - return nil, fmt.Errorf("attachOrganizationPools0: %w", err) - } - - return pools1, nil -} - -func (organization0 *Organization) InsertPools(ctx context.Context, exec bob.Executor, related ...*PoolSetter) error { - if len(related) == 0 { - return nil - } - - var err error - - pools1, err := insertOrganizationPools0(ctx, exec, related, organization0) - if err != nil { - return err - } - - organization0.R.Pools = append(organization0.R.Pools, pools1...) - - for _, rel := range pools1 { - rel.R.Organization = organization0 - } - return nil -} - -func (organization0 *Organization) AttachPools(ctx context.Context, exec bob.Executor, related ...*Pool) error { - if len(related) == 0 { - return nil - } - - var err error - pools1 := PoolSlice(related) - - _, err = attachOrganizationPools0(ctx, exec, len(related), pools1, organization0) - if err != nil { - return err - } - - organization0.R.Pools = append(organization0.R.Pools, pools1...) - - for _, rel := range related { - rel.R.Organization = organization0 - } - - return nil -} - func insertOrganizationNuisances0(ctx context.Context, exec bob.Executor, publicreportNuisances1 []*PublicreportNuisanceSetter, organization0 *Organization) (PublicreportNuisanceSlice, error) { for i := range publicreportNuisances1 { publicreportNuisances1[i].OrganizationID = omitnull.From(organization0.ID) @@ -4703,6 +4703,20 @@ func (o *Organization) Preload(name string, retrieved any) error { o.R.Files = rels + for _, rel := range rels { + if rel != nil { + rel.R.Organization = o + } + } + return nil + case "Pools": + rels, ok := retrieved.(FileuploadPoolSlice) + if !ok { + return fmt.Errorf("organization cannot load %T as %q", retrieved, name) + } + + o.R.Pools = rels + for _, rel := range rels { if rel != nil { rel.R.Organization = o @@ -4763,20 +4777,6 @@ func (o *Organization) Preload(name string, retrieved any) error { rel.R.ImportDistrictGidOrganization = o } return nil - case "Pools": - rels, ok := retrieved.(PoolSlice) - if !ok { - return fmt.Errorf("organization cannot load %T as %q", retrieved, name) - } - - o.R.Pools = rels - - for _, rel := range rels { - if rel != nil { - rel.R.Organization = o - } - } - return nil case "Nuisances": rels, ok := retrieved.(PublicreportNuisanceSlice) if !ok { @@ -4892,11 +4892,11 @@ type organizationThenLoader[Q orm.Loadable] struct { Zones2s func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] FieldseekerSyncs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] Files func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Pools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] H3Aggregations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] NoteAudios func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] NoteImages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] ImportDistrictGidDistrict func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - Pools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] Nuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] PublicreportPool func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] Quicks func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] @@ -4997,6 +4997,9 @@ func buildOrganizationThenLoader[Q orm.Loadable]() organizationThenLoader[Q] { type FilesLoadInterface interface { LoadFiles(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } + type PoolsLoadInterface interface { + LoadPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } type H3AggregationsLoadInterface interface { LoadH3Aggregations(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } @@ -5009,9 +5012,6 @@ func buildOrganizationThenLoader[Q orm.Loadable]() organizationThenLoader[Q] { type ImportDistrictGidDistrictLoadInterface interface { LoadImportDistrictGidDistrict(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } - type PoolsLoadInterface interface { - LoadPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error - } type NuisancesLoadInterface interface { LoadNuisances(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } @@ -5212,6 +5212,12 @@ func buildOrganizationThenLoader[Q orm.Loadable]() organizationThenLoader[Q] { return retrieved.LoadFiles(ctx, exec, mods...) }, ), + Pools: thenLoadBuilder[Q]( + "Pools", + func(ctx context.Context, exec bob.Executor, retrieved PoolsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadPools(ctx, exec, mods...) + }, + ), H3Aggregations: thenLoadBuilder[Q]( "H3Aggregations", func(ctx context.Context, exec bob.Executor, retrieved H3AggregationsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { @@ -5236,12 +5242,6 @@ func buildOrganizationThenLoader[Q orm.Loadable]() organizationThenLoader[Q] { return retrieved.LoadImportDistrictGidDistrict(ctx, exec, mods...) }, ), - Pools: thenLoadBuilder[Q]( - "Pools", - func(ctx context.Context, exec bob.Executor, retrieved PoolsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadPools(ctx, exec, mods...) - }, - ), Nuisances: thenLoadBuilder[Q]( "Nuisances", func(ctx context.Context, exec bob.Executor, retrieved NuisancesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { @@ -7200,6 +7200,67 @@ func (os OrganizationSlice) LoadFiles(ctx context.Context, exec bob.Executor, mo return nil } +// LoadPools loads the organization's Pools into the .R struct +func (o *Organization) LoadPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.Pools = nil + + related, err := o.Pools(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.Organization = o + } + + o.R.Pools = related + return nil +} + +// LoadPools loads the organization's Pools into the .R struct +func (os OrganizationSlice) LoadPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + fileuploadPools, err := os.Pools(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.Pools = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range fileuploadPools { + + if !(o.ID == rel.OrganizationID) { + continue + } + + rel.R.Organization = o + + o.R.Pools = append(o.R.Pools, rel) + } + } + + return nil +} + // LoadH3Aggregations loads the organization's H3Aggregations into the .R struct func (o *Organization) LoadH3Aggregations(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if o == nil { @@ -7438,67 +7499,6 @@ func (os OrganizationSlice) LoadImportDistrictGidDistrict(ctx context.Context, e return nil } -// LoadPools loads the organization's Pools into the .R struct -func (o *Organization) LoadPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if o == nil { - return nil - } - - // Reset the relationship - o.R.Pools = nil - - related, err := o.Pools(mods...).All(ctx, exec) - if err != nil { - return err - } - - for _, rel := range related { - rel.R.Organization = o - } - - o.R.Pools = related - return nil -} - -// LoadPools loads the organization's Pools into the .R struct -func (os OrganizationSlice) LoadPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if len(os) == 0 { - return nil - } - - pools, err := os.Pools(mods...).All(ctx, exec) - if err != nil { - return err - } - - for _, o := range os { - if o == nil { - continue - } - - o.R.Pools = nil - } - - for _, o := range os { - if o == nil { - continue - } - - for _, rel := range pools { - - if !(o.ID == rel.OrganizationID) { - continue - } - - rel.R.Organization = o - - o.R.Pools = append(o.R.Pools, rel) - } - } - - return nil -} - // LoadNuisances loads the organization's Nuisances into the .R struct func (o *Organization) LoadNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if o == nil { @@ -7785,10 +7785,10 @@ type organizationC struct { Zones2s *int64 FieldseekerSyncs *int64 Files *int64 + Pools *int64 H3Aggregations *int64 NoteAudios *int64 NoteImages *int64 - Pools *int64 Nuisances *int64 PublicreportPool *int64 Quicks *int64 @@ -7864,14 +7864,14 @@ func (o *Organization) PreloadCount(name string, count int64) error { o.C.FieldseekerSyncs = &count case "Files": o.C.Files = &count + case "Pools": + o.C.Pools = &count case "H3Aggregations": o.C.H3Aggregations = &count case "NoteAudios": o.C.NoteAudios = &count case "NoteImages": o.C.NoteImages = &count - case "Pools": - o.C.Pools = &count case "Nuisances": o.C.Nuisances = &count case "PublicreportPool": @@ -7916,10 +7916,10 @@ type organizationCountPreloader struct { Zones2s func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader FieldseekerSyncs func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader Files func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader + Pools func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader H3Aggregations func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader NoteAudios func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader NoteImages func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader - Pools func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader Nuisances func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader PublicreportPool func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader Quicks func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader @@ -8461,6 +8461,23 @@ func buildOrganizationCountPreloader() organizationCountPreloader { return psql.Group(psql.Select(subqueryMods...).Expression) }) }, + Pools: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader { + return countPreloader[*Organization]("Pools", func(parent string) bob.Expression { + // Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk) + if parent == "" { + parent = Organizations.Alias() + } + + subqueryMods := []bob.Mod[*dialect.SelectQuery]{ + sm.Columns(psql.Raw("count(*)")), + + sm.From(FileuploadPools.Name()), + sm.Where(psql.Quote(FileuploadPools.Alias(), "organization_id").EQ(psql.Quote(parent, "id"))), + } + subqueryMods = append(subqueryMods, mods...) + return psql.Group(psql.Select(subqueryMods...).Expression) + }) + }, H3Aggregations: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader { return countPreloader[*Organization]("H3Aggregations", func(parent string) bob.Expression { // Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk) @@ -8512,23 +8529,6 @@ func buildOrganizationCountPreloader() organizationCountPreloader { return psql.Group(psql.Select(subqueryMods...).Expression) }) }, - Pools: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader { - return countPreloader[*Organization]("Pools", func(parent string) bob.Expression { - // Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk) - if parent == "" { - parent = Organizations.Alias() - } - - subqueryMods := []bob.Mod[*dialect.SelectQuery]{ - sm.Columns(psql.Raw("count(*)")), - - sm.From(Pools.Name()), - sm.Where(psql.Quote(Pools.Alias(), "organization_id").EQ(psql.Quote(parent, "id"))), - } - subqueryMods = append(subqueryMods, mods...) - return psql.Group(psql.Select(subqueryMods...).Expression) - }) - }, Nuisances: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader { return countPreloader[*Organization]("Nuisances", func(parent string) bob.Expression { // Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk) @@ -8632,10 +8632,10 @@ type organizationCountThenLoader[Q orm.Loadable] struct { Zones2s func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] FieldseekerSyncs func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] Files func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + Pools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] H3Aggregations func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] NoteAudios func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] NoteImages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - Pools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] Nuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] PublicreportPool func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] Quicks func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] @@ -8736,6 +8736,9 @@ func buildOrganizationCountThenLoader[Q orm.Loadable]() organizationCountThenLoa type FilesCountInterface interface { LoadCountFiles(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } + type PoolsCountInterface interface { + LoadCountPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } type H3AggregationsCountInterface interface { LoadCountH3Aggregations(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } @@ -8745,9 +8748,6 @@ func buildOrganizationCountThenLoader[Q orm.Loadable]() organizationCountThenLoa type NoteImagesCountInterface interface { LoadCountNoteImages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } - type PoolsCountInterface interface { - LoadCountPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error - } type NuisancesCountInterface interface { LoadCountNuisances(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } @@ -8948,6 +8948,12 @@ func buildOrganizationCountThenLoader[Q orm.Loadable]() organizationCountThenLoa return retrieved.LoadCountFiles(ctx, exec, mods...) }, ), + Pools: countThenLoadBuilder[Q]( + "Pools", + func(ctx context.Context, exec bob.Executor, retrieved PoolsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadCountPools(ctx, exec, mods...) + }, + ), H3Aggregations: countThenLoadBuilder[Q]( "H3Aggregations", func(ctx context.Context, exec bob.Executor, retrieved H3AggregationsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { @@ -8966,12 +8972,6 @@ func buildOrganizationCountThenLoader[Q orm.Loadable]() organizationCountThenLoa return retrieved.LoadCountNoteImages(ctx, exec, mods...) }, ), - Pools: countThenLoadBuilder[Q]( - "Pools", - func(ctx context.Context, exec bob.Executor, retrieved PoolsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadCountPools(ctx, exec, mods...) - }, - ), Nuisances: countThenLoadBuilder[Q]( "Nuisances", func(ctx context.Context, exec bob.Executor, retrieved NuisancesCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { @@ -9929,6 +9929,36 @@ func (os OrganizationSlice) LoadCountFiles(ctx context.Context, exec bob.Executo return nil } +// LoadCountPools loads the count of Pools into the C struct +func (o *Organization) LoadCountPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + count, err := o.Pools(mods...).Count(ctx, exec) + if err != nil { + return err + } + + o.C.Pools = &count + return nil +} + +// LoadCountPools loads the count of Pools for a slice +func (os OrganizationSlice) LoadCountPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + for _, o := range os { + if err := o.LoadCountPools(ctx, exec, mods...); err != nil { + return err + } + } + + return nil +} + // LoadCountH3Aggregations loads the count of H3Aggregations into the C struct func (o *Organization) LoadCountH3Aggregations(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if o == nil { @@ -10019,36 +10049,6 @@ func (os OrganizationSlice) LoadCountNoteImages(ctx context.Context, exec bob.Ex return nil } -// LoadCountPools loads the count of Pools into the C struct -func (o *Organization) LoadCountPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if o == nil { - return nil - } - - count, err := o.Pools(mods...).Count(ctx, exec) - if err != nil { - return err - } - - o.C.Pools = &count - return nil -} - -// LoadCountPools loads the count of Pools for a slice -func (os OrganizationSlice) LoadCountPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if len(os) == 0 { - return nil - } - - for _, o := range os { - if err := o.LoadCountPools(ctx, exec, mods...); err != nil { - return err - } - } - - return nil -} - // LoadCountNuisances loads the count of Nuisances into the C struct func (o *Organization) LoadCountNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if o == nil { @@ -10202,11 +10202,11 @@ type organizationJoins[Q dialect.Joinable] struct { Zones2s modAs[Q, fieldseekerZones2Columns] FieldseekerSyncs modAs[Q, fieldseekerSyncColumns] Files modAs[Q, fileuploadFileColumns] + Pools modAs[Q, fileuploadPoolColumns] H3Aggregations modAs[Q, h3AggregationColumns] NoteAudios modAs[Q, noteAudioColumns] NoteImages modAs[Q, noteImageColumns] ImportDistrictGidDistrict modAs[Q, importDistrictColumns] - Pools modAs[Q, poolColumns] Nuisances modAs[Q, publicreportNuisanceColumns] PublicreportPool modAs[Q, publicreportPoolColumns] Quicks modAs[Q, publicreportQuickColumns] @@ -10670,6 +10670,20 @@ func buildOrganizationJoins[Q dialect.Joinable](cols organizationColumns, typ st return mods }, }, + Pools: modAs[Q, fileuploadPoolColumns]{ + c: FileuploadPools.Columns, + f: func(to fileuploadPoolColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, FileuploadPools.Name().As(to.Alias())).On( + to.OrganizationID.EQ(cols.ID), + )) + } + + return mods + }, + }, H3Aggregations: modAs[Q, h3AggregationColumns]{ c: H3Aggregations.Columns, f: func(to h3AggregationColumns) bob.Mod[Q] { @@ -10726,20 +10740,6 @@ func buildOrganizationJoins[Q dialect.Joinable](cols organizationColumns, typ st return mods }, }, - Pools: modAs[Q, poolColumns]{ - c: Pools.Columns, - f: func(to poolColumns) bob.Mod[Q] { - mods := make(mods.QueryMods[Q], 0, 1) - - { - mods = append(mods, dialect.Join[Q](typ, Pools.Name().As(to.Alias())).On( - to.OrganizationID.EQ(cols.ID), - )) - } - - return mods - }, - }, Nuisances: modAs[Q, publicreportNuisanceColumns]{ c: PublicreportNuisances.Columns, f: func(to publicreportNuisanceColumns) bob.Mod[Q] { diff --git a/db/models/pool.bob.go b/db/models/pool.bob.go deleted file mode 100644 index 0379f082..00000000 --- a/db/models/pool.bob.go +++ /dev/null @@ -1,1142 +0,0 @@ -// Code generated by BobGen psql v0.42.5. DO NOT EDIT. -// This file is meant to be re-generated in place and/or deleted at any time. - -package models - -import ( - "context" - "fmt" - "io" - "time" - - "github.com/Gleipnir-Technology/bob" - "github.com/Gleipnir-Technology/bob/dialect/psql" - "github.com/Gleipnir-Technology/bob/dialect/psql/dialect" - "github.com/Gleipnir-Technology/bob/dialect/psql/dm" - "github.com/Gleipnir-Technology/bob/dialect/psql/sm" - "github.com/Gleipnir-Technology/bob/dialect/psql/um" - "github.com/Gleipnir-Technology/bob/expr" - "github.com/Gleipnir-Technology/bob/mods" - "github.com/Gleipnir-Technology/bob/orm" - "github.com/Gleipnir-Technology/bob/types/pgtypes" - enums "github.com/Gleipnir-Technology/nidus-sync/db/enums" - "github.com/aarondl/opt/null" - "github.com/aarondl/opt/omit" - "github.com/aarondl/opt/omitnull" -) - -// Pool is an object representing the database table. -type Pool struct { - AddressCity string `db:"address_city" ` - AddressPostalCode string `db:"address_postal_code" ` - AddressStreet string `db:"address_street" ` - Condition enums.Poolconditiontype `db:"condition" ` - Created time.Time `db:"created" ` - CreatorID int32 `db:"creator_id" ` - Deleted null.Val[time.Time] `db:"deleted" ` - Committed bool `db:"committed" ` - ID int32 `db:"id,pk" ` - Notes string `db:"notes" ` - OrganizationID int32 `db:"organization_id" ` - PropertyOwnerName string `db:"property_owner_name" ` - PropertyOwnerPhone null.Val[string] `db:"property_owner_phone" ` - ResidentOwned null.Val[bool] `db:"resident_owned" ` - ResidentPhone null.Val[string] `db:"resident_phone" ` - Version int32 `db:"version,pk" ` - - R poolR `db:"-" ` -} - -// PoolSlice is an alias for a slice of pointers to Pool. -// This should almost always be used instead of []*Pool. -type PoolSlice []*Pool - -// Pools contains methods to work with the pool table -var Pools = psql.NewTablex[*Pool, PoolSlice, *PoolSetter]("", "pool", buildPoolColumns("pool")) - -// PoolsQuery is a query on the pool table -type PoolsQuery = *psql.ViewQuery[*Pool, PoolSlice] - -// poolR is where relationships are stored. -type poolR struct { - CreatorUser *User // pool.pool_creator_id_fkey - Organization *Organization // pool.pool_organization_id_fkey -} - -func buildPoolColumns(alias string) poolColumns { - return poolColumns{ - ColumnsExpr: expr.NewColumnsExpr( - "address_city", "address_postal_code", "address_street", "condition", "created", "creator_id", "deleted", "committed", "id", "notes", "organization_id", "property_owner_name", "property_owner_phone", "resident_owned", "resident_phone", "version", - ).WithParent("pool"), - tableAlias: alias, - AddressCity: psql.Quote(alias, "address_city"), - AddressPostalCode: psql.Quote(alias, "address_postal_code"), - AddressStreet: psql.Quote(alias, "address_street"), - Condition: psql.Quote(alias, "condition"), - Created: psql.Quote(alias, "created"), - CreatorID: psql.Quote(alias, "creator_id"), - Deleted: psql.Quote(alias, "deleted"), - Committed: psql.Quote(alias, "committed"), - ID: psql.Quote(alias, "id"), - Notes: psql.Quote(alias, "notes"), - OrganizationID: psql.Quote(alias, "organization_id"), - PropertyOwnerName: psql.Quote(alias, "property_owner_name"), - PropertyOwnerPhone: psql.Quote(alias, "property_owner_phone"), - ResidentOwned: psql.Quote(alias, "resident_owned"), - ResidentPhone: psql.Quote(alias, "resident_phone"), - Version: psql.Quote(alias, "version"), - } -} - -type poolColumns struct { - expr.ColumnsExpr - tableAlias string - AddressCity psql.Expression - AddressPostalCode psql.Expression - AddressStreet psql.Expression - Condition psql.Expression - Created psql.Expression - CreatorID psql.Expression - Deleted psql.Expression - Committed psql.Expression - ID psql.Expression - Notes psql.Expression - OrganizationID psql.Expression - PropertyOwnerName psql.Expression - PropertyOwnerPhone psql.Expression - ResidentOwned psql.Expression - ResidentPhone psql.Expression - Version psql.Expression -} - -func (c poolColumns) Alias() string { - return c.tableAlias -} - -func (poolColumns) AliasedAs(alias string) poolColumns { - return buildPoolColumns(alias) -} - -// PoolSetter is used for insert/upsert/update operations -// All values are optional, and do not have to be set -// Generated columns are not included -type PoolSetter struct { - AddressCity omit.Val[string] `db:"address_city" ` - AddressPostalCode omit.Val[string] `db:"address_postal_code" ` - AddressStreet omit.Val[string] `db:"address_street" ` - Condition omit.Val[enums.Poolconditiontype] `db:"condition" ` - Created omit.Val[time.Time] `db:"created" ` - CreatorID omit.Val[int32] `db:"creator_id" ` - Deleted omitnull.Val[time.Time] `db:"deleted" ` - Committed omit.Val[bool] `db:"committed" ` - ID omit.Val[int32] `db:"id,pk" ` - Notes omit.Val[string] `db:"notes" ` - OrganizationID omit.Val[int32] `db:"organization_id" ` - PropertyOwnerName omit.Val[string] `db:"property_owner_name" ` - PropertyOwnerPhone omitnull.Val[string] `db:"property_owner_phone" ` - ResidentOwned omitnull.Val[bool] `db:"resident_owned" ` - ResidentPhone omitnull.Val[string] `db:"resident_phone" ` - Version omit.Val[int32] `db:"version,pk" ` -} - -func (s PoolSetter) SetColumns() []string { - vals := make([]string, 0, 16) - if s.AddressCity.IsValue() { - vals = append(vals, "address_city") - } - if s.AddressPostalCode.IsValue() { - vals = append(vals, "address_postal_code") - } - if s.AddressStreet.IsValue() { - vals = append(vals, "address_street") - } - if s.Condition.IsValue() { - vals = append(vals, "condition") - } - if s.Created.IsValue() { - vals = append(vals, "created") - } - if s.CreatorID.IsValue() { - vals = append(vals, "creator_id") - } - if !s.Deleted.IsUnset() { - vals = append(vals, "deleted") - } - if s.Committed.IsValue() { - vals = append(vals, "committed") - } - if s.ID.IsValue() { - vals = append(vals, "id") - } - if s.Notes.IsValue() { - vals = append(vals, "notes") - } - if s.OrganizationID.IsValue() { - vals = append(vals, "organization_id") - } - if s.PropertyOwnerName.IsValue() { - vals = append(vals, "property_owner_name") - } - if !s.PropertyOwnerPhone.IsUnset() { - vals = append(vals, "property_owner_phone") - } - if !s.ResidentOwned.IsUnset() { - vals = append(vals, "resident_owned") - } - if !s.ResidentPhone.IsUnset() { - vals = append(vals, "resident_phone") - } - if s.Version.IsValue() { - vals = append(vals, "version") - } - return vals -} - -func (s PoolSetter) Overwrite(t *Pool) { - if s.AddressCity.IsValue() { - t.AddressCity = s.AddressCity.MustGet() - } - if s.AddressPostalCode.IsValue() { - t.AddressPostalCode = s.AddressPostalCode.MustGet() - } - if s.AddressStreet.IsValue() { - t.AddressStreet = s.AddressStreet.MustGet() - } - if s.Condition.IsValue() { - t.Condition = s.Condition.MustGet() - } - if s.Created.IsValue() { - t.Created = s.Created.MustGet() - } - if s.CreatorID.IsValue() { - t.CreatorID = s.CreatorID.MustGet() - } - if !s.Deleted.IsUnset() { - t.Deleted = s.Deleted.MustGetNull() - } - if s.Committed.IsValue() { - t.Committed = s.Committed.MustGet() - } - if s.ID.IsValue() { - t.ID = s.ID.MustGet() - } - if s.Notes.IsValue() { - t.Notes = s.Notes.MustGet() - } - if s.OrganizationID.IsValue() { - t.OrganizationID = s.OrganizationID.MustGet() - } - if s.PropertyOwnerName.IsValue() { - t.PropertyOwnerName = s.PropertyOwnerName.MustGet() - } - if !s.PropertyOwnerPhone.IsUnset() { - t.PropertyOwnerPhone = s.PropertyOwnerPhone.MustGetNull() - } - if !s.ResidentOwned.IsUnset() { - t.ResidentOwned = s.ResidentOwned.MustGetNull() - } - if !s.ResidentPhone.IsUnset() { - t.ResidentPhone = s.ResidentPhone.MustGetNull() - } - if s.Version.IsValue() { - t.Version = s.Version.MustGet() - } -} - -func (s *PoolSetter) Apply(q *dialect.InsertQuery) { - q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { - return Pools.BeforeInsertHooks.RunHooks(ctx, exec, s) - }) - - q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { - vals := make([]bob.Expression, 16) - if s.AddressCity.IsValue() { - vals[0] = psql.Arg(s.AddressCity.MustGet()) - } else { - vals[0] = psql.Raw("DEFAULT") - } - - if s.AddressPostalCode.IsValue() { - vals[1] = psql.Arg(s.AddressPostalCode.MustGet()) - } else { - vals[1] = psql.Raw("DEFAULT") - } - - if s.AddressStreet.IsValue() { - vals[2] = psql.Arg(s.AddressStreet.MustGet()) - } else { - vals[2] = psql.Raw("DEFAULT") - } - - if s.Condition.IsValue() { - vals[3] = psql.Arg(s.Condition.MustGet()) - } else { - vals[3] = psql.Raw("DEFAULT") - } - - if s.Created.IsValue() { - vals[4] = psql.Arg(s.Created.MustGet()) - } else { - vals[4] = psql.Raw("DEFAULT") - } - - if s.CreatorID.IsValue() { - vals[5] = psql.Arg(s.CreatorID.MustGet()) - } else { - vals[5] = psql.Raw("DEFAULT") - } - - if !s.Deleted.IsUnset() { - vals[6] = psql.Arg(s.Deleted.MustGetNull()) - } else { - vals[6] = psql.Raw("DEFAULT") - } - - if s.Committed.IsValue() { - vals[7] = psql.Arg(s.Committed.MustGet()) - } else { - vals[7] = psql.Raw("DEFAULT") - } - - if s.ID.IsValue() { - vals[8] = psql.Arg(s.ID.MustGet()) - } else { - vals[8] = psql.Raw("DEFAULT") - } - - if s.Notes.IsValue() { - vals[9] = psql.Arg(s.Notes.MustGet()) - } else { - vals[9] = psql.Raw("DEFAULT") - } - - if s.OrganizationID.IsValue() { - vals[10] = psql.Arg(s.OrganizationID.MustGet()) - } else { - vals[10] = psql.Raw("DEFAULT") - } - - if s.PropertyOwnerName.IsValue() { - vals[11] = psql.Arg(s.PropertyOwnerName.MustGet()) - } else { - vals[11] = psql.Raw("DEFAULT") - } - - if !s.PropertyOwnerPhone.IsUnset() { - vals[12] = psql.Arg(s.PropertyOwnerPhone.MustGetNull()) - } else { - vals[12] = psql.Raw("DEFAULT") - } - - if !s.ResidentOwned.IsUnset() { - vals[13] = psql.Arg(s.ResidentOwned.MustGetNull()) - } else { - vals[13] = psql.Raw("DEFAULT") - } - - if !s.ResidentPhone.IsUnset() { - vals[14] = psql.Arg(s.ResidentPhone.MustGetNull()) - } else { - vals[14] = psql.Raw("DEFAULT") - } - - if s.Version.IsValue() { - vals[15] = psql.Arg(s.Version.MustGet()) - } else { - vals[15] = psql.Raw("DEFAULT") - } - - return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "") - })) -} - -func (s PoolSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] { - return um.Set(s.Expressions()...) -} - -func (s PoolSetter) Expressions(prefix ...string) []bob.Expression { - exprs := make([]bob.Expression, 0, 16) - - if s.AddressCity.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "address_city")...), - psql.Arg(s.AddressCity), - }}) - } - - if s.AddressPostalCode.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "address_postal_code")...), - psql.Arg(s.AddressPostalCode), - }}) - } - - if s.AddressStreet.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "address_street")...), - psql.Arg(s.AddressStreet), - }}) - } - - if s.Condition.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "condition")...), - psql.Arg(s.Condition), - }}) - } - - if s.Created.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "created")...), - psql.Arg(s.Created), - }}) - } - - if s.CreatorID.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "creator_id")...), - psql.Arg(s.CreatorID), - }}) - } - - if !s.Deleted.IsUnset() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "deleted")...), - psql.Arg(s.Deleted), - }}) - } - - if s.Committed.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "committed")...), - psql.Arg(s.Committed), - }}) - } - - if s.ID.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "id")...), - psql.Arg(s.ID), - }}) - } - - if s.Notes.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "notes")...), - psql.Arg(s.Notes), - }}) - } - - if s.OrganizationID.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "organization_id")...), - psql.Arg(s.OrganizationID), - }}) - } - - if s.PropertyOwnerName.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "property_owner_name")...), - psql.Arg(s.PropertyOwnerName), - }}) - } - - if !s.PropertyOwnerPhone.IsUnset() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "property_owner_phone")...), - psql.Arg(s.PropertyOwnerPhone), - }}) - } - - if !s.ResidentOwned.IsUnset() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "resident_owned")...), - psql.Arg(s.ResidentOwned), - }}) - } - - if !s.ResidentPhone.IsUnset() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "resident_phone")...), - psql.Arg(s.ResidentPhone), - }}) - } - - if s.Version.IsValue() { - exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ - psql.Quote(append(prefix, "version")...), - psql.Arg(s.Version), - }}) - } - - return exprs -} - -// FindPool retrieves a single record by primary key -// If cols is empty Find will return all columns. -func FindPool(ctx context.Context, exec bob.Executor, IDPK int32, VersionPK int32, cols ...string) (*Pool, error) { - if len(cols) == 0 { - return Pools.Query( - sm.Where(Pools.Columns.ID.EQ(psql.Arg(IDPK))), - sm.Where(Pools.Columns.Version.EQ(psql.Arg(VersionPK))), - ).One(ctx, exec) - } - - return Pools.Query( - sm.Where(Pools.Columns.ID.EQ(psql.Arg(IDPK))), - sm.Where(Pools.Columns.Version.EQ(psql.Arg(VersionPK))), - sm.Columns(Pools.Columns.Only(cols...)), - ).One(ctx, exec) -} - -// PoolExists checks the presence of a single record by primary key -func PoolExists(ctx context.Context, exec bob.Executor, IDPK int32, VersionPK int32) (bool, error) { - return Pools.Query( - sm.Where(Pools.Columns.ID.EQ(psql.Arg(IDPK))), - sm.Where(Pools.Columns.Version.EQ(psql.Arg(VersionPK))), - ).Exists(ctx, exec) -} - -// AfterQueryHook is called after Pool is retrieved from the database -func (o *Pool) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { - var err error - - switch queryType { - case bob.QueryTypeSelect: - ctx, err = Pools.AfterSelectHooks.RunHooks(ctx, exec, PoolSlice{o}) - case bob.QueryTypeInsert: - ctx, err = Pools.AfterInsertHooks.RunHooks(ctx, exec, PoolSlice{o}) - case bob.QueryTypeUpdate: - ctx, err = Pools.AfterUpdateHooks.RunHooks(ctx, exec, PoolSlice{o}) - case bob.QueryTypeDelete: - ctx, err = Pools.AfterDeleteHooks.RunHooks(ctx, exec, PoolSlice{o}) - } - - return err -} - -// primaryKeyVals returns the primary key values of the Pool -func (o *Pool) primaryKeyVals() bob.Expression { - return psql.ArgGroup( - o.ID, - o.Version, - ) -} - -func (o *Pool) pkEQ() dialect.Expression { - return psql.Group(psql.Quote("pool", "id"), psql.Quote("pool", "version")).EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { - return o.primaryKeyVals().WriteSQL(ctx, w, d, start) - })) -} - -// Update uses an executor to update the Pool -func (o *Pool) Update(ctx context.Context, exec bob.Executor, s *PoolSetter) error { - v, err := Pools.Update(s.UpdateMod(), um.Where(o.pkEQ())).One(ctx, exec) - if err != nil { - return err - } - - o.R = v.R - *o = *v - - return nil -} - -// Delete deletes a single Pool record with an executor -func (o *Pool) Delete(ctx context.Context, exec bob.Executor) error { - _, err := Pools.Delete(dm.Where(o.pkEQ())).Exec(ctx, exec) - return err -} - -// Reload refreshes the Pool using the executor -func (o *Pool) Reload(ctx context.Context, exec bob.Executor) error { - o2, err := Pools.Query( - sm.Where(Pools.Columns.ID.EQ(psql.Arg(o.ID))), - sm.Where(Pools.Columns.Version.EQ(psql.Arg(o.Version))), - ).One(ctx, exec) - if err != nil { - return err - } - o2.R = o.R - *o = *o2 - - return nil -} - -// AfterQueryHook is called after PoolSlice is retrieved from the database -func (o PoolSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error { - var err error - - switch queryType { - case bob.QueryTypeSelect: - ctx, err = Pools.AfterSelectHooks.RunHooks(ctx, exec, o) - case bob.QueryTypeInsert: - ctx, err = Pools.AfterInsertHooks.RunHooks(ctx, exec, o) - case bob.QueryTypeUpdate: - ctx, err = Pools.AfterUpdateHooks.RunHooks(ctx, exec, o) - case bob.QueryTypeDelete: - ctx, err = Pools.AfterDeleteHooks.RunHooks(ctx, exec, o) - } - - return err -} - -func (o PoolSlice) pkIN() dialect.Expression { - if len(o) == 0 { - return psql.Raw("NULL") - } - - return psql.Group(psql.Quote("pool", "id"), psql.Quote("pool", "version")).In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) { - pkPairs := make([]bob.Expression, len(o)) - for i, row := range o { - pkPairs[i] = row.primaryKeyVals() - } - return bob.ExpressSlice(ctx, w, d, start, pkPairs, "", ", ", "") - })) -} - -// copyMatchingRows finds models in the given slice that have the same primary key -// then it first copies the existing relationships from the old model to the new model -// and then replaces the old model in the slice with the new model -func (o PoolSlice) copyMatchingRows(from ...*Pool) { - for i, old := range o { - for _, new := range from { - if new.ID != old.ID { - continue - } - if new.Version != old.Version { - continue - } - new.R = old.R - o[i] = new - break - } - } -} - -// UpdateMod modifies an update query with "WHERE primary_key IN (o...)" -func (o PoolSlice) UpdateMod() bob.Mod[*dialect.UpdateQuery] { - return bob.ModFunc[*dialect.UpdateQuery](func(q *dialect.UpdateQuery) { - q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { - return Pools.BeforeUpdateHooks.RunHooks(ctx, exec, o) - }) - - q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { - var err error - switch retrieved := retrieved.(type) { - case *Pool: - o.copyMatchingRows(retrieved) - case []*Pool: - o.copyMatchingRows(retrieved...) - case PoolSlice: - o.copyMatchingRows(retrieved...) - default: - // If the retrieved value is not a Pool or a slice of Pool - // then run the AfterUpdateHooks on the slice - _, err = Pools.AfterUpdateHooks.RunHooks(ctx, exec, o) - } - - return err - })) - - q.AppendWhere(o.pkIN()) - }) -} - -// DeleteMod modifies an delete query with "WHERE primary_key IN (o...)" -func (o PoolSlice) DeleteMod() bob.Mod[*dialect.DeleteQuery] { - return bob.ModFunc[*dialect.DeleteQuery](func(q *dialect.DeleteQuery) { - q.AppendHooks(func(ctx context.Context, exec bob.Executor) (context.Context, error) { - return Pools.BeforeDeleteHooks.RunHooks(ctx, exec, o) - }) - - q.AppendLoader(bob.LoaderFunc(func(ctx context.Context, exec bob.Executor, retrieved any) error { - var err error - switch retrieved := retrieved.(type) { - case *Pool: - o.copyMatchingRows(retrieved) - case []*Pool: - o.copyMatchingRows(retrieved...) - case PoolSlice: - o.copyMatchingRows(retrieved...) - default: - // If the retrieved value is not a Pool or a slice of Pool - // then run the AfterDeleteHooks on the slice - _, err = Pools.AfterDeleteHooks.RunHooks(ctx, exec, o) - } - - return err - })) - - q.AppendWhere(o.pkIN()) - }) -} - -func (o PoolSlice) UpdateAll(ctx context.Context, exec bob.Executor, vals PoolSetter) error { - if len(o) == 0 { - return nil - } - - _, err := Pools.Update(vals.UpdateMod(), o.UpdateMod()).All(ctx, exec) - return err -} - -func (o PoolSlice) DeleteAll(ctx context.Context, exec bob.Executor) error { - if len(o) == 0 { - return nil - } - - _, err := Pools.Delete(o.DeleteMod()).Exec(ctx, exec) - return err -} - -func (o PoolSlice) ReloadAll(ctx context.Context, exec bob.Executor) error { - if len(o) == 0 { - return nil - } - - o2, err := Pools.Query(sm.Where(o.pkIN())).All(ctx, exec) - if err != nil { - return err - } - - o.copyMatchingRows(o2...) - - return nil -} - -// CreatorUser starts a query for related objects on user_ -func (o *Pool) CreatorUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery { - return Users.Query(append(mods, - sm.Where(Users.Columns.ID.EQ(psql.Arg(o.CreatorID))), - )...) -} - -func (os PoolSlice) CreatorUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery { - pkCreatorID := make(pgtypes.Array[int32], 0, len(os)) - for _, o := range os { - if o == nil { - continue - } - pkCreatorID = append(pkCreatorID, o.CreatorID) - } - PKArgExpr := psql.Select(sm.Columns( - psql.F("unnest", psql.Cast(psql.Arg(pkCreatorID), "integer[]")), - )) - - return Users.Query(append(mods, - sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)), - )...) -} - -// Organization starts a query for related objects on organization -func (o *Pool) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery { - return Organizations.Query(append(mods, - sm.Where(Organizations.Columns.ID.EQ(psql.Arg(o.OrganizationID))), - )...) -} - -func (os PoolSlice) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery { - pkOrganizationID := make(pgtypes.Array[int32], 0, len(os)) - for _, o := range os { - if o == nil { - continue - } - pkOrganizationID = append(pkOrganizationID, o.OrganizationID) - } - PKArgExpr := psql.Select(sm.Columns( - psql.F("unnest", psql.Cast(psql.Arg(pkOrganizationID), "integer[]")), - )) - - return Organizations.Query(append(mods, - sm.Where(psql.Group(Organizations.Columns.ID).OP("IN", PKArgExpr)), - )...) -} - -func attachPoolCreatorUser0(ctx context.Context, exec bob.Executor, count int, pool0 *Pool, user1 *User) (*Pool, error) { - setter := &PoolSetter{ - CreatorID: omit.From(user1.ID), - } - - err := pool0.Update(ctx, exec, setter) - if err != nil { - return nil, fmt.Errorf("attachPoolCreatorUser0: %w", err) - } - - return pool0, nil -} - -func (pool0 *Pool) InsertCreatorUser(ctx context.Context, exec bob.Executor, related *UserSetter) error { - var err error - - user1, err := Users.Insert(related).One(ctx, exec) - if err != nil { - return fmt.Errorf("inserting related objects: %w", err) - } - - _, err = attachPoolCreatorUser0(ctx, exec, 1, pool0, user1) - if err != nil { - return err - } - - pool0.R.CreatorUser = user1 - - user1.R.CreatorPools = append(user1.R.CreatorPools, pool0) - - return nil -} - -func (pool0 *Pool) AttachCreatorUser(ctx context.Context, exec bob.Executor, user1 *User) error { - var err error - - _, err = attachPoolCreatorUser0(ctx, exec, 1, pool0, user1) - if err != nil { - return err - } - - pool0.R.CreatorUser = user1 - - user1.R.CreatorPools = append(user1.R.CreatorPools, pool0) - - return nil -} - -func attachPoolOrganization0(ctx context.Context, exec bob.Executor, count int, pool0 *Pool, organization1 *Organization) (*Pool, error) { - setter := &PoolSetter{ - OrganizationID: omit.From(organization1.ID), - } - - err := pool0.Update(ctx, exec, setter) - if err != nil { - return nil, fmt.Errorf("attachPoolOrganization0: %w", err) - } - - return pool0, nil -} - -func (pool0 *Pool) InsertOrganization(ctx context.Context, exec bob.Executor, related *OrganizationSetter) error { - var err error - - organization1, err := Organizations.Insert(related).One(ctx, exec) - if err != nil { - return fmt.Errorf("inserting related objects: %w", err) - } - - _, err = attachPoolOrganization0(ctx, exec, 1, pool0, organization1) - if err != nil { - return err - } - - pool0.R.Organization = organization1 - - organization1.R.Pools = append(organization1.R.Pools, pool0) - - return nil -} - -func (pool0 *Pool) AttachOrganization(ctx context.Context, exec bob.Executor, organization1 *Organization) error { - var err error - - _, err = attachPoolOrganization0(ctx, exec, 1, pool0, organization1) - if err != nil { - return err - } - - pool0.R.Organization = organization1 - - organization1.R.Pools = append(organization1.R.Pools, pool0) - - return nil -} - -type poolWhere[Q psql.Filterable] struct { - AddressCity psql.WhereMod[Q, string] - AddressPostalCode psql.WhereMod[Q, string] - AddressStreet psql.WhereMod[Q, string] - Condition psql.WhereMod[Q, enums.Poolconditiontype] - Created psql.WhereMod[Q, time.Time] - CreatorID psql.WhereMod[Q, int32] - Deleted psql.WhereNullMod[Q, time.Time] - Committed psql.WhereMod[Q, bool] - ID psql.WhereMod[Q, int32] - Notes psql.WhereMod[Q, string] - OrganizationID psql.WhereMod[Q, int32] - PropertyOwnerName psql.WhereMod[Q, string] - PropertyOwnerPhone psql.WhereNullMod[Q, string] - ResidentOwned psql.WhereNullMod[Q, bool] - ResidentPhone psql.WhereNullMod[Q, string] - Version psql.WhereMod[Q, int32] -} - -func (poolWhere[Q]) AliasedAs(alias string) poolWhere[Q] { - return buildPoolWhere[Q](buildPoolColumns(alias)) -} - -func buildPoolWhere[Q psql.Filterable](cols poolColumns) poolWhere[Q] { - return poolWhere[Q]{ - AddressCity: psql.Where[Q, string](cols.AddressCity), - AddressPostalCode: psql.Where[Q, string](cols.AddressPostalCode), - AddressStreet: psql.Where[Q, string](cols.AddressStreet), - Condition: psql.Where[Q, enums.Poolconditiontype](cols.Condition), - Created: psql.Where[Q, time.Time](cols.Created), - CreatorID: psql.Where[Q, int32](cols.CreatorID), - Deleted: psql.WhereNull[Q, time.Time](cols.Deleted), - Committed: psql.Where[Q, bool](cols.Committed), - ID: psql.Where[Q, int32](cols.ID), - Notes: psql.Where[Q, string](cols.Notes), - OrganizationID: psql.Where[Q, int32](cols.OrganizationID), - PropertyOwnerName: psql.Where[Q, string](cols.PropertyOwnerName), - PropertyOwnerPhone: psql.WhereNull[Q, string](cols.PropertyOwnerPhone), - ResidentOwned: psql.WhereNull[Q, bool](cols.ResidentOwned), - ResidentPhone: psql.WhereNull[Q, string](cols.ResidentPhone), - Version: psql.Where[Q, int32](cols.Version), - } -} - -func (o *Pool) Preload(name string, retrieved any) error { - if o == nil { - return nil - } - - switch name { - case "CreatorUser": - rel, ok := retrieved.(*User) - if !ok { - return fmt.Errorf("pool cannot load %T as %q", retrieved, name) - } - - o.R.CreatorUser = rel - - if rel != nil { - rel.R.CreatorPools = PoolSlice{o} - } - return nil - case "Organization": - rel, ok := retrieved.(*Organization) - if !ok { - return fmt.Errorf("pool cannot load %T as %q", retrieved, name) - } - - o.R.Organization = rel - - if rel != nil { - rel.R.Pools = PoolSlice{o} - } - return nil - default: - return fmt.Errorf("pool has no relationship %q", name) - } -} - -type poolPreloader struct { - CreatorUser func(...psql.PreloadOption) psql.Preloader - Organization func(...psql.PreloadOption) psql.Preloader -} - -func buildPoolPreloader() poolPreloader { - return poolPreloader{ - CreatorUser: func(opts ...psql.PreloadOption) psql.Preloader { - return psql.Preload[*User, UserSlice](psql.PreloadRel{ - Name: "CreatorUser", - Sides: []psql.PreloadSide{ - { - From: Pools, - To: Users, - FromColumns: []string{"creator_id"}, - ToColumns: []string{"id"}, - }, - }, - }, Users.Columns.Names(), opts...) - }, - Organization: func(opts ...psql.PreloadOption) psql.Preloader { - return psql.Preload[*Organization, OrganizationSlice](psql.PreloadRel{ - Name: "Organization", - Sides: []psql.PreloadSide{ - { - From: Pools, - To: Organizations, - FromColumns: []string{"organization_id"}, - ToColumns: []string{"id"}, - }, - }, - }, Organizations.Columns.Names(), opts...) - }, - } -} - -type poolThenLoader[Q orm.Loadable] struct { - CreatorUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] -} - -func buildPoolThenLoader[Q orm.Loadable]() poolThenLoader[Q] { - type CreatorUserLoadInterface interface { - LoadCreatorUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error - } - type OrganizationLoadInterface interface { - LoadOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error - } - - return poolThenLoader[Q]{ - CreatorUser: thenLoadBuilder[Q]( - "CreatorUser", - func(ctx context.Context, exec bob.Executor, retrieved CreatorUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadCreatorUser(ctx, exec, mods...) - }, - ), - Organization: thenLoadBuilder[Q]( - "Organization", - func(ctx context.Context, exec bob.Executor, retrieved OrganizationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadOrganization(ctx, exec, mods...) - }, - ), - } -} - -// LoadCreatorUser loads the pool's CreatorUser into the .R struct -func (o *Pool) LoadCreatorUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if o == nil { - return nil - } - - // Reset the relationship - o.R.CreatorUser = nil - - related, err := o.CreatorUser(mods...).One(ctx, exec) - if err != nil { - return err - } - - related.R.CreatorPools = PoolSlice{o} - - o.R.CreatorUser = related - return nil -} - -// LoadCreatorUser loads the pool's CreatorUser into the .R struct -func (os PoolSlice) LoadCreatorUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if len(os) == 0 { - return nil - } - - users, err := os.CreatorUser(mods...).All(ctx, exec) - if err != nil { - return err - } - - for _, o := range os { - if o == nil { - continue - } - - for _, rel := range users { - - if !(o.CreatorID == rel.ID) { - continue - } - - rel.R.CreatorPools = append(rel.R.CreatorPools, o) - - o.R.CreatorUser = rel - break - } - } - - return nil -} - -// LoadOrganization loads the pool's Organization into the .R struct -func (o *Pool) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if o == nil { - return nil - } - - // Reset the relationship - o.R.Organization = nil - - related, err := o.Organization(mods...).One(ctx, exec) - if err != nil { - return err - } - - related.R.Pools = PoolSlice{o} - - o.R.Organization = related - return nil -} - -// LoadOrganization loads the pool's Organization into the .R struct -func (os PoolSlice) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if len(os) == 0 { - return nil - } - - organizations, err := os.Organization(mods...).All(ctx, exec) - if err != nil { - return err - } - - for _, o := range os { - if o == nil { - continue - } - - for _, rel := range organizations { - - if !(o.OrganizationID == rel.ID) { - continue - } - - rel.R.Pools = append(rel.R.Pools, o) - - o.R.Organization = rel - break - } - } - - return nil -} - -type poolJoins[Q dialect.Joinable] struct { - typ string - CreatorUser modAs[Q, userColumns] - Organization modAs[Q, organizationColumns] -} - -func (j poolJoins[Q]) aliasedAs(alias string) poolJoins[Q] { - return buildPoolJoins[Q](buildPoolColumns(alias), j.typ) -} - -func buildPoolJoins[Q dialect.Joinable](cols poolColumns, typ string) poolJoins[Q] { - return poolJoins[Q]{ - typ: typ, - CreatorUser: modAs[Q, userColumns]{ - c: Users.Columns, - f: func(to userColumns) bob.Mod[Q] { - mods := make(mods.QueryMods[Q], 0, 1) - - { - mods = append(mods, dialect.Join[Q](typ, Users.Name().As(to.Alias())).On( - to.ID.EQ(cols.CreatorID), - )) - } - - return mods - }, - }, - Organization: modAs[Q, organizationColumns]{ - c: Organizations.Columns, - f: func(to organizationColumns) bob.Mod[Q] { - mods := make(mods.QueryMods[Q], 0, 1) - - { - mods = append(mods, dialect.Join[Q](typ, Organizations.Name().As(to.Alias())).On( - to.ID.EQ(cols.OrganizationID), - )) - } - - return mods - }, - }, - } -} diff --git a/db/models/user_.bob.go b/db/models/user_.bob.go index 37eb4d1d..dab7addb 100644 --- a/db/models/user_.bob.go +++ b/db/models/user_.bob.go @@ -59,13 +59,13 @@ type UsersQuery = *psql.ViewQuery[*User, UserSlice] type userR struct { PublicUserUser ArcgisUserSlice // arcgis.user_.user__public_user_id_fkey CreatorFiles FileuploadFileSlice // fileupload.file.file_creator_id_fkey + CreatorPools FileuploadPoolSlice // fileupload.pool.pool_creator_id_fkey CreatorNoteAudios NoteAudioSlice // note_audio.note_audio_creator_id_fkey DeletorNoteAudios NoteAudioSlice // note_audio.note_audio_deletor_id_fkey CreatorNoteImages NoteImageSlice // note_image.note_image_creator_id_fkey DeletorNoteImages NoteImageSlice // note_image.note_image_deletor_id_fkey UserNotifications NotificationSlice // notification.notification_user_id_fkey UserOauthTokens OauthTokenSlice // oauth_token.oauth_token_user_id_fkey - CreatorPools PoolSlice // pool.pool_creator_id_fkey Organization *Organization // user_.user__organization_id_fkey } @@ -661,6 +661,30 @@ func (os UserSlice) CreatorFiles(mods ...bob.Mod[*dialect.SelectQuery]) Fileuplo )...) } +// CreatorPools starts a query for related objects on fileupload.pool +func (o *User) CreatorPools(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadPoolsQuery { + return FileuploadPools.Query(append(mods, + sm.Where(FileuploadPools.Columns.CreatorID.EQ(psql.Arg(o.ID))), + )...) +} + +func (os UserSlice) CreatorPools(mods ...bob.Mod[*dialect.SelectQuery]) FileuploadPoolsQuery { + pkID := make(pgtypes.Array[int32], 0, len(os)) + for _, o := range os { + if o == nil { + continue + } + pkID = append(pkID, o.ID) + } + PKArgExpr := psql.Select(sm.Columns( + psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")), + )) + + return FileuploadPools.Query(append(mods, + sm.Where(psql.Group(FileuploadPools.Columns.CreatorID).OP("IN", PKArgExpr)), + )...) +} + // CreatorNoteAudios starts a query for related objects on note_audio func (o *User) CreatorNoteAudios(mods ...bob.Mod[*dialect.SelectQuery]) NoteAudiosQuery { return NoteAudios.Query(append(mods, @@ -805,30 +829,6 @@ func (os UserSlice) UserOauthTokens(mods ...bob.Mod[*dialect.SelectQuery]) Oauth )...) } -// CreatorPools starts a query for related objects on pool -func (o *User) CreatorPools(mods ...bob.Mod[*dialect.SelectQuery]) PoolsQuery { - return Pools.Query(append(mods, - sm.Where(Pools.Columns.CreatorID.EQ(psql.Arg(o.ID))), - )...) -} - -func (os UserSlice) CreatorPools(mods ...bob.Mod[*dialect.SelectQuery]) PoolsQuery { - pkID := make(pgtypes.Array[int32], 0, len(os)) - for _, o := range os { - if o == nil { - continue - } - pkID = append(pkID, o.ID) - } - PKArgExpr := psql.Select(sm.Columns( - psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")), - )) - - return Pools.Query(append(mods, - sm.Where(psql.Group(Pools.Columns.CreatorID).OP("IN", PKArgExpr)), - )...) -} - // Organization starts a query for related objects on organization func (o *User) Organization(mods ...bob.Mod[*dialect.SelectQuery]) OrganizationsQuery { return Organizations.Query(append(mods, @@ -989,6 +989,74 @@ func (user0 *User) AttachCreatorFiles(ctx context.Context, exec bob.Executor, re return nil } +func insertUserCreatorPools0(ctx context.Context, exec bob.Executor, fileuploadPools1 []*FileuploadPoolSetter, user0 *User) (FileuploadPoolSlice, error) { + for i := range fileuploadPools1 { + fileuploadPools1[i].CreatorID = omit.From(user0.ID) + } + + ret, err := FileuploadPools.Insert(bob.ToMods(fileuploadPools1...)).All(ctx, exec) + if err != nil { + return ret, fmt.Errorf("insertUserCreatorPools0: %w", err) + } + + return ret, nil +} + +func attachUserCreatorPools0(ctx context.Context, exec bob.Executor, count int, fileuploadPools1 FileuploadPoolSlice, user0 *User) (FileuploadPoolSlice, error) { + setter := &FileuploadPoolSetter{ + CreatorID: omit.From(user0.ID), + } + + err := fileuploadPools1.UpdateAll(ctx, exec, *setter) + if err != nil { + return nil, fmt.Errorf("attachUserCreatorPools0: %w", err) + } + + return fileuploadPools1, nil +} + +func (user0 *User) InsertCreatorPools(ctx context.Context, exec bob.Executor, related ...*FileuploadPoolSetter) error { + if len(related) == 0 { + return nil + } + + var err error + + fileuploadPools1, err := insertUserCreatorPools0(ctx, exec, related, user0) + if err != nil { + return err + } + + user0.R.CreatorPools = append(user0.R.CreatorPools, fileuploadPools1...) + + for _, rel := range fileuploadPools1 { + rel.R.CreatorUser = user0 + } + return nil +} + +func (user0 *User) AttachCreatorPools(ctx context.Context, exec bob.Executor, related ...*FileuploadPool) error { + if len(related) == 0 { + return nil + } + + var err error + fileuploadPools1 := FileuploadPoolSlice(related) + + _, err = attachUserCreatorPools0(ctx, exec, len(related), fileuploadPools1, user0) + if err != nil { + return err + } + + user0.R.CreatorPools = append(user0.R.CreatorPools, fileuploadPools1...) + + for _, rel := range related { + rel.R.CreatorUser = user0 + } + + return nil +} + func insertUserCreatorNoteAudios0(ctx context.Context, exec bob.Executor, noteAudios1 []*NoteAudioSetter, user0 *User) (NoteAudioSlice, error) { for i := range noteAudios1 { noteAudios1[i].CreatorID = omit.From(user0.ID) @@ -1397,74 +1465,6 @@ func (user0 *User) AttachUserOauthTokens(ctx context.Context, exec bob.Executor, return nil } -func insertUserCreatorPools0(ctx context.Context, exec bob.Executor, pools1 []*PoolSetter, user0 *User) (PoolSlice, error) { - for i := range pools1 { - pools1[i].CreatorID = omit.From(user0.ID) - } - - ret, err := Pools.Insert(bob.ToMods(pools1...)).All(ctx, exec) - if err != nil { - return ret, fmt.Errorf("insertUserCreatorPools0: %w", err) - } - - return ret, nil -} - -func attachUserCreatorPools0(ctx context.Context, exec bob.Executor, count int, pools1 PoolSlice, user0 *User) (PoolSlice, error) { - setter := &PoolSetter{ - CreatorID: omit.From(user0.ID), - } - - err := pools1.UpdateAll(ctx, exec, *setter) - if err != nil { - return nil, fmt.Errorf("attachUserCreatorPools0: %w", err) - } - - return pools1, nil -} - -func (user0 *User) InsertCreatorPools(ctx context.Context, exec bob.Executor, related ...*PoolSetter) error { - if len(related) == 0 { - return nil - } - - var err error - - pools1, err := insertUserCreatorPools0(ctx, exec, related, user0) - if err != nil { - return err - } - - user0.R.CreatorPools = append(user0.R.CreatorPools, pools1...) - - for _, rel := range pools1 { - rel.R.CreatorUser = user0 - } - return nil -} - -func (user0 *User) AttachCreatorPools(ctx context.Context, exec bob.Executor, related ...*Pool) error { - if len(related) == 0 { - return nil - } - - var err error - pools1 := PoolSlice(related) - - _, err = attachUserCreatorPools0(ctx, exec, len(related), pools1, user0) - if err != nil { - return err - } - - user0.R.CreatorPools = append(user0.R.CreatorPools, pools1...) - - for _, rel := range related { - rel.R.CreatorUser = user0 - } - - return nil -} - func attachUserOrganization0(ctx context.Context, exec bob.Executor, count int, user0 *User, organization1 *Organization) (*User, error) { setter := &UserSetter{ OrganizationID: omit.From(organization1.ID), @@ -1577,6 +1577,20 @@ func (o *User) Preload(name string, retrieved any) error { o.R.CreatorFiles = rels + for _, rel := range rels { + if rel != nil { + rel.R.CreatorUser = o + } + } + return nil + case "CreatorPools": + rels, ok := retrieved.(FileuploadPoolSlice) + if !ok { + return fmt.Errorf("user cannot load %T as %q", retrieved, name) + } + + o.R.CreatorPools = rels + for _, rel := range rels { if rel != nil { rel.R.CreatorUser = o @@ -1667,20 +1681,6 @@ func (o *User) Preload(name string, retrieved any) error { } } return nil - case "CreatorPools": - rels, ok := retrieved.(PoolSlice) - if !ok { - return fmt.Errorf("user cannot load %T as %q", retrieved, name) - } - - o.R.CreatorPools = rels - - for _, rel := range rels { - if rel != nil { - rel.R.CreatorUser = o - } - } - return nil case "Organization": rel, ok := retrieved.(*Organization) if !ok { @@ -1723,13 +1723,13 @@ func buildUserPreloader() userPreloader { type userThenLoader[Q orm.Loadable] struct { PublicUserUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] CreatorFiles func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + CreatorPools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] CreatorNoteAudios func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] DeletorNoteAudios func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] CreatorNoteImages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] DeletorNoteImages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] UserNotifications func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] UserOauthTokens func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - CreatorPools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] } @@ -1740,6 +1740,9 @@ func buildUserThenLoader[Q orm.Loadable]() userThenLoader[Q] { type CreatorFilesLoadInterface interface { LoadCreatorFiles(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } + type CreatorPoolsLoadInterface interface { + LoadCreatorPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } type CreatorNoteAudiosLoadInterface interface { LoadCreatorNoteAudios(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } @@ -1758,9 +1761,6 @@ func buildUserThenLoader[Q orm.Loadable]() userThenLoader[Q] { type UserOauthTokensLoadInterface interface { LoadUserOauthTokens(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } - type CreatorPoolsLoadInterface interface { - LoadCreatorPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error - } type OrganizationLoadInterface interface { LoadOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } @@ -1778,6 +1778,12 @@ func buildUserThenLoader[Q orm.Loadable]() userThenLoader[Q] { return retrieved.LoadCreatorFiles(ctx, exec, mods...) }, ), + CreatorPools: thenLoadBuilder[Q]( + "CreatorPools", + func(ctx context.Context, exec bob.Executor, retrieved CreatorPoolsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadCreatorPools(ctx, exec, mods...) + }, + ), CreatorNoteAudios: thenLoadBuilder[Q]( "CreatorNoteAudios", func(ctx context.Context, exec bob.Executor, retrieved CreatorNoteAudiosLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { @@ -1814,12 +1820,6 @@ func buildUserThenLoader[Q orm.Loadable]() userThenLoader[Q] { return retrieved.LoadUserOauthTokens(ctx, exec, mods...) }, ), - CreatorPools: thenLoadBuilder[Q]( - "CreatorPools", - func(ctx context.Context, exec bob.Executor, retrieved CreatorPoolsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadCreatorPools(ctx, exec, mods...) - }, - ), Organization: thenLoadBuilder[Q]( "Organization", func(ctx context.Context, exec bob.Executor, retrieved OrganizationLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { @@ -1951,6 +1951,67 @@ func (os UserSlice) LoadCreatorFiles(ctx context.Context, exec bob.Executor, mod return nil } +// LoadCreatorPools loads the user's CreatorPools into the .R struct +func (o *User) LoadCreatorPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + // Reset the relationship + o.R.CreatorPools = nil + + related, err := o.CreatorPools(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, rel := range related { + rel.R.CreatorUser = o + } + + o.R.CreatorPools = related + return nil +} + +// LoadCreatorPools loads the user's CreatorPools into the .R struct +func (os UserSlice) LoadCreatorPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + fileuploadPools, err := os.CreatorPools(mods...).All(ctx, exec) + if err != nil { + return err + } + + for _, o := range os { + if o == nil { + continue + } + + o.R.CreatorPools = nil + } + + for _, o := range os { + if o == nil { + continue + } + + for _, rel := range fileuploadPools { + + if !(o.ID == rel.CreatorID) { + continue + } + + rel.R.CreatorUser = o + + o.R.CreatorPools = append(o.R.CreatorPools, rel) + } + } + + return nil +} + // LoadCreatorNoteAudios loads the user's CreatorNoteAudios into the .R struct func (o *User) LoadCreatorNoteAudios(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if o == nil { @@ -2323,67 +2384,6 @@ func (os UserSlice) LoadUserOauthTokens(ctx context.Context, exec bob.Executor, return nil } -// LoadCreatorPools loads the user's CreatorPools into the .R struct -func (o *User) LoadCreatorPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if o == nil { - return nil - } - - // Reset the relationship - o.R.CreatorPools = nil - - related, err := o.CreatorPools(mods...).All(ctx, exec) - if err != nil { - return err - } - - for _, rel := range related { - rel.R.CreatorUser = o - } - - o.R.CreatorPools = related - return nil -} - -// LoadCreatorPools loads the user's CreatorPools into the .R struct -func (os UserSlice) LoadCreatorPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if len(os) == 0 { - return nil - } - - pools, err := os.CreatorPools(mods...).All(ctx, exec) - if err != nil { - return err - } - - for _, o := range os { - if o == nil { - continue - } - - o.R.CreatorPools = nil - } - - for _, o := range os { - if o == nil { - continue - } - - for _, rel := range pools { - - if !(o.ID == rel.CreatorID) { - continue - } - - rel.R.CreatorUser = o - - o.R.CreatorPools = append(o.R.CreatorPools, rel) - } - } - - return nil -} - // LoadOrganization loads the user's Organization into the .R struct func (o *User) LoadOrganization(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if o == nil { @@ -2440,13 +2440,13 @@ func (os UserSlice) LoadOrganization(ctx context.Context, exec bob.Executor, mod type userC struct { PublicUserUser *int64 CreatorFiles *int64 + CreatorPools *int64 CreatorNoteAudios *int64 DeletorNoteAudios *int64 CreatorNoteImages *int64 DeletorNoteImages *int64 UserNotifications *int64 UserOauthTokens *int64 - CreatorPools *int64 } // PreloadCount sets a count in the C struct by name @@ -2460,6 +2460,8 @@ func (o *User) PreloadCount(name string, count int64) error { o.C.PublicUserUser = &count case "CreatorFiles": o.C.CreatorFiles = &count + case "CreatorPools": + o.C.CreatorPools = &count case "CreatorNoteAudios": o.C.CreatorNoteAudios = &count case "DeletorNoteAudios": @@ -2472,8 +2474,6 @@ func (o *User) PreloadCount(name string, count int64) error { o.C.UserNotifications = &count case "UserOauthTokens": o.C.UserOauthTokens = &count - case "CreatorPools": - o.C.CreatorPools = &count } return nil } @@ -2481,13 +2481,13 @@ func (o *User) PreloadCount(name string, count int64) error { type userCountPreloader struct { PublicUserUser func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader CreatorFiles func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader + CreatorPools func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader CreatorNoteAudios func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader DeletorNoteAudios func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader CreatorNoteImages func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader DeletorNoteImages func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader UserNotifications func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader UserOauthTokens func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader - CreatorPools func(...bob.Mod[*dialect.SelectQuery]) psql.Preloader } func buildUserCountPreloader() userCountPreloader { @@ -2526,6 +2526,23 @@ func buildUserCountPreloader() userCountPreloader { return psql.Group(psql.Select(subqueryMods...).Expression) }) }, + CreatorPools: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader { + return countPreloader[*User]("CreatorPools", func(parent string) bob.Expression { + // Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk) + if parent == "" { + parent = Users.Alias() + } + + subqueryMods := []bob.Mod[*dialect.SelectQuery]{ + sm.Columns(psql.Raw("count(*)")), + + sm.From(FileuploadPools.Name()), + sm.Where(psql.Quote(FileuploadPools.Alias(), "creator_id").EQ(psql.Quote(parent, "id"))), + } + subqueryMods = append(subqueryMods, mods...) + return psql.Group(psql.Select(subqueryMods...).Expression) + }) + }, CreatorNoteAudios: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader { return countPreloader[*User]("CreatorNoteAudios", func(parent string) bob.Expression { // Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk) @@ -2628,36 +2645,19 @@ func buildUserCountPreloader() userCountPreloader { return psql.Group(psql.Select(subqueryMods...).Expression) }) }, - CreatorPools: func(mods ...bob.Mod[*dialect.SelectQuery]) psql.Preloader { - return countPreloader[*User]("CreatorPools", func(parent string) bob.Expression { - // Build a correlated subquery: (SELECT COUNT(*) FROM related WHERE fk = parent.pk) - if parent == "" { - parent = Users.Alias() - } - - subqueryMods := []bob.Mod[*dialect.SelectQuery]{ - sm.Columns(psql.Raw("count(*)")), - - sm.From(Pools.Name()), - sm.Where(psql.Quote(Pools.Alias(), "creator_id").EQ(psql.Quote(parent, "id"))), - } - subqueryMods = append(subqueryMods, mods...) - return psql.Group(psql.Select(subqueryMods...).Expression) - }) - }, } } type userCountThenLoader[Q orm.Loadable] struct { PublicUserUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] CreatorFiles func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] + CreatorPools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] CreatorNoteAudios func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] DeletorNoteAudios func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] CreatorNoteImages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] DeletorNoteImages func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] UserNotifications func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] UserOauthTokens func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] - CreatorPools func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q] } func buildUserCountThenLoader[Q orm.Loadable]() userCountThenLoader[Q] { @@ -2667,6 +2667,9 @@ func buildUserCountThenLoader[Q orm.Loadable]() userCountThenLoader[Q] { type CreatorFilesCountInterface interface { LoadCountCreatorFiles(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } + type CreatorPoolsCountInterface interface { + LoadCountCreatorPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error + } type CreatorNoteAudiosCountInterface interface { LoadCountCreatorNoteAudios(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } @@ -2685,9 +2688,6 @@ func buildUserCountThenLoader[Q orm.Loadable]() userCountThenLoader[Q] { type UserOauthTokensCountInterface interface { LoadCountUserOauthTokens(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error } - type CreatorPoolsCountInterface interface { - LoadCountCreatorPools(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error - } return userCountThenLoader[Q]{ PublicUserUser: countThenLoadBuilder[Q]( @@ -2702,6 +2702,12 @@ func buildUserCountThenLoader[Q orm.Loadable]() userCountThenLoader[Q] { return retrieved.LoadCountCreatorFiles(ctx, exec, mods...) }, ), + CreatorPools: countThenLoadBuilder[Q]( + "CreatorPools", + func(ctx context.Context, exec bob.Executor, retrieved CreatorPoolsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { + return retrieved.LoadCountCreatorPools(ctx, exec, mods...) + }, + ), CreatorNoteAudios: countThenLoadBuilder[Q]( "CreatorNoteAudios", func(ctx context.Context, exec bob.Executor, retrieved CreatorNoteAudiosCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { @@ -2738,12 +2744,6 @@ func buildUserCountThenLoader[Q orm.Loadable]() userCountThenLoader[Q] { return retrieved.LoadCountUserOauthTokens(ctx, exec, mods...) }, ), - CreatorPools: countThenLoadBuilder[Q]( - "CreatorPools", - func(ctx context.Context, exec bob.Executor, retrieved CreatorPoolsCountInterface, mods ...bob.Mod[*dialect.SelectQuery]) error { - return retrieved.LoadCountCreatorPools(ctx, exec, mods...) - }, - ), } } @@ -2807,6 +2807,36 @@ func (os UserSlice) LoadCountCreatorFiles(ctx context.Context, exec bob.Executor return nil } +// LoadCountCreatorPools loads the count of CreatorPools into the C struct +func (o *User) LoadCountCreatorPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if o == nil { + return nil + } + + count, err := o.CreatorPools(mods...).Count(ctx, exec) + if err != nil { + return err + } + + o.C.CreatorPools = &count + return nil +} + +// LoadCountCreatorPools loads the count of CreatorPools for a slice +func (os UserSlice) LoadCountCreatorPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { + if len(os) == 0 { + return nil + } + + for _, o := range os { + if err := o.LoadCountCreatorPools(ctx, exec, mods...); err != nil { + return err + } + } + + return nil +} + // LoadCountCreatorNoteAudios loads the count of CreatorNoteAudios into the C struct func (o *User) LoadCountCreatorNoteAudios(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { if o == nil { @@ -2987,47 +3017,17 @@ func (os UserSlice) LoadCountUserOauthTokens(ctx context.Context, exec bob.Execu return nil } -// LoadCountCreatorPools loads the count of CreatorPools into the C struct -func (o *User) LoadCountCreatorPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if o == nil { - return nil - } - - count, err := o.CreatorPools(mods...).Count(ctx, exec) - if err != nil { - return err - } - - o.C.CreatorPools = &count - return nil -} - -// LoadCountCreatorPools loads the count of CreatorPools for a slice -func (os UserSlice) LoadCountCreatorPools(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error { - if len(os) == 0 { - return nil - } - - for _, o := range os { - if err := o.LoadCountCreatorPools(ctx, exec, mods...); err != nil { - return err - } - } - - return nil -} - type userJoins[Q dialect.Joinable] struct { typ string PublicUserUser modAs[Q, arcgisuserColumns] CreatorFiles modAs[Q, fileuploadFileColumns] + CreatorPools modAs[Q, fileuploadPoolColumns] CreatorNoteAudios modAs[Q, noteAudioColumns] DeletorNoteAudios modAs[Q, noteAudioColumns] CreatorNoteImages modAs[Q, noteImageColumns] DeletorNoteImages modAs[Q, noteImageColumns] UserNotifications modAs[Q, notificationColumns] UserOauthTokens modAs[Q, oauthTokenColumns] - CreatorPools modAs[Q, poolColumns] Organization modAs[Q, organizationColumns] } @@ -3066,6 +3066,20 @@ func buildUserJoins[Q dialect.Joinable](cols userColumns, typ string) userJoins[ return mods }, }, + CreatorPools: modAs[Q, fileuploadPoolColumns]{ + c: FileuploadPools.Columns, + f: func(to fileuploadPoolColumns) bob.Mod[Q] { + mods := make(mods.QueryMods[Q], 0, 1) + + { + mods = append(mods, dialect.Join[Q](typ, FileuploadPools.Name().As(to.Alias())).On( + to.CreatorID.EQ(cols.ID), + )) + } + + return mods + }, + }, CreatorNoteAudios: modAs[Q, noteAudioColumns]{ c: NoteAudios.Columns, f: func(to noteAudioColumns) bob.Mod[Q] { @@ -3150,20 +3164,6 @@ func buildUserJoins[Q dialect.Joinable](cols userColumns, typ string) userJoins[ return mods }, }, - CreatorPools: modAs[Q, poolColumns]{ - c: Pools.Columns, - f: func(to poolColumns) bob.Mod[Q] { - mods := make(mods.QueryMods[Q], 0, 1) - - { - mods = append(mods, dialect.Join[Q](typ, Pools.Name().As(to.Alias())).On( - to.CreatorID.EQ(cols.ID), - )) - } - - return mods - }, - }, Organization: modAs[Q, organizationColumns]{ c: Organizations.Columns, f: func(to organizationColumns) bob.Mod[Q] { diff --git a/platform/csv/pool.go b/platform/csv/pool.go index 597d8904..199e8911 100644 --- a/platform/csv/pool.go +++ b/platform/csv/pool.go @@ -100,17 +100,22 @@ func ProcessJob(ctx context.Context, file_id int32) error { } return fmt.Errorf("Failed to read all CSV records for file %d: %w", file_id, err) } - setter := models.PoolSetter{ + setter := models.FileuploadPoolSetter{ // required fields //AddressCity: omit.From(), //AddressPostalCode: omit.From(), //AddressStreet: omit.From(), + Committed: omit.From(false), + Condition: omit.From(enums.FileuploadPoolconditiontypeUnknown), Created: omit.From(time.Now()), CreatorID: omit.From(file.CreatorID), - Committed: omit.From(false), - Condition: omit.From(enums.PoolconditiontypeUnknown), + CSVFile: omit.From(file.ID), Deleted: omitnull.FromPtr[time.Time](nil), + Geom: omitnull.FromPtr[string](nil), + H3cell: omitnull.FromPtr[string](nil), // ID - generated + IsInDistrict: omit.From(false), + IsNew: omit.From(false), Notes: omit.From(""), OrganizationID: omit.From(file.OrganizationID), PropertyOwnerName: omit.From(""), @@ -129,7 +134,7 @@ func ProcessJob(ctx context.Context, file_id int32) error { case headerAddressStreet: setter.AddressStreet = omit.From(col) case headerCondition: - var condition enums.Poolconditiontype + var condition enums.FileuploadPoolconditiontype err := condition.Scan(strings.ToLower(col)) if err != nil { addError(ctx, txn, c, int32(row_number), int32(i), fmt.Sprintf("'%s' is not a pool condition that we recognize. It should be one of %s", poolConditionValidValues())) @@ -153,7 +158,7 @@ func ProcessJob(ctx context.Context, file_id int32) error { setter.ResidentPhone = omitnull.From(col) } } - _, err = models.Pools.Insert(&setter).Exec(ctx, txn) + _, err = models.FileuploadPools.Insert(&setter).Exec(ctx, txn) if err != nil { return fmt.Errorf("Failed to create pool: %w", err) } @@ -260,7 +265,7 @@ func missingRequiredHeaders(headers []headerPoolEnum) []headerPoolEnum { } func poolConditionValidValues() string { var b strings.Builder - for i, cond := range enums.AllPoolconditiontype() { + for i, cond := range enums.AllFileuploadPoolconditiontype() { if i == 0 { fmt.Fprintf(&b, "'%s'", cond) } else { diff --git a/platform/pool.go b/platform/pool.go index 8e4b78d8..84020c84 100644 --- a/platform/pool.go +++ b/platform/pool.go @@ -19,6 +19,16 @@ import ( "github.com/stephenafamo/scan" ) +type PoolDetail struct { + Created time.Time `db:"created"` + ID int32 `db:"id"` + Pools []PoolRow + Status string `db:"status"` +} +type PoolRow struct { + Street string + City string +} type PoolUpload struct { Created time.Time `db:"created"` ID int32 `db:"id"` @@ -62,6 +72,35 @@ func NewPoolUpload(ctx context.Context, u *models.User, upload userfile.FileUplo ID: file.ID, }, nil } +func GetPoolDetail(ctx context.Context, organization_id int32, file_id int32) (PoolDetail, error) { + file, err := models.FindFileuploadFile(ctx, db.PGInstance.BobDB, file_id) + if err != nil { + return PoolDetail{}, fmt.Errorf("Failed to lookup file %d: %w", file_id, err) + } + /* + csv, err := models.FindFileuploadCSV(ctx, db.PGInstance.BobDB, file_id) + if err != nil { + return PoolDetail{}, fmt.Errorf("Failed to lookup csv %d: %w", file_id, err) + } + */ + rows, err := models.FileuploadPools.Query( + models.SelectWhere.FileuploadPools.CSVFile.EQ(file_id), + ).All(ctx, db.PGInstance.BobDB) + if err != nil { + return PoolDetail{}, fmt.Errorf("Failed to query pools for %d: %w", file_id, err) + } + pools := make([]PoolRow, 0) + for _, r := range rows { + pools = append(pools, PoolRow{ + Street: r.AddressStreet, + City: r.AddressCity, + }) + } + return PoolDetail{ + Pools: pools, + Status: file.Status.String(), + }, nil +} func PoolUploadList(ctx context.Context, organization_id int32) ([]PoolUpload, error) { results := make([]PoolUpload, 0) rows, err := bob.All(ctx, db.PGInstance.BobDB, psql.Select( diff --git a/sync/pool.go b/sync/pool.go index a4028272..09a1e966 100644 --- a/sync/pool.go +++ b/sync/pool.go @@ -3,13 +3,20 @@ package sync import ( "fmt" "net/http" + "strconv" "github.com/Gleipnir-Technology/nidus-sync/db/models" "github.com/Gleipnir-Technology/nidus-sync/html" "github.com/Gleipnir-Technology/nidus-sync/platform" "github.com/Gleipnir-Technology/nidus-sync/userfile" + "github.com/go-chi/chi/v5" ) +type ContentPoolDetail struct { + Pool platform.PoolDetail + URL ContentURL + User User +} type ContentPoolList struct { Uploads []platform.PoolUpload URL ContentURL @@ -58,7 +65,20 @@ func getPoolUploadByID(w http.ResponseWriter, r *http.Request, u *models.User) { respondError(w, "Failed to get user", err, http.StatusInternalServerError) return } - data := ContentPoolUpload{ + ctx := r.Context() + file_id_str := chi.URLParam(r, "id") + file_id, err := strconv.ParseInt(file_id_str, 10, 32) + if err != nil { + respondError(w, "Failed to parse file_id", err, http.StatusInternalServerError) + return + } + detail, err := platform.GetPoolDetail(ctx, u.OrganizationID, int32(file_id)) + if err != nil { + respondError(w, "Failed to get pool", err, http.StatusInternalServerError) + return + } + data := ContentPoolDetail{ + Pool: detail, URL: newContentURL(), User: userContent, }