Add mode data to pool upload rows, move to fileupload schema

This allows users to review the data before committing it to the
database
This commit is contained in:
Eli Ribble 2026-02-09 19:03:27 +00:00
parent 135ad2b73e
commit d06b8f7949
No known key found for this signature in database
23 changed files with 4285 additions and 3182 deletions

View file

@ -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
}

View file

@ -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{}
}

View file

@ -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"

View file

@ -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")
)

View file

@ -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
}

View file

@ -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

View file

@ -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
})
}

File diff suppressed because it is too large Load diff

View file

@ -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{{

File diff suppressed because it is too large Load diff

View file

@ -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
})
}

View file

@ -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;

View file

@ -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),

View file

@ -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](),

View file

@ -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),

View file

@ -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
},
},

File diff suppressed because it is too large Load diff

View file

@ -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] {

File diff suppressed because it is too large Load diff

View file

@ -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] {

View file

@ -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 {

View file

@ -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(

View file

@ -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,
}