Add new view for report counts and invalidated status
Also drop site.version from the primary key.
This commit is contained in:
parent
9525363bc8
commit
32dcc50c94
23 changed files with 1656 additions and 623 deletions
|
|
@ -1,45 +0,0 @@
|
|||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/notification"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/platform"
|
||||
)
|
||||
|
||||
func ContentForUser(ctx context.Context, user *models.User) (platform.User, error) {
|
||||
notifications, err := notification.ForUser(ctx, user)
|
||||
if err != nil {
|
||||
return platform.User{}, err
|
||||
}
|
||||
org := user.R.Organization
|
||||
var organization platform.Organization
|
||||
if org != nil {
|
||||
organization.ID = int32(org.ID)
|
||||
organization.Name = org.Name
|
||||
}
|
||||
return platform.User{
|
||||
DisplayName: user.DisplayName,
|
||||
Initials: extractInitials(user.DisplayName),
|
||||
Notifications: notifications,
|
||||
Organization: organization,
|
||||
Role: user.Role.String(),
|
||||
Username: user.Username,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
||||
func extractInitials(name string) string {
|
||||
parts := strings.Fields(name)
|
||||
var initials strings.Builder
|
||||
|
||||
for _, part := range parts {
|
||||
if len(part) > 0 {
|
||||
initials.WriteString(strings.ToUpper(string(part[0])))
|
||||
}
|
||||
}
|
||||
|
||||
return initials.String()
|
||||
}
|
||||
|
|
@ -7,7 +7,7 @@ var SiteErrors = &siteErrors{
|
|||
ErrUniqueSitePkey: &UniqueConstraintError{
|
||||
schema: "",
|
||||
table: "site",
|
||||
columns: []string{"id", "version"},
|
||||
columns: []string{"id"},
|
||||
s: "site_pkey",
|
||||
},
|
||||
|
||||
|
|
@ -17,10 +17,19 @@ var SiteErrors = &siteErrors{
|
|||
columns: []string{"address_id"},
|
||||
s: "site_address_id_key",
|
||||
},
|
||||
|
||||
ErrUniqueSiteIdVersionUnique: &UniqueConstraintError{
|
||||
schema: "",
|
||||
table: "site",
|
||||
columns: []string{"id", "version"},
|
||||
s: "site_id_version_unique",
|
||||
},
|
||||
}
|
||||
|
||||
type siteErrors struct {
|
||||
ErrUniqueSitePkey *UniqueConstraintError
|
||||
|
||||
ErrUniqueSiteAddressIdKey *UniqueConstraintError
|
||||
|
||||
ErrUniqueSiteIdVersionUnique *UniqueConstraintError
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,15 +60,6 @@ var Features = Table[
|
|||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
SiteVersion: column{
|
||||
Name: "site_version",
|
||||
DBType: "integer",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
Location: column{
|
||||
Name: "location",
|
||||
DBType: "geometry",
|
||||
|
|
@ -122,14 +113,14 @@ var Features = Table[
|
|||
ForeignTable: "organization",
|
||||
ForeignColumns: []string{"id"},
|
||||
},
|
||||
FeatureFeatureSiteIDSiteVersionFkey: foreignKey{
|
||||
FeatureFeatureSiteIDFkey: foreignKey{
|
||||
constraint: constraint{
|
||||
Name: "feature.feature_site_id_site_version_fkey",
|
||||
Columns: []string{"site_id", "site_version"},
|
||||
Name: "feature.feature_site_id_fkey",
|
||||
Columns: []string{"site_id"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignTable: "site",
|
||||
ForeignColumns: []string{"id", "version"},
|
||||
ForeignColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -142,13 +133,12 @@ type featureColumns struct {
|
|||
ID column
|
||||
OrganizationID column
|
||||
SiteID column
|
||||
SiteVersion column
|
||||
Location column
|
||||
}
|
||||
|
||||
func (c featureColumns) AsSlice() []column {
|
||||
return []column{
|
||||
c.Created, c.CreatorID, c.ID, c.OrganizationID, c.SiteID, c.SiteVersion, c.Location,
|
||||
c.Created, c.CreatorID, c.ID, c.OrganizationID, c.SiteID, c.Location,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -165,12 +155,12 @@ func (i featureIndexes) AsSlice() []index {
|
|||
type featureForeignKeys struct {
|
||||
FeatureFeatureCreatorIDFkey foreignKey
|
||||
FeatureFeatureOrganizationIDFkey foreignKey
|
||||
FeatureFeatureSiteIDSiteVersionFkey foreignKey
|
||||
FeatureFeatureSiteIDFkey foreignKey
|
||||
}
|
||||
|
||||
func (f featureForeignKeys) AsSlice() []foreignKey {
|
||||
return []foreignKey{
|
||||
f.FeatureFeatureCreatorIDFkey, f.FeatureFeatureOrganizationIDFkey, f.FeatureFeatureSiteIDSiteVersionFkey,
|
||||
f.FeatureFeatureCreatorIDFkey, f.FeatureFeatureOrganizationIDFkey, f.FeatureFeatureSiteIDFkey,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -60,15 +60,6 @@ var Leads = Table[
|
|||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
SiteVersion: column{
|
||||
Name: "site_version",
|
||||
DBType: "integer",
|
||||
Default: "NULL",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
Type: column{
|
||||
Name: "type_",
|
||||
DBType: "public.leadtype",
|
||||
|
|
@ -122,14 +113,14 @@ var Leads = Table[
|
|||
ForeignTable: "organization",
|
||||
ForeignColumns: []string{"id"},
|
||||
},
|
||||
LeadLeadSiteIDSiteVersionFkey: foreignKey{
|
||||
LeadLeadSiteIDFkey: foreignKey{
|
||||
constraint: constraint{
|
||||
Name: "lead.lead_site_id_site_version_fkey",
|
||||
Columns: []string{"site_id", "site_version"},
|
||||
Name: "lead.lead_site_id_fkey",
|
||||
Columns: []string{"site_id"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignTable: "site",
|
||||
ForeignColumns: []string{"id", "version"},
|
||||
ForeignColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -142,13 +133,12 @@ type leadColumns struct {
|
|||
ID column
|
||||
OrganizationID column
|
||||
SiteID column
|
||||
SiteVersion column
|
||||
Type column
|
||||
}
|
||||
|
||||
func (c leadColumns) AsSlice() []column {
|
||||
return []column{
|
||||
c.Created, c.Creator, c.ID, c.OrganizationID, c.SiteID, c.SiteVersion, c.Type,
|
||||
c.Created, c.Creator, c.ID, c.OrganizationID, c.SiteID, c.Type,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -165,12 +155,12 @@ func (i leadIndexes) AsSlice() []index {
|
|||
type leadForeignKeys struct {
|
||||
LeadLeadCreatorFkey foreignKey
|
||||
LeadLeadOrganizationIDFkey foreignKey
|
||||
LeadLeadSiteIDSiteVersionFkey foreignKey
|
||||
LeadLeadSiteIDFkey foreignKey
|
||||
}
|
||||
|
||||
func (f leadForeignKeys) AsSlice() []foreignKey {
|
||||
return []foreignKey{
|
||||
f.LeadLeadCreatorFkey, f.LeadLeadOrganizationIDFkey, f.LeadLeadSiteIDSiteVersionFkey,
|
||||
f.LeadLeadCreatorFkey, f.LeadLeadOrganizationIDFkey, f.LeadLeadSiteIDFkey,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -348,6 +348,24 @@ var PublicreportNuisances = Table[
|
|||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
Reviewed: column{
|
||||
Name: "reviewed",
|
||||
DBType: "timestamp without time zone",
|
||||
Default: "NULL",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
ReviewerID: column{
|
||||
Name: "reviewer_id",
|
||||
DBType: "integer",
|
||||
Default: "NULL",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
},
|
||||
Indexes: publicreportNuisanceIndexes{
|
||||
NuisancePkey: index{
|
||||
|
|
@ -409,6 +427,15 @@ var PublicreportNuisances = Table[
|
|||
ForeignTable: "organization",
|
||||
ForeignColumns: []string{"id"},
|
||||
},
|
||||
PublicreportNuisanceNuisanceReviewerIDFkey: foreignKey{
|
||||
constraint: constraint{
|
||||
Name: "publicreport.nuisance.nuisance_reviewer_id_fkey",
|
||||
Columns: []string{"reviewer_id"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignTable: "user_",
|
||||
ForeignColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
Uniques: publicreportNuisanceUniques{
|
||||
NuisancePublicIDKey: constraint{
|
||||
|
|
@ -459,11 +486,13 @@ type publicreportNuisanceColumns struct {
|
|||
Location column
|
||||
AddressNumber column
|
||||
AddressID column
|
||||
Reviewed column
|
||||
ReviewerID column
|
||||
}
|
||||
|
||||
func (c publicreportNuisanceColumns) AsSlice() []column {
|
||||
return []column{
|
||||
c.ID, c.AdditionalInfo, c.Created, c.Duration, c.SourceContainer, c.SourceDescription, c.SourceStagnant, c.PublicID, c.ReporterEmail, c.ReporterName, c.ReporterPhone, c.AddressRaw, c.Status, c.OrganizationID, c.SourceGutter, c.H3cell, c.AddressCountry, c.AddressLocality, c.AddressPostalCode, c.AddressRegion, c.AddressStreet, c.IsLocationBackyard, c.IsLocationFrontyard, c.IsLocationGarden, c.IsLocationOther, c.IsLocationPool, c.MapZoom, c.TodEarly, c.TodDay, c.TodEvening, c.TodNight, c.LatlngAccuracyType, c.LatlngAccuracyValue, c.ReporterContactConsent, c.Location, c.AddressNumber, c.AddressID,
|
||||
c.ID, c.AdditionalInfo, c.Created, c.Duration, c.SourceContainer, c.SourceDescription, c.SourceStagnant, c.PublicID, c.ReporterEmail, c.ReporterName, c.ReporterPhone, c.AddressRaw, c.Status, c.OrganizationID, c.SourceGutter, c.H3cell, c.AddressCountry, c.AddressLocality, c.AddressPostalCode, c.AddressRegion, c.AddressStreet, c.IsLocationBackyard, c.IsLocationFrontyard, c.IsLocationGarden, c.IsLocationOther, c.IsLocationPool, c.MapZoom, c.TodEarly, c.TodDay, c.TodEvening, c.TodNight, c.LatlngAccuracyType, c.LatlngAccuracyValue, c.ReporterContactConsent, c.Location, c.AddressNumber, c.AddressID, c.Reviewed, c.ReviewerID,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -481,11 +510,12 @@ func (i publicreportNuisanceIndexes) AsSlice() []index {
|
|||
type publicreportNuisanceForeignKeys struct {
|
||||
PublicreportNuisanceNuisanceAddressIDFkey foreignKey
|
||||
PublicreportNuisanceNuisanceOrganizationIDFkey foreignKey
|
||||
PublicreportNuisanceNuisanceReviewerIDFkey foreignKey
|
||||
}
|
||||
|
||||
func (f publicreportNuisanceForeignKeys) AsSlice() []foreignKey {
|
||||
return []foreignKey{
|
||||
f.PublicreportNuisanceNuisanceAddressIDFkey, f.PublicreportNuisanceNuisanceOrganizationIDFkey,
|
||||
f.PublicreportNuisanceNuisanceAddressIDFkey, f.PublicreportNuisanceNuisanceOrganizationIDFkey, f.PublicreportNuisanceNuisanceReviewerIDFkey,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
162
db/dbinfo/publicreport.organization_report_count.bob.go
Normal file
162
db/dbinfo/publicreport.organization_report_count.bob.go
Normal file
|
|
@ -0,0 +1,162 @@
|
|||
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package dbinfo
|
||||
|
||||
var PublicreportOrganizationReportCounts = Table[
|
||||
publicreportOrganizationReportCountColumns,
|
||||
publicreportOrganizationReportCountIndexes,
|
||||
publicreportOrganizationReportCountForeignKeys,
|
||||
publicreportOrganizationReportCountUniques,
|
||||
publicreportOrganizationReportCountChecks,
|
||||
]{
|
||||
Schema: "publicreport",
|
||||
Name: "organization_report_count",
|
||||
Columns: publicreportOrganizationReportCountColumns{
|
||||
OrganizationID: column{
|
||||
Name: "organization_id",
|
||||
DBType: "integer",
|
||||
Default: "NULL",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
NuisanceReported: column{
|
||||
Name: "nuisance_reported",
|
||||
DBType: "bigint",
|
||||
Default: "NULL",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
NuisanceReviewed: column{
|
||||
Name: "nuisance_reviewed",
|
||||
DBType: "bigint",
|
||||
Default: "NULL",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
NuisanceScheduled: column{
|
||||
Name: "nuisance_scheduled",
|
||||
DBType: "bigint",
|
||||
Default: "NULL",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
NuisanceTreated: column{
|
||||
Name: "nuisance_treated",
|
||||
DBType: "bigint",
|
||||
Default: "NULL",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
NuisanceInvalidated: column{
|
||||
Name: "nuisance_invalidated",
|
||||
DBType: "bigint",
|
||||
Default: "NULL",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
WaterReported: column{
|
||||
Name: "water_reported",
|
||||
DBType: "bigint",
|
||||
Default: "NULL",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
WaterReviewed: column{
|
||||
Name: "water_reviewed",
|
||||
DBType: "bigint",
|
||||
Default: "NULL",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
WaterScheduled: column{
|
||||
Name: "water_scheduled",
|
||||
DBType: "bigint",
|
||||
Default: "NULL",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
WaterTreated: column{
|
||||
Name: "water_treated",
|
||||
DBType: "bigint",
|
||||
Default: "NULL",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
WaterInvalidated: column{
|
||||
Name: "water_invalidated",
|
||||
DBType: "bigint",
|
||||
Default: "NULL",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
},
|
||||
|
||||
Comment: "",
|
||||
}
|
||||
|
||||
type publicreportOrganizationReportCountColumns struct {
|
||||
OrganizationID column
|
||||
NuisanceReported column
|
||||
NuisanceReviewed column
|
||||
NuisanceScheduled column
|
||||
NuisanceTreated column
|
||||
NuisanceInvalidated column
|
||||
WaterReported column
|
||||
WaterReviewed column
|
||||
WaterScheduled column
|
||||
WaterTreated column
|
||||
WaterInvalidated column
|
||||
}
|
||||
|
||||
func (c publicreportOrganizationReportCountColumns) AsSlice() []column {
|
||||
return []column{
|
||||
c.OrganizationID, c.NuisanceReported, c.NuisanceReviewed, c.NuisanceScheduled, c.NuisanceTreated, c.NuisanceInvalidated, c.WaterReported, c.WaterReviewed, c.WaterScheduled, c.WaterTreated, c.WaterInvalidated,
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportOrganizationReportCountIndexes struct{}
|
||||
|
||||
func (i publicreportOrganizationReportCountIndexes) AsSlice() []index {
|
||||
return []index{}
|
||||
}
|
||||
|
||||
type publicreportOrganizationReportCountForeignKeys struct{}
|
||||
|
||||
func (f publicreportOrganizationReportCountForeignKeys) AsSlice() []foreignKey {
|
||||
return []foreignKey{}
|
||||
}
|
||||
|
||||
type publicreportOrganizationReportCountUniques struct{}
|
||||
|
||||
func (u publicreportOrganizationReportCountUniques) AsSlice() []constraint {
|
||||
return []constraint{}
|
||||
}
|
||||
|
||||
type publicreportOrganizationReportCountChecks struct{}
|
||||
|
||||
func (c publicreportOrganizationReportCountChecks) AsSlice() []check {
|
||||
return []check{}
|
||||
}
|
||||
|
|
@ -339,6 +339,24 @@ var PublicreportWaters = Table[
|
|||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
Reviewed: column{
|
||||
Name: "reviewed",
|
||||
DBType: "timestamp without time zone",
|
||||
Default: "NULL",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
ReviewerID: column{
|
||||
Name: "reviewer_id",
|
||||
DBType: "integer",
|
||||
Default: "NULL",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
},
|
||||
Indexes: publicreportWaterIndexes{
|
||||
PoolPkey: index{
|
||||
|
|
@ -400,6 +418,15 @@ var PublicreportWaters = Table[
|
|||
ForeignTable: "organization",
|
||||
ForeignColumns: []string{"id"},
|
||||
},
|
||||
PublicreportWaterWaterReviewerIDFkey: foreignKey{
|
||||
constraint: constraint{
|
||||
Name: "publicreport.water.water_reviewer_id_fkey",
|
||||
Columns: []string{"reviewer_id"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignTable: "user_",
|
||||
ForeignColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
Uniques: publicreportWaterUniques{
|
||||
PoolPublicIDKey: constraint{
|
||||
|
|
@ -449,11 +476,13 @@ type publicreportWaterColumns struct {
|
|||
Location column
|
||||
AddressNumber column
|
||||
AddressID column
|
||||
Reviewed column
|
||||
ReviewerID column
|
||||
}
|
||||
|
||||
func (c publicreportWaterColumns) AsSlice() []column {
|
||||
return []column{
|
||||
c.ID, c.AccessComments, c.AccessGate, c.AccessFence, c.AccessLocked, c.AccessDog, c.AccessOther, c.AddressRaw, c.AddressCountry, c.AddressPostalCode, c.AddressLocality, c.AddressStreet, c.AddressRegion, c.Comments, c.Created, c.H3cell, c.HasAdult, c.HasLarvae, c.HasPupae, c.MapZoom, c.OwnerEmail, c.OwnerName, c.OwnerPhone, c.PublicID, c.ReporterEmail, c.ReporterName, c.ReporterPhone, c.Status, c.OrganizationID, c.HasBackyardPermission, c.IsReporterConfidential, c.IsReporterOwner, c.ReporterContactConsent, c.Location, c.AddressNumber, c.AddressID,
|
||||
c.ID, c.AccessComments, c.AccessGate, c.AccessFence, c.AccessLocked, c.AccessDog, c.AccessOther, c.AddressRaw, c.AddressCountry, c.AddressPostalCode, c.AddressLocality, c.AddressStreet, c.AddressRegion, c.Comments, c.Created, c.H3cell, c.HasAdult, c.HasLarvae, c.HasPupae, c.MapZoom, c.OwnerEmail, c.OwnerName, c.OwnerPhone, c.PublicID, c.ReporterEmail, c.ReporterName, c.ReporterPhone, c.Status, c.OrganizationID, c.HasBackyardPermission, c.IsReporterConfidential, c.IsReporterOwner, c.ReporterContactConsent, c.Location, c.AddressNumber, c.AddressID, c.Reviewed, c.ReviewerID,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -471,11 +500,12 @@ func (i publicreportWaterIndexes) AsSlice() []index {
|
|||
type publicreportWaterForeignKeys struct {
|
||||
PublicreportWaterPoolAddressIDFkey foreignKey
|
||||
PublicreportWaterPoolOrganizationIDFkey foreignKey
|
||||
PublicreportWaterWaterReviewerIDFkey foreignKey
|
||||
}
|
||||
|
||||
func (f publicreportWaterForeignKeys) AsSlice() []foreignKey {
|
||||
return []foreignKey{
|
||||
f.PublicreportWaterPoolAddressIDFkey, f.PublicreportWaterPoolOrganizationIDFkey,
|
||||
f.PublicreportWaterPoolAddressIDFkey, f.PublicreportWaterPoolOrganizationIDFkey, f.PublicreportWaterWaterReviewerIDFkey,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -78,15 +78,6 @@ var Residents = Table[
|
|||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
SiteVersion: column{
|
||||
Name: "site_version",
|
||||
DBType: "integer",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
},
|
||||
Indexes: residentIndexes{
|
||||
ResidentPkey: index{
|
||||
|
|
@ -140,14 +131,14 @@ var Residents = Table[
|
|||
ForeignTable: "comms.phone",
|
||||
ForeignColumns: []string{"e164"},
|
||||
},
|
||||
ResidentResidentSiteIDSiteVersionFkey: foreignKey{
|
||||
ResidentResidentSiteIDFkey: foreignKey{
|
||||
constraint: constraint{
|
||||
Name: "resident.resident_site_id_site_version_fkey",
|
||||
Columns: []string{"site_id", "site_version"},
|
||||
Name: "resident.resident_site_id_fkey",
|
||||
Columns: []string{"site_id"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignTable: "site",
|
||||
ForeignColumns: []string{"id", "version"},
|
||||
ForeignColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -162,12 +153,11 @@ type residentColumns struct {
|
|||
Name column
|
||||
PhoneMobile column
|
||||
SiteID column
|
||||
SiteVersion column
|
||||
}
|
||||
|
||||
func (c residentColumns) AsSlice() []column {
|
||||
return []column{
|
||||
c.AddressID, c.Created, c.Creator, c.ID, c.Name, c.PhoneMobile, c.SiteID, c.SiteVersion,
|
||||
c.AddressID, c.Created, c.Creator, c.ID, c.Name, c.PhoneMobile, c.SiteID,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -185,12 +175,12 @@ type residentForeignKeys struct {
|
|||
ResidentResidentAddressIDFkey foreignKey
|
||||
ResidentResidentCreatorFkey foreignKey
|
||||
ResidentResidentPhoneMobileFkey foreignKey
|
||||
ResidentResidentSiteIDSiteVersionFkey foreignKey
|
||||
ResidentResidentSiteIDFkey foreignKey
|
||||
}
|
||||
|
||||
func (f residentForeignKeys) AsSlice() []foreignKey {
|
||||
return []foreignKey{
|
||||
f.ResidentResidentAddressIDFkey, f.ResidentResidentCreatorFkey, f.ResidentResidentPhoneMobileFkey, f.ResidentResidentSiteIDSiteVersionFkey,
|
||||
f.ResidentResidentAddressIDFkey, f.ResidentResidentCreatorFkey, f.ResidentResidentPhoneMobileFkey, f.ResidentResidentSiteIDFkey,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -143,15 +143,10 @@ var Sites = Table[
|
|||
Desc: null.FromCond(false, true),
|
||||
IsExpression: false,
|
||||
},
|
||||
{
|
||||
Name: "version",
|
||||
Desc: null.FromCond(false, true),
|
||||
IsExpression: false,
|
||||
},
|
||||
},
|
||||
Unique: true,
|
||||
Comment: "",
|
||||
NullsFirst: []bool{false, false},
|
||||
NullsFirst: []bool{false},
|
||||
NullsDistinct: false,
|
||||
Where: "",
|
||||
Include: []string{},
|
||||
|
|
@ -173,10 +168,32 @@ var Sites = Table[
|
|||
Where: "",
|
||||
Include: []string{},
|
||||
},
|
||||
SiteIDVersionUnique: index{
|
||||
Type: "btree",
|
||||
Name: "site_id_version_unique",
|
||||
Columns: []indexColumn{
|
||||
{
|
||||
Name: "id",
|
||||
Desc: null.FromCond(false, true),
|
||||
IsExpression: false,
|
||||
},
|
||||
{
|
||||
Name: "version",
|
||||
Desc: null.FromCond(false, true),
|
||||
IsExpression: false,
|
||||
},
|
||||
},
|
||||
Unique: true,
|
||||
Comment: "",
|
||||
NullsFirst: []bool{false, false},
|
||||
NullsDistinct: false,
|
||||
Where: "",
|
||||
Include: []string{},
|
||||
},
|
||||
},
|
||||
PrimaryKey: &constraint{
|
||||
Name: "site_pkey",
|
||||
Columns: []string{"id", "version"},
|
||||
Columns: []string{"id"},
|
||||
Comment: "",
|
||||
},
|
||||
ForeignKeys: siteForeignKeys{
|
||||
|
|
@ -223,6 +240,11 @@ var Sites = Table[
|
|||
Columns: []string{"address_id"},
|
||||
Comment: "",
|
||||
},
|
||||
SiteIDVersionUnique: constraint{
|
||||
Name: "site_id_version_unique",
|
||||
Columns: []string{"id", "version"},
|
||||
Comment: "",
|
||||
},
|
||||
},
|
||||
|
||||
Comment: "",
|
||||
|
|
@ -253,11 +275,12 @@ func (c siteColumns) AsSlice() []column {
|
|||
type siteIndexes struct {
|
||||
SitePkey index
|
||||
SiteAddressIDKey index
|
||||
SiteIDVersionUnique index
|
||||
}
|
||||
|
||||
func (i siteIndexes) AsSlice() []index {
|
||||
return []index{
|
||||
i.SitePkey, i.SiteAddressIDKey,
|
||||
i.SitePkey, i.SiteAddressIDKey, i.SiteIDVersionUnique,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -276,11 +299,12 @@ func (f siteForeignKeys) AsSlice() []foreignKey {
|
|||
|
||||
type siteUniques struct {
|
||||
SiteAddressIDKey constraint
|
||||
SiteIDVersionUnique constraint
|
||||
}
|
||||
|
||||
func (u siteUniques) AsSlice() []constraint {
|
||||
return []constraint{
|
||||
u.SiteAddressIDKey,
|
||||
u.SiteAddressIDKey, u.SiteIDVersionUnique,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1872,6 +1872,7 @@ const (
|
|||
PublicreportReportstatustypeReviewed PublicreportReportstatustype = "reviewed"
|
||||
PublicreportReportstatustypeScheduled PublicreportReportstatustype = "scheduled"
|
||||
PublicreportReportstatustypeTreated PublicreportReportstatustype = "treated"
|
||||
PublicreportReportstatustypeInvalidated PublicreportReportstatustype = "invalidated"
|
||||
)
|
||||
|
||||
func AllPublicreportReportstatustype() []PublicreportReportstatustype {
|
||||
|
|
@ -1880,6 +1881,7 @@ func AllPublicreportReportstatustype() []PublicreportReportstatustype {
|
|||
PublicreportReportstatustypeReviewed,
|
||||
PublicreportReportstatustypeScheduled,
|
||||
PublicreportReportstatustypeTreated,
|
||||
PublicreportReportstatustypeInvalidated,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1894,7 +1896,8 @@ func (e PublicreportReportstatustype) Valid() bool {
|
|||
case PublicreportReportstatustypeReported,
|
||||
PublicreportReportstatustypeReviewed,
|
||||
PublicreportReportstatustypeScheduled,
|
||||
PublicreportReportstatustypeTreated:
|
||||
PublicreportReportstatustypeTreated,
|
||||
PublicreportReportstatustypeInvalidated:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
|
|
|
|||
36
db/migrations/00103_site_version.sql
Normal file
36
db/migrations/00103_site_version.sql
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
-- +goose Up
|
||||
-- Step 1: Drop foreign key constraints that reference the composite primary key
|
||||
ALTER TABLE feature DROP CONSTRAINT feature_site_id_site_version_fkey;
|
||||
ALTER TABLE lead DROP CONSTRAINT lead_site_id_site_version_fkey;
|
||||
ALTER TABLE resident DROP CONSTRAINT resident_site_id_site_version_fkey;
|
||||
|
||||
-- Step 2: Drop the existing composite primary key
|
||||
ALTER TABLE site DROP CONSTRAINT site_pkey;
|
||||
|
||||
-- Step 3: Create new primary key on just the id column
|
||||
ALTER TABLE site ADD PRIMARY KEY (id);
|
||||
|
||||
-- Step 4: Create a unique constraint on (id, version) to maintain uniqueness
|
||||
ALTER TABLE site ADD CONSTRAINT site_id_version_unique UNIQUE (id, version);
|
||||
|
||||
-- Step 5: Recreate the foreign key constraints
|
||||
ALTER TABLE feature
|
||||
ADD CONSTRAINT feature_site_id_fkey
|
||||
FOREIGN KEY (site_id)
|
||||
REFERENCES site(id);
|
||||
ALTER TABLE feature
|
||||
DROP COLUMN site_version;
|
||||
|
||||
ALTER TABLE lead
|
||||
ADD CONSTRAINT lead_site_id_fkey
|
||||
FOREIGN KEY (site_id)
|
||||
REFERENCES site(id);
|
||||
ALTER TABLE lead
|
||||
DROP COLUMN site_version;
|
||||
|
||||
ALTER TABLE resident
|
||||
ADD CONSTRAINT resident_site_id_fkey
|
||||
FOREIGN KEY (site_id)
|
||||
REFERENCES site(id);
|
||||
ALTER TABLE resident
|
||||
DROP COLUMN site_version;
|
||||
3
db/migrations/00104_publicreport_status_invalidated.sql
Normal file
3
db/migrations/00104_publicreport_status_invalidated.sql
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
-- +goose Up
|
||||
ALTER TYPE publicreport.ReportStatusType ADD VALUE 'invalidated' AFTER 'treated';
|
||||
-- +goose Down
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
-- +goose Up
|
||||
ALTER TABLE publicreport.nuisance ADD COLUMN reviewed TIMESTAMP WITHOUT TIME ZONE;
|
||||
ALTER TABLE publicreport.nuisance ADD COLUMN reviewer_id INTEGER REFERENCES user_(id);
|
||||
ALTER TABLE publicreport.water ADD COLUMN reviewed TIMESTAMP WITHOUT TIME ZONE;
|
||||
ALTER TABLE publicreport.water ADD COLUMN reviewer_id INTEGER REFERENCES user_(id);
|
||||
|
||||
CREATE VIEW publicreport.organization_report_count AS
|
||||
SELECT
|
||||
o.id AS organization_id,
|
||||
COUNT(n.id) FILTER (WHERE n.status = 'reported') AS nuisance_reported,
|
||||
COUNT(n.id) FILTER (WHERE n.status = 'reviewed') AS nuisance_reviewed,
|
||||
COUNT(n.id) FILTER (WHERE n.status = 'scheduled') AS nuisance_scheduled,
|
||||
COUNT(n.id) FILTER (WHERE n.status = 'treated') AS nuisance_treated,
|
||||
COUNT(n.id) FILTER (WHERE n.status = 'invalidated') AS nuisance_invalidated,
|
||||
COUNT(w.id) FILTER (WHERE w.status = 'reported') AS water_reported,
|
||||
COUNT(w.id) FILTER (WHERE w.status = 'reviewed') AS water_reviewed,
|
||||
COUNT(w.id) FILTER (WHERE w.status = 'scheduled') AS water_scheduled,
|
||||
COUNT(w.id) FILTER (WHERE w.status = 'treated') AS water_treated,
|
||||
COUNT(w.id) FILTER (WHERE w.status = 'invalidated') AS water_invalidated
|
||||
FROM organization o
|
||||
LEFT JOIN publicreport.nuisance n ON o.id = n.organization_id
|
||||
LEFT JOIN publicreport.water w ON o.id = w.organization_id
|
||||
GROUP BY o.id;
|
||||
|
||||
-- +goose Down
|
||||
DROP VIEW publicreport.organization_report_count;
|
||||
ALTER TABLE publicreport.water DROP COLUMN reviewer_id;
|
||||
ALTER TABLE publicreport.water DROP COLUMN reviewed;
|
||||
ALTER TABLE publicreport.nuisance DROP COLUMN reviewer_id;
|
||||
ALTER TABLE publicreport.nuisance DROP COLUMN reviewed;
|
||||
|
|
@ -96,6 +96,7 @@ func Where[Q psql.Filterable]() struct {
|
|||
PublicreportNotifyPhoneWaters publicreportNotifyPhoneWaterWhere[Q]
|
||||
PublicreportNuisances publicreportNuisanceWhere[Q]
|
||||
PublicreportNuisanceImages publicreportNuisanceImageWhere[Q]
|
||||
PublicreportOrganizationReportCounts publicreportOrganizationReportCountWhere[Q]
|
||||
PublicreportReportLocations publicreportReportLocationWhere[Q]
|
||||
PublicreportSubscribeEmails publicreportSubscribeEmailWhere[Q]
|
||||
PublicreportSubscribePhones publicreportSubscribePhoneWhere[Q]
|
||||
|
|
@ -193,6 +194,7 @@ func Where[Q psql.Filterable]() struct {
|
|||
PublicreportNotifyPhoneWaters publicreportNotifyPhoneWaterWhere[Q]
|
||||
PublicreportNuisances publicreportNuisanceWhere[Q]
|
||||
PublicreportNuisanceImages publicreportNuisanceImageWhere[Q]
|
||||
PublicreportOrganizationReportCounts publicreportOrganizationReportCountWhere[Q]
|
||||
PublicreportReportLocations publicreportReportLocationWhere[Q]
|
||||
PublicreportSubscribeEmails publicreportSubscribeEmailWhere[Q]
|
||||
PublicreportSubscribePhones publicreportSubscribePhoneWhere[Q]
|
||||
|
|
@ -289,6 +291,7 @@ func Where[Q psql.Filterable]() struct {
|
|||
PublicreportNotifyPhoneWaters: buildPublicreportNotifyPhoneWaterWhere[Q](PublicreportNotifyPhoneWaters.Columns),
|
||||
PublicreportNuisances: buildPublicreportNuisanceWhere[Q](PublicreportNuisances.Columns),
|
||||
PublicreportNuisanceImages: buildPublicreportNuisanceImageWhere[Q](PublicreportNuisanceImages.Columns),
|
||||
PublicreportOrganizationReportCounts: buildPublicreportOrganizationReportCountWhere[Q](PublicreportOrganizationReportCounts.Columns),
|
||||
PublicreportReportLocations: buildPublicreportReportLocationWhere[Q](PublicreportReportLocations.Columns),
|
||||
PublicreportSubscribeEmails: buildPublicreportSubscribeEmailWhere[Q](PublicreportSubscribeEmails.Columns),
|
||||
PublicreportSubscribePhones: buildPublicreportSubscribePhoneWhere[Q](PublicreportSubscribePhones.Columns),
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ type Feature struct {
|
|||
ID int32 `db:"id,pk" `
|
||||
OrganizationID int32 `db:"organization_id" `
|
||||
SiteID int32 `db:"site_id" `
|
||||
SiteVersion int32 `db:"site_version" `
|
||||
Location null.Val[string] `db:"location" `
|
||||
|
||||
R featureR `db:"-" `
|
||||
|
|
@ -50,14 +49,14 @@ type FeaturesQuery = *psql.ViewQuery[*Feature, FeatureSlice]
|
|||
type featureR struct {
|
||||
CreatorUser *User // feature.feature_creator_id_fkey
|
||||
Organization *Organization // feature.feature_organization_id_fkey
|
||||
Site *Site // feature.feature_site_id_site_version_fkey
|
||||
Site *Site // feature.feature_site_id_fkey
|
||||
FeaturePool *FeaturePool // feature_pool.feature_pool_feature_id_fkey
|
||||
}
|
||||
|
||||
func buildFeatureColumns(alias string) featureColumns {
|
||||
return featureColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"created", "creator_id", "id", "organization_id", "site_id", "site_version", "location",
|
||||
"created", "creator_id", "id", "organization_id", "site_id", "location",
|
||||
).WithParent("feature"),
|
||||
tableAlias: alias,
|
||||
Created: psql.Quote(alias, "created"),
|
||||
|
|
@ -65,7 +64,6 @@ func buildFeatureColumns(alias string) featureColumns {
|
|||
ID: psql.Quote(alias, "id"),
|
||||
OrganizationID: psql.Quote(alias, "organization_id"),
|
||||
SiteID: psql.Quote(alias, "site_id"),
|
||||
SiteVersion: psql.Quote(alias, "site_version"),
|
||||
Location: psql.Quote(alias, "location"),
|
||||
}
|
||||
}
|
||||
|
|
@ -78,7 +76,6 @@ type featureColumns struct {
|
|||
ID psql.Expression
|
||||
OrganizationID psql.Expression
|
||||
SiteID psql.Expression
|
||||
SiteVersion psql.Expression
|
||||
Location psql.Expression
|
||||
}
|
||||
|
||||
|
|
@ -99,12 +96,11 @@ type FeatureSetter struct {
|
|||
ID omit.Val[int32] `db:"id,pk" `
|
||||
OrganizationID omit.Val[int32] `db:"organization_id" `
|
||||
SiteID omit.Val[int32] `db:"site_id" `
|
||||
SiteVersion omit.Val[int32] `db:"site_version" `
|
||||
Location omitnull.Val[string] `db:"location" `
|
||||
}
|
||||
|
||||
func (s FeatureSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 7)
|
||||
vals := make([]string, 0, 6)
|
||||
if s.Created.IsValue() {
|
||||
vals = append(vals, "created")
|
||||
}
|
||||
|
|
@ -120,9 +116,6 @@ func (s FeatureSetter) SetColumns() []string {
|
|||
if s.SiteID.IsValue() {
|
||||
vals = append(vals, "site_id")
|
||||
}
|
||||
if s.SiteVersion.IsValue() {
|
||||
vals = append(vals, "site_version")
|
||||
}
|
||||
if !s.Location.IsUnset() {
|
||||
vals = append(vals, "location")
|
||||
}
|
||||
|
|
@ -145,9 +138,6 @@ func (s FeatureSetter) Overwrite(t *Feature) {
|
|||
if s.SiteID.IsValue() {
|
||||
t.SiteID = s.SiteID.MustGet()
|
||||
}
|
||||
if s.SiteVersion.IsValue() {
|
||||
t.SiteVersion = s.SiteVersion.MustGet()
|
||||
}
|
||||
if !s.Location.IsUnset() {
|
||||
t.Location = s.Location.MustGetNull()
|
||||
}
|
||||
|
|
@ -159,7 +149,7 @@ func (s *FeatureSetter) Apply(q *dialect.InsertQuery) {
|
|||
})
|
||||
|
||||
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
vals := make([]bob.Expression, 7)
|
||||
vals := make([]bob.Expression, 6)
|
||||
if s.Created.IsValue() {
|
||||
vals[0] = psql.Arg(s.Created.MustGet())
|
||||
} else {
|
||||
|
|
@ -190,18 +180,12 @@ func (s *FeatureSetter) Apply(q *dialect.InsertQuery) {
|
|||
vals[4] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.SiteVersion.IsValue() {
|
||||
vals[5] = psql.Arg(s.SiteVersion.MustGet())
|
||||
if !s.Location.IsUnset() {
|
||||
vals[5] = psql.Arg(s.Location.MustGetNull())
|
||||
} else {
|
||||
vals[5] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.Location.IsUnset() {
|
||||
vals[6] = psql.Arg(s.Location.MustGetNull())
|
||||
} else {
|
||||
vals[6] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
|
@ -211,7 +195,7 @@ func (s FeatureSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|||
}
|
||||
|
||||
func (s FeatureSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 7)
|
||||
exprs := make([]bob.Expression, 0, 6)
|
||||
|
||||
if s.Created.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
|
|
@ -248,13 +232,6 @@ func (s FeatureSetter) Expressions(prefix ...string) []bob.Expression {
|
|||
}})
|
||||
}
|
||||
|
||||
if s.SiteVersion.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "site_version")...),
|
||||
psql.Arg(s.SiteVersion),
|
||||
}})
|
||||
}
|
||||
|
||||
if !s.Location.IsUnset() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "location")...),
|
||||
|
|
@ -539,28 +516,24 @@ func (os FeatureSlice) Organization(mods ...bob.Mod[*dialect.SelectQuery]) Organ
|
|||
// Site starts a query for related objects on site
|
||||
func (o *Feature) Site(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
|
||||
return Sites.Query(append(mods,
|
||||
sm.Where(Sites.Columns.ID.EQ(psql.Arg(o.SiteID))), sm.Where(Sites.Columns.Version.EQ(psql.Arg(o.SiteVersion))),
|
||||
sm.Where(Sites.Columns.ID.EQ(psql.Arg(o.SiteID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os FeatureSlice) Site(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
|
||||
pkSiteID := make(pgtypes.Array[int32], 0, len(os))
|
||||
|
||||
pkSiteVersion := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkSiteID = append(pkSiteID, o.SiteID)
|
||||
pkSiteVersion = append(pkSiteVersion, o.SiteVersion)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkSiteID), "integer[]")),
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkSiteVersion), "integer[]")),
|
||||
))
|
||||
|
||||
return Sites.Query(append(mods,
|
||||
sm.Where(psql.Group(Sites.Columns.ID, Sites.Columns.Version).OP("IN", PKArgExpr)),
|
||||
sm.Where(psql.Group(Sites.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
|
|
@ -687,7 +660,6 @@ func (feature0 *Feature) AttachOrganization(ctx context.Context, exec bob.Execut
|
|||
func attachFeatureSite0(ctx context.Context, exec bob.Executor, count int, feature0 *Feature, site1 *Site) (*Feature, error) {
|
||||
setter := &FeatureSetter{
|
||||
SiteID: omit.From(site1.ID),
|
||||
SiteVersion: omit.From(site1.Version),
|
||||
}
|
||||
|
||||
err := feature0.Update(ctx, exec, setter)
|
||||
|
|
@ -793,7 +765,6 @@ type featureWhere[Q psql.Filterable] struct {
|
|||
ID psql.WhereMod[Q, int32]
|
||||
OrganizationID psql.WhereMod[Q, int32]
|
||||
SiteID psql.WhereMod[Q, int32]
|
||||
SiteVersion psql.WhereMod[Q, int32]
|
||||
Location psql.WhereNullMod[Q, string]
|
||||
}
|
||||
|
||||
|
|
@ -808,7 +779,6 @@ func buildFeatureWhere[Q psql.Filterable](cols featureColumns) featureWhere[Q] {
|
|||
ID: psql.Where[Q, int32](cols.ID),
|
||||
OrganizationID: psql.Where[Q, int32](cols.OrganizationID),
|
||||
SiteID: psql.Where[Q, int32](cols.SiteID),
|
||||
SiteVersion: psql.Where[Q, int32](cols.SiteVersion),
|
||||
Location: psql.WhereNull[Q, string](cols.Location),
|
||||
}
|
||||
}
|
||||
|
|
@ -914,8 +884,8 @@ func buildFeaturePreloader() featurePreloader {
|
|||
{
|
||||
From: Features,
|
||||
To: Sites,
|
||||
FromColumns: []string{"site_id", "site_version"},
|
||||
ToColumns: []string{"id", "version"},
|
||||
FromColumns: []string{"site_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, Sites.Columns.Names(), opts...)
|
||||
|
|
@ -1131,10 +1101,6 @@ func (os FeatureSlice) LoadSite(ctx context.Context, exec bob.Executor, mods ...
|
|||
continue
|
||||
}
|
||||
|
||||
if !(o.SiteVersion == rel.Version) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.Features = append(rel.R.Features, o)
|
||||
|
||||
o.R.Site = rel
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ type Lead struct {
|
|||
ID int32 `db:"id,pk" `
|
||||
OrganizationID int32 `db:"organization_id" `
|
||||
SiteID null.Val[int32] `db:"site_id" `
|
||||
SiteVersion null.Val[int32] `db:"site_version" `
|
||||
Type enums.Leadtype `db:"type_" `
|
||||
|
||||
R leadR `db:"-" `
|
||||
|
|
@ -52,13 +51,13 @@ type leadR struct {
|
|||
ComplianceReportRequests ComplianceReportRequestSlice // compliance_report_request.compliance_report_request_lead_id_fkey
|
||||
CreatorUser *User // lead.lead_creator_fkey
|
||||
Organization *Organization // lead.lead_organization_id_fkey
|
||||
Site *Site // lead.lead_site_id_site_version_fkey
|
||||
Site *Site // lead.lead_site_id_fkey
|
||||
}
|
||||
|
||||
func buildLeadColumns(alias string) leadColumns {
|
||||
return leadColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"created", "creator", "id", "organization_id", "site_id", "site_version", "type_",
|
||||
"created", "creator", "id", "organization_id", "site_id", "type_",
|
||||
).WithParent("lead"),
|
||||
tableAlias: alias,
|
||||
Created: psql.Quote(alias, "created"),
|
||||
|
|
@ -66,7 +65,6 @@ func buildLeadColumns(alias string) leadColumns {
|
|||
ID: psql.Quote(alias, "id"),
|
||||
OrganizationID: psql.Quote(alias, "organization_id"),
|
||||
SiteID: psql.Quote(alias, "site_id"),
|
||||
SiteVersion: psql.Quote(alias, "site_version"),
|
||||
Type: psql.Quote(alias, "type_"),
|
||||
}
|
||||
}
|
||||
|
|
@ -79,7 +77,6 @@ type leadColumns struct {
|
|||
ID psql.Expression
|
||||
OrganizationID psql.Expression
|
||||
SiteID psql.Expression
|
||||
SiteVersion psql.Expression
|
||||
Type psql.Expression
|
||||
}
|
||||
|
||||
|
|
@ -100,12 +97,11 @@ type LeadSetter struct {
|
|||
ID omit.Val[int32] `db:"id,pk" `
|
||||
OrganizationID omit.Val[int32] `db:"organization_id" `
|
||||
SiteID omitnull.Val[int32] `db:"site_id" `
|
||||
SiteVersion omitnull.Val[int32] `db:"site_version" `
|
||||
Type omit.Val[enums.Leadtype] `db:"type_" `
|
||||
}
|
||||
|
||||
func (s LeadSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 7)
|
||||
vals := make([]string, 0, 6)
|
||||
if s.Created.IsValue() {
|
||||
vals = append(vals, "created")
|
||||
}
|
||||
|
|
@ -121,9 +117,6 @@ func (s LeadSetter) SetColumns() []string {
|
|||
if !s.SiteID.IsUnset() {
|
||||
vals = append(vals, "site_id")
|
||||
}
|
||||
if !s.SiteVersion.IsUnset() {
|
||||
vals = append(vals, "site_version")
|
||||
}
|
||||
if s.Type.IsValue() {
|
||||
vals = append(vals, "type_")
|
||||
}
|
||||
|
|
@ -146,9 +139,6 @@ func (s LeadSetter) Overwrite(t *Lead) {
|
|||
if !s.SiteID.IsUnset() {
|
||||
t.SiteID = s.SiteID.MustGetNull()
|
||||
}
|
||||
if !s.SiteVersion.IsUnset() {
|
||||
t.SiteVersion = s.SiteVersion.MustGetNull()
|
||||
}
|
||||
if s.Type.IsValue() {
|
||||
t.Type = s.Type.MustGet()
|
||||
}
|
||||
|
|
@ -160,7 +150,7 @@ func (s *LeadSetter) Apply(q *dialect.InsertQuery) {
|
|||
})
|
||||
|
||||
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
vals := make([]bob.Expression, 7)
|
||||
vals := make([]bob.Expression, 6)
|
||||
if s.Created.IsValue() {
|
||||
vals[0] = psql.Arg(s.Created.MustGet())
|
||||
} else {
|
||||
|
|
@ -191,18 +181,12 @@ func (s *LeadSetter) Apply(q *dialect.InsertQuery) {
|
|||
vals[4] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.SiteVersion.IsUnset() {
|
||||
vals[5] = psql.Arg(s.SiteVersion.MustGetNull())
|
||||
if s.Type.IsValue() {
|
||||
vals[5] = psql.Arg(s.Type.MustGet())
|
||||
} else {
|
||||
vals[5] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.Type.IsValue() {
|
||||
vals[6] = psql.Arg(s.Type.MustGet())
|
||||
} else {
|
||||
vals[6] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
|
@ -212,7 +196,7 @@ func (s LeadSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|||
}
|
||||
|
||||
func (s LeadSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 7)
|
||||
exprs := make([]bob.Expression, 0, 6)
|
||||
|
||||
if s.Created.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
|
|
@ -249,13 +233,6 @@ func (s LeadSetter) Expressions(prefix ...string) []bob.Expression {
|
|||
}})
|
||||
}
|
||||
|
||||
if !s.SiteVersion.IsUnset() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "site_version")...),
|
||||
psql.Arg(s.SiteVersion),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Type.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "type_")...),
|
||||
|
|
@ -564,28 +541,24 @@ func (os LeadSlice) Organization(mods ...bob.Mod[*dialect.SelectQuery]) Organiza
|
|||
// Site starts a query for related objects on site
|
||||
func (o *Lead) Site(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
|
||||
return Sites.Query(append(mods,
|
||||
sm.Where(Sites.Columns.ID.EQ(psql.Arg(o.SiteID))), sm.Where(Sites.Columns.Version.EQ(psql.Arg(o.SiteVersion))),
|
||||
sm.Where(Sites.Columns.ID.EQ(psql.Arg(o.SiteID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os LeadSlice) Site(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
|
||||
pkSiteID := make(pgtypes.Array[null.Val[int32]], 0, len(os))
|
||||
|
||||
pkSiteVersion := make(pgtypes.Array[null.Val[int32]], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkSiteID = append(pkSiteID, o.SiteID)
|
||||
pkSiteVersion = append(pkSiteVersion, o.SiteVersion)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkSiteID), "integer[]")),
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkSiteVersion), "integer[]")),
|
||||
))
|
||||
|
||||
return Sites.Query(append(mods,
|
||||
sm.Where(psql.Group(Sites.Columns.ID, Sites.Columns.Version).OP("IN", PKArgExpr)),
|
||||
sm.Where(psql.Group(Sites.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
|
|
@ -756,7 +729,6 @@ func (lead0 *Lead) AttachOrganization(ctx context.Context, exec bob.Executor, or
|
|||
func attachLeadSite0(ctx context.Context, exec bob.Executor, count int, lead0 *Lead, site1 *Site) (*Lead, error) {
|
||||
setter := &LeadSetter{
|
||||
SiteID: omitnull.From(site1.ID),
|
||||
SiteVersion: omitnull.From(site1.Version),
|
||||
}
|
||||
|
||||
err := lead0.Update(ctx, exec, setter)
|
||||
|
|
@ -808,7 +780,6 @@ type leadWhere[Q psql.Filterable] struct {
|
|||
ID psql.WhereMod[Q, int32]
|
||||
OrganizationID psql.WhereMod[Q, int32]
|
||||
SiteID psql.WhereNullMod[Q, int32]
|
||||
SiteVersion psql.WhereNullMod[Q, int32]
|
||||
Type psql.WhereMod[Q, enums.Leadtype]
|
||||
}
|
||||
|
||||
|
|
@ -823,7 +794,6 @@ func buildLeadWhere[Q psql.Filterable](cols leadColumns) leadWhere[Q] {
|
|||
ID: psql.Where[Q, int32](cols.ID),
|
||||
OrganizationID: psql.Where[Q, int32](cols.OrganizationID),
|
||||
SiteID: psql.WhereNull[Q, int32](cols.SiteID),
|
||||
SiteVersion: psql.WhereNull[Q, int32](cols.SiteVersion),
|
||||
Type: psql.Where[Q, enums.Leadtype](cols.Type),
|
||||
}
|
||||
}
|
||||
|
|
@ -930,8 +900,8 @@ func buildLeadPreloader() leadPreloader {
|
|||
{
|
||||
From: Leads,
|
||||
To: Sites,
|
||||
FromColumns: []string{"site_id", "site_version"},
|
||||
ToColumns: []string{"id", "version"},
|
||||
FromColumns: []string{"site_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, Sites.Columns.Names(), opts...)
|
||||
|
|
@ -1200,13 +1170,6 @@ func (os LeadSlice) LoadSite(ctx context.Context, exec bob.Executor, mods ...bob
|
|||
if !(o.SiteID.IsValue() && o.SiteID.MustGet() == rel.ID) {
|
||||
continue
|
||||
}
|
||||
if !o.SiteVersion.IsValue() {
|
||||
continue
|
||||
}
|
||||
|
||||
if !(o.SiteVersion.IsValue() && o.SiteVersion.MustGet() == rel.Version) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.Leads = append(rel.R.Leads, o)
|
||||
|
||||
|
|
|
|||
|
|
@ -64,6 +64,8 @@ type PublicreportNuisance struct {
|
|||
Location null.Val[string] `db:"location" `
|
||||
AddressNumber string `db:"address_number" `
|
||||
AddressID null.Val[int32] `db:"address_id" `
|
||||
Reviewed null.Val[time.Time] `db:"reviewed" `
|
||||
ReviewerID null.Val[int32] `db:"reviewer_id" `
|
||||
|
||||
R publicreportNuisanceR `db:"-" `
|
||||
}
|
||||
|
|
@ -84,13 +86,14 @@ type publicreportNuisanceR struct {
|
|||
NotifyPhoneNuisances PublicreportNotifyPhoneNuisanceSlice // publicreport.notify_phone_nuisance.notify_phone_nuisance_nuisance_id_fkey
|
||||
Address *Address // publicreport.nuisance.nuisance_address_id_fkey
|
||||
Organization *Organization // publicreport.nuisance.nuisance_organization_id_fkey
|
||||
ReviewerUser *User // publicreport.nuisance.nuisance_reviewer_id_fkey
|
||||
Images PublicreportImageSlice // publicreport.nuisance_image.nuisance_image_image_id_fkeypublicreport.nuisance_image.nuisance_image_nuisance_id_fkey
|
||||
}
|
||||
|
||||
func buildPublicreportNuisanceColumns(alias string) publicreportNuisanceColumns {
|
||||
return publicreportNuisanceColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"id", "additional_info", "created", "duration", "source_container", "source_description", "source_stagnant", "public_id", "reporter_email", "reporter_name", "reporter_phone", "address_raw", "status", "organization_id", "source_gutter", "h3cell", "address_country", "address_locality", "address_postal_code", "address_region", "address_street", "is_location_backyard", "is_location_frontyard", "is_location_garden", "is_location_other", "is_location_pool", "map_zoom", "tod_early", "tod_day", "tod_evening", "tod_night", "latlng_accuracy_type", "latlng_accuracy_value", "reporter_contact_consent", "location", "address_number", "address_id",
|
||||
"id", "additional_info", "created", "duration", "source_container", "source_description", "source_stagnant", "public_id", "reporter_email", "reporter_name", "reporter_phone", "address_raw", "status", "organization_id", "source_gutter", "h3cell", "address_country", "address_locality", "address_postal_code", "address_region", "address_street", "is_location_backyard", "is_location_frontyard", "is_location_garden", "is_location_other", "is_location_pool", "map_zoom", "tod_early", "tod_day", "tod_evening", "tod_night", "latlng_accuracy_type", "latlng_accuracy_value", "reporter_contact_consent", "location", "address_number", "address_id", "reviewed", "reviewer_id",
|
||||
).WithParent("publicreport.nuisance"),
|
||||
tableAlias: alias,
|
||||
ID: psql.Quote(alias, "id"),
|
||||
|
|
@ -130,6 +133,8 @@ func buildPublicreportNuisanceColumns(alias string) publicreportNuisanceColumns
|
|||
Location: psql.Quote(alias, "location"),
|
||||
AddressNumber: psql.Quote(alias, "address_number"),
|
||||
AddressID: psql.Quote(alias, "address_id"),
|
||||
Reviewed: psql.Quote(alias, "reviewed"),
|
||||
ReviewerID: psql.Quote(alias, "reviewer_id"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -173,6 +178,8 @@ type publicreportNuisanceColumns struct {
|
|||
Location psql.Expression
|
||||
AddressNumber psql.Expression
|
||||
AddressID psql.Expression
|
||||
Reviewed psql.Expression
|
||||
ReviewerID psql.Expression
|
||||
}
|
||||
|
||||
func (c publicreportNuisanceColumns) Alias() string {
|
||||
|
|
@ -224,10 +231,12 @@ type PublicreportNuisanceSetter struct {
|
|||
Location omitnull.Val[string] `db:"location" `
|
||||
AddressNumber omit.Val[string] `db:"address_number" `
|
||||
AddressID omitnull.Val[int32] `db:"address_id" `
|
||||
Reviewed omitnull.Val[time.Time] `db:"reviewed" `
|
||||
ReviewerID omitnull.Val[int32] `db:"reviewer_id" `
|
||||
}
|
||||
|
||||
func (s PublicreportNuisanceSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 37)
|
||||
vals := make([]string, 0, 39)
|
||||
if s.ID.IsValue() {
|
||||
vals = append(vals, "id")
|
||||
}
|
||||
|
|
@ -339,6 +348,12 @@ func (s PublicreportNuisanceSetter) SetColumns() []string {
|
|||
if !s.AddressID.IsUnset() {
|
||||
vals = append(vals, "address_id")
|
||||
}
|
||||
if !s.Reviewed.IsUnset() {
|
||||
vals = append(vals, "reviewed")
|
||||
}
|
||||
if !s.ReviewerID.IsUnset() {
|
||||
vals = append(vals, "reviewer_id")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
|
|
@ -454,6 +469,12 @@ func (s PublicreportNuisanceSetter) Overwrite(t *PublicreportNuisance) {
|
|||
if !s.AddressID.IsUnset() {
|
||||
t.AddressID = s.AddressID.MustGetNull()
|
||||
}
|
||||
if !s.Reviewed.IsUnset() {
|
||||
t.Reviewed = s.Reviewed.MustGetNull()
|
||||
}
|
||||
if !s.ReviewerID.IsUnset() {
|
||||
t.ReviewerID = s.ReviewerID.MustGetNull()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PublicreportNuisanceSetter) Apply(q *dialect.InsertQuery) {
|
||||
|
|
@ -462,7 +483,7 @@ func (s *PublicreportNuisanceSetter) Apply(q *dialect.InsertQuery) {
|
|||
})
|
||||
|
||||
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
vals := make([]bob.Expression, 37)
|
||||
vals := make([]bob.Expression, 39)
|
||||
if s.ID.IsValue() {
|
||||
vals[0] = psql.Arg(s.ID.MustGet())
|
||||
} else {
|
||||
|
|
@ -685,6 +706,18 @@ func (s *PublicreportNuisanceSetter) Apply(q *dialect.InsertQuery) {
|
|||
vals[36] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.Reviewed.IsUnset() {
|
||||
vals[37] = psql.Arg(s.Reviewed.MustGetNull())
|
||||
} else {
|
||||
vals[37] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.ReviewerID.IsUnset() {
|
||||
vals[38] = psql.Arg(s.ReviewerID.MustGetNull())
|
||||
} else {
|
||||
vals[38] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
|
@ -694,7 +727,7 @@ func (s PublicreportNuisanceSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|||
}
|
||||
|
||||
func (s PublicreportNuisanceSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 37)
|
||||
exprs := make([]bob.Expression, 0, 39)
|
||||
|
||||
if s.ID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
|
|
@ -955,6 +988,20 @@ func (s PublicreportNuisanceSetter) Expressions(prefix ...string) []bob.Expressi
|
|||
}})
|
||||
}
|
||||
|
||||
if !s.Reviewed.IsUnset() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "reviewed")...),
|
||||
psql.Arg(s.Reviewed),
|
||||
}})
|
||||
}
|
||||
|
||||
if !s.ReviewerID.IsUnset() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "reviewer_id")...),
|
||||
psql.Arg(s.ReviewerID),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
|
|
@ -1277,6 +1324,30 @@ func (os PublicreportNuisanceSlice) Organization(mods ...bob.Mod[*dialect.Select
|
|||
)...)
|
||||
}
|
||||
|
||||
// ReviewerUser starts a query for related objects on user_
|
||||
func (o *PublicreportNuisance) ReviewerUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
|
||||
return Users.Query(append(mods,
|
||||
sm.Where(Users.Columns.ID.EQ(psql.Arg(o.ReviewerID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os PublicreportNuisanceSlice) ReviewerUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
|
||||
pkReviewerID := make(pgtypes.Array[null.Val[int32]], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkReviewerID = append(pkReviewerID, o.ReviewerID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkReviewerID), "integer[]")),
|
||||
))
|
||||
|
||||
return Users.Query(append(mods,
|
||||
sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// Images starts a query for related objects on publicreport.image
|
||||
func (o *PublicreportNuisance) Images(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery {
|
||||
return PublicreportImages.Query(append(mods,
|
||||
|
|
@ -1538,6 +1609,54 @@ func (publicreportNuisance0 *PublicreportNuisance) AttachOrganization(ctx contex
|
|||
return nil
|
||||
}
|
||||
|
||||
func attachPublicreportNuisanceReviewerUser0(ctx context.Context, exec bob.Executor, count int, publicreportNuisance0 *PublicreportNuisance, user1 *User) (*PublicreportNuisance, error) {
|
||||
setter := &PublicreportNuisanceSetter{
|
||||
ReviewerID: omitnull.From(user1.ID),
|
||||
}
|
||||
|
||||
err := publicreportNuisance0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachPublicreportNuisanceReviewerUser0: %w", err)
|
||||
}
|
||||
|
||||
return publicreportNuisance0, nil
|
||||
}
|
||||
|
||||
func (publicreportNuisance0 *PublicreportNuisance) InsertReviewerUser(ctx context.Context, exec bob.Executor, related *UserSetter) error {
|
||||
var err error
|
||||
|
||||
user1, err := Users.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachPublicreportNuisanceReviewerUser0(ctx, exec, 1, publicreportNuisance0, user1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportNuisance0.R.ReviewerUser = user1
|
||||
|
||||
user1.R.ReviewerNuisances = append(user1.R.ReviewerNuisances, publicreportNuisance0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (publicreportNuisance0 *PublicreportNuisance) AttachReviewerUser(ctx context.Context, exec bob.Executor, user1 *User) error {
|
||||
var err error
|
||||
|
||||
_, err = attachPublicreportNuisanceReviewerUser0(ctx, exec, 1, publicreportNuisance0, user1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportNuisance0.R.ReviewerUser = user1
|
||||
|
||||
user1.R.ReviewerNuisances = append(user1.R.ReviewerNuisances, publicreportNuisance0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func attachPublicreportNuisanceImages0(ctx context.Context, exec bob.Executor, count int, publicreportNuisance0 *PublicreportNuisance, publicreportImages2 PublicreportImageSlice) (PublicreportNuisanceImageSlice, error) {
|
||||
setters := make([]*PublicreportNuisanceImageSetter, count)
|
||||
for i := range count {
|
||||
|
|
@ -1641,6 +1760,8 @@ type publicreportNuisanceWhere[Q psql.Filterable] struct {
|
|||
Location psql.WhereNullMod[Q, string]
|
||||
AddressNumber psql.WhereMod[Q, string]
|
||||
AddressID psql.WhereNullMod[Q, int32]
|
||||
Reviewed psql.WhereNullMod[Q, time.Time]
|
||||
ReviewerID psql.WhereNullMod[Q, int32]
|
||||
}
|
||||
|
||||
func (publicreportNuisanceWhere[Q]) AliasedAs(alias string) publicreportNuisanceWhere[Q] {
|
||||
|
|
@ -1686,6 +1807,8 @@ func buildPublicreportNuisanceWhere[Q psql.Filterable](cols publicreportNuisance
|
|||
Location: psql.WhereNull[Q, string](cols.Location),
|
||||
AddressNumber: psql.Where[Q, string](cols.AddressNumber),
|
||||
AddressID: psql.WhereNull[Q, int32](cols.AddressID),
|
||||
Reviewed: psql.WhereNull[Q, time.Time](cols.Reviewed),
|
||||
ReviewerID: psql.WhereNull[Q, int32](cols.ReviewerID),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1747,6 +1870,18 @@ func (o *PublicreportNuisance) Preload(name string, retrieved any) error {
|
|||
rel.R.Nuisances = PublicreportNuisanceSlice{o}
|
||||
}
|
||||
return nil
|
||||
case "ReviewerUser":
|
||||
rel, ok := retrieved.(*User)
|
||||
if !ok {
|
||||
return fmt.Errorf("publicreportNuisance cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.ReviewerUser = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.ReviewerNuisances = PublicreportNuisanceSlice{o}
|
||||
}
|
||||
return nil
|
||||
case "Images":
|
||||
rels, ok := retrieved.(PublicreportImageSlice)
|
||||
if !ok {
|
||||
|
|
@ -1769,6 +1904,7 @@ func (o *PublicreportNuisance) Preload(name string, retrieved any) error {
|
|||
type publicreportNuisancePreloader struct {
|
||||
Address func(...psql.PreloadOption) psql.Preloader
|
||||
Organization func(...psql.PreloadOption) psql.Preloader
|
||||
ReviewerUser func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildPublicreportNuisancePreloader() publicreportNuisancePreloader {
|
||||
|
|
@ -1799,6 +1935,19 @@ func buildPublicreportNuisancePreloader() publicreportNuisancePreloader {
|
|||
},
|
||||
}, Organizations.Columns.Names(), opts...)
|
||||
},
|
||||
ReviewerUser: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*User, UserSlice](psql.PreloadRel{
|
||||
Name: "ReviewerUser",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: PublicreportNuisances,
|
||||
To: Users,
|
||||
FromColumns: []string{"reviewer_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, Users.Columns.Names(), opts...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1807,6 +1956,7 @@ type publicreportNuisanceThenLoader[Q orm.Loadable] struct {
|
|||
NotifyPhoneNuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Address func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
ReviewerUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Images func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
|
|
@ -1823,6 +1973,9 @@ func buildPublicreportNuisanceThenLoader[Q orm.Loadable]() publicreportNuisanceT
|
|||
type OrganizationLoadInterface interface {
|
||||
LoadOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type ReviewerUserLoadInterface interface {
|
||||
LoadReviewerUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type ImagesLoadInterface interface {
|
||||
LoadImages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
|
@ -1852,6 +2005,12 @@ func buildPublicreportNuisanceThenLoader[Q orm.Loadable]() publicreportNuisanceT
|
|||
return retrieved.LoadOrganization(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
ReviewerUser: thenLoadBuilder[Q](
|
||||
"ReviewerUser",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ReviewerUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadReviewerUser(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
Images: thenLoadBuilder[Q](
|
||||
"Images",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ImagesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
|
|
@ -2093,6 +2252,61 @@ func (os PublicreportNuisanceSlice) LoadOrganization(ctx context.Context, exec b
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadReviewerUser loads the publicreportNuisance's ReviewerUser into the .R struct
|
||||
func (o *PublicreportNuisance) LoadReviewerUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.ReviewerUser = nil
|
||||
|
||||
related, err := o.ReviewerUser(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.ReviewerNuisances = PublicreportNuisanceSlice{o}
|
||||
|
||||
o.R.ReviewerUser = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadReviewerUser loads the publicreportNuisance's ReviewerUser into the .R struct
|
||||
func (os PublicreportNuisanceSlice) LoadReviewerUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
users, err := os.ReviewerUser(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range users {
|
||||
if !o.ReviewerID.IsValue() {
|
||||
continue
|
||||
}
|
||||
|
||||
if !(o.ReviewerID.IsValue() && o.ReviewerID.MustGet() == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.ReviewerNuisances = append(rel.R.ReviewerNuisances, o)
|
||||
|
||||
o.R.ReviewerUser = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadImages loads the publicreportNuisance's Images into the .R struct
|
||||
func (o *PublicreportNuisance) LoadImages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
|
|
|
|||
140
db/models/publicreport.organization_report_count.bob.go
Normal file
140
db/models/publicreport.organization_report_count.bob.go
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
|
||||
// This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Gleipnir-Technology/bob"
|
||||
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
||||
"github.com/Gleipnir-Technology/bob/expr"
|
||||
"github.com/aarondl/opt/null"
|
||||
)
|
||||
|
||||
// PublicreportOrganizationReportCount is an object representing the database table.
|
||||
type PublicreportOrganizationReportCount struct {
|
||||
OrganizationID null.Val[int32] `db:"organization_id" `
|
||||
NuisanceReported null.Val[int64] `db:"nuisance_reported" `
|
||||
NuisanceReviewed null.Val[int64] `db:"nuisance_reviewed" `
|
||||
NuisanceScheduled null.Val[int64] `db:"nuisance_scheduled" `
|
||||
NuisanceTreated null.Val[int64] `db:"nuisance_treated" `
|
||||
NuisanceInvalidated null.Val[int64] `db:"nuisance_invalidated" `
|
||||
WaterReported null.Val[int64] `db:"water_reported" `
|
||||
WaterReviewed null.Val[int64] `db:"water_reviewed" `
|
||||
WaterScheduled null.Val[int64] `db:"water_scheduled" `
|
||||
WaterTreated null.Val[int64] `db:"water_treated" `
|
||||
WaterInvalidated null.Val[int64] `db:"water_invalidated" `
|
||||
}
|
||||
|
||||
// PublicreportOrganizationReportCountSlice is an alias for a slice of pointers to PublicreportOrganizationReportCount.
|
||||
// This should almost always be used instead of []*PublicreportOrganizationReportCount.
|
||||
type PublicreportOrganizationReportCountSlice []*PublicreportOrganizationReportCount
|
||||
|
||||
// PublicreportOrganizationReportCounts contains methods to work with the organization_report_count view
|
||||
var PublicreportOrganizationReportCounts = psql.NewViewx[*PublicreportOrganizationReportCount, PublicreportOrganizationReportCountSlice]("publicreport", "organization_report_count", buildPublicreportOrganizationReportCountColumns("publicreport.organization_report_count"))
|
||||
|
||||
// PublicreportOrganizationReportCountsQuery is a query on the organization_report_count view
|
||||
type PublicreportOrganizationReportCountsQuery = *psql.ViewQuery[*PublicreportOrganizationReportCount, PublicreportOrganizationReportCountSlice]
|
||||
|
||||
func buildPublicreportOrganizationReportCountColumns(alias string) publicreportOrganizationReportCountColumns {
|
||||
return publicreportOrganizationReportCountColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"organization_id", "nuisance_reported", "nuisance_reviewed", "nuisance_scheduled", "nuisance_treated", "nuisance_invalidated", "water_reported", "water_reviewed", "water_scheduled", "water_treated", "water_invalidated",
|
||||
).WithParent("publicreport.organization_report_count"),
|
||||
tableAlias: alias,
|
||||
OrganizationID: psql.Quote(alias, "organization_id"),
|
||||
NuisanceReported: psql.Quote(alias, "nuisance_reported"),
|
||||
NuisanceReviewed: psql.Quote(alias, "nuisance_reviewed"),
|
||||
NuisanceScheduled: psql.Quote(alias, "nuisance_scheduled"),
|
||||
NuisanceTreated: psql.Quote(alias, "nuisance_treated"),
|
||||
NuisanceInvalidated: psql.Quote(alias, "nuisance_invalidated"),
|
||||
WaterReported: psql.Quote(alias, "water_reported"),
|
||||
WaterReviewed: psql.Quote(alias, "water_reviewed"),
|
||||
WaterScheduled: psql.Quote(alias, "water_scheduled"),
|
||||
WaterTreated: psql.Quote(alias, "water_treated"),
|
||||
WaterInvalidated: psql.Quote(alias, "water_invalidated"),
|
||||
}
|
||||
}
|
||||
|
||||
type publicreportOrganizationReportCountColumns struct {
|
||||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
OrganizationID psql.Expression
|
||||
NuisanceReported psql.Expression
|
||||
NuisanceReviewed psql.Expression
|
||||
NuisanceScheduled psql.Expression
|
||||
NuisanceTreated psql.Expression
|
||||
NuisanceInvalidated psql.Expression
|
||||
WaterReported psql.Expression
|
||||
WaterReviewed psql.Expression
|
||||
WaterScheduled psql.Expression
|
||||
WaterTreated psql.Expression
|
||||
WaterInvalidated psql.Expression
|
||||
}
|
||||
|
||||
func (c publicreportOrganizationReportCountColumns) Alias() string {
|
||||
return c.tableAlias
|
||||
}
|
||||
|
||||
func (publicreportOrganizationReportCountColumns) AliasedAs(alias string) publicreportOrganizationReportCountColumns {
|
||||
return buildPublicreportOrganizationReportCountColumns(alias)
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after PublicreportOrganizationReportCount is retrieved from the database
|
||||
func (o *PublicreportOrganizationReportCount) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = PublicreportOrganizationReportCounts.AfterSelectHooks.RunHooks(ctx, exec, PublicreportOrganizationReportCountSlice{o})
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// AfterQueryHook is called after PublicreportOrganizationReportCountSlice is retrieved from the database
|
||||
func (o PublicreportOrganizationReportCountSlice) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType bob.QueryType) error {
|
||||
var err error
|
||||
|
||||
switch queryType {
|
||||
case bob.QueryTypeSelect:
|
||||
ctx, err = PublicreportOrganizationReportCounts.AfterSelectHooks.RunHooks(ctx, exec, o)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
type publicreportOrganizationReportCountWhere[Q psql.Filterable] struct {
|
||||
OrganizationID psql.WhereNullMod[Q, int32]
|
||||
NuisanceReported psql.WhereNullMod[Q, int64]
|
||||
NuisanceReviewed psql.WhereNullMod[Q, int64]
|
||||
NuisanceScheduled psql.WhereNullMod[Q, int64]
|
||||
NuisanceTreated psql.WhereNullMod[Q, int64]
|
||||
NuisanceInvalidated psql.WhereNullMod[Q, int64]
|
||||
WaterReported psql.WhereNullMod[Q, int64]
|
||||
WaterReviewed psql.WhereNullMod[Q, int64]
|
||||
WaterScheduled psql.WhereNullMod[Q, int64]
|
||||
WaterTreated psql.WhereNullMod[Q, int64]
|
||||
WaterInvalidated psql.WhereNullMod[Q, int64]
|
||||
}
|
||||
|
||||
func (publicreportOrganizationReportCountWhere[Q]) AliasedAs(alias string) publicreportOrganizationReportCountWhere[Q] {
|
||||
return buildPublicreportOrganizationReportCountWhere[Q](buildPublicreportOrganizationReportCountColumns(alias))
|
||||
}
|
||||
|
||||
func buildPublicreportOrganizationReportCountWhere[Q psql.Filterable](cols publicreportOrganizationReportCountColumns) publicreportOrganizationReportCountWhere[Q] {
|
||||
return publicreportOrganizationReportCountWhere[Q]{
|
||||
OrganizationID: psql.WhereNull[Q, int32](cols.OrganizationID),
|
||||
NuisanceReported: psql.WhereNull[Q, int64](cols.NuisanceReported),
|
||||
NuisanceReviewed: psql.WhereNull[Q, int64](cols.NuisanceReviewed),
|
||||
NuisanceScheduled: psql.WhereNull[Q, int64](cols.NuisanceScheduled),
|
||||
NuisanceTreated: psql.WhereNull[Q, int64](cols.NuisanceTreated),
|
||||
NuisanceInvalidated: psql.WhereNull[Q, int64](cols.NuisanceInvalidated),
|
||||
WaterReported: psql.WhereNull[Q, int64](cols.WaterReported),
|
||||
WaterReviewed: psql.WhereNull[Q, int64](cols.WaterReviewed),
|
||||
WaterScheduled: psql.WhereNull[Q, int64](cols.WaterScheduled),
|
||||
WaterTreated: psql.WhereNull[Q, int64](cols.WaterTreated),
|
||||
WaterInvalidated: psql.WhereNull[Q, int64](cols.WaterInvalidated),
|
||||
}
|
||||
}
|
||||
|
|
@ -63,6 +63,8 @@ type PublicreportWater struct {
|
|||
Location null.Val[string] `db:"location" `
|
||||
AddressNumber string `db:"address_number" `
|
||||
AddressID null.Val[int32] `db:"address_id" `
|
||||
Reviewed null.Val[time.Time] `db:"reviewed" `
|
||||
ReviewerID null.Val[int32] `db:"reviewer_id" `
|
||||
|
||||
R publicreportWaterR `db:"-" `
|
||||
}
|
||||
|
|
@ -83,13 +85,14 @@ type publicreportWaterR struct {
|
|||
NotifyPhoneWaters PublicreportNotifyPhoneWaterSlice // publicreport.notify_phone_water.notify_phone_pool_pool_id_fkey
|
||||
Address *Address // publicreport.water.pool_address_id_fkey
|
||||
Organization *Organization // publicreport.water.pool_organization_id_fkey
|
||||
ReviewerUser *User // publicreport.water.water_reviewer_id_fkey
|
||||
Images PublicreportImageSlice // publicreport.water_image.pool_image_image_id_fkeypublicreport.water_image.pool_image_pool_id_fkey
|
||||
}
|
||||
|
||||
func buildPublicreportWaterColumns(alias string) publicreportWaterColumns {
|
||||
return publicreportWaterColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"id", "access_comments", "access_gate", "access_fence", "access_locked", "access_dog", "access_other", "address_raw", "address_country", "address_postal_code", "address_locality", "address_street", "address_region", "comments", "created", "h3cell", "has_adult", "has_larvae", "has_pupae", "map_zoom", "owner_email", "owner_name", "owner_phone", "public_id", "reporter_email", "reporter_name", "reporter_phone", "status", "organization_id", "has_backyard_permission", "is_reporter_confidential", "is_reporter_owner", "reporter_contact_consent", "location", "address_number", "address_id",
|
||||
"id", "access_comments", "access_gate", "access_fence", "access_locked", "access_dog", "access_other", "address_raw", "address_country", "address_postal_code", "address_locality", "address_street", "address_region", "comments", "created", "h3cell", "has_adult", "has_larvae", "has_pupae", "map_zoom", "owner_email", "owner_name", "owner_phone", "public_id", "reporter_email", "reporter_name", "reporter_phone", "status", "organization_id", "has_backyard_permission", "is_reporter_confidential", "is_reporter_owner", "reporter_contact_consent", "location", "address_number", "address_id", "reviewed", "reviewer_id",
|
||||
).WithParent("publicreport.water"),
|
||||
tableAlias: alias,
|
||||
ID: psql.Quote(alias, "id"),
|
||||
|
|
@ -128,6 +131,8 @@ func buildPublicreportWaterColumns(alias string) publicreportWaterColumns {
|
|||
Location: psql.Quote(alias, "location"),
|
||||
AddressNumber: psql.Quote(alias, "address_number"),
|
||||
AddressID: psql.Quote(alias, "address_id"),
|
||||
Reviewed: psql.Quote(alias, "reviewed"),
|
||||
ReviewerID: psql.Quote(alias, "reviewer_id"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -170,6 +175,8 @@ type publicreportWaterColumns struct {
|
|||
Location psql.Expression
|
||||
AddressNumber psql.Expression
|
||||
AddressID psql.Expression
|
||||
Reviewed psql.Expression
|
||||
ReviewerID psql.Expression
|
||||
}
|
||||
|
||||
func (c publicreportWaterColumns) Alias() string {
|
||||
|
|
@ -220,10 +227,12 @@ type PublicreportWaterSetter struct {
|
|||
Location omitnull.Val[string] `db:"location" `
|
||||
AddressNumber omit.Val[string] `db:"address_number" `
|
||||
AddressID omitnull.Val[int32] `db:"address_id" `
|
||||
Reviewed omitnull.Val[time.Time] `db:"reviewed" `
|
||||
ReviewerID omitnull.Val[int32] `db:"reviewer_id" `
|
||||
}
|
||||
|
||||
func (s PublicreportWaterSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 36)
|
||||
vals := make([]string, 0, 38)
|
||||
if s.ID.IsValue() {
|
||||
vals = append(vals, "id")
|
||||
}
|
||||
|
|
@ -332,6 +341,12 @@ func (s PublicreportWaterSetter) SetColumns() []string {
|
|||
if !s.AddressID.IsUnset() {
|
||||
vals = append(vals, "address_id")
|
||||
}
|
||||
if !s.Reviewed.IsUnset() {
|
||||
vals = append(vals, "reviewed")
|
||||
}
|
||||
if !s.ReviewerID.IsUnset() {
|
||||
vals = append(vals, "reviewer_id")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
|
|
@ -444,6 +459,12 @@ func (s PublicreportWaterSetter) Overwrite(t *PublicreportWater) {
|
|||
if !s.AddressID.IsUnset() {
|
||||
t.AddressID = s.AddressID.MustGetNull()
|
||||
}
|
||||
if !s.Reviewed.IsUnset() {
|
||||
t.Reviewed = s.Reviewed.MustGetNull()
|
||||
}
|
||||
if !s.ReviewerID.IsUnset() {
|
||||
t.ReviewerID = s.ReviewerID.MustGetNull()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PublicreportWaterSetter) Apply(q *dialect.InsertQuery) {
|
||||
|
|
@ -452,7 +473,7 @@ func (s *PublicreportWaterSetter) Apply(q *dialect.InsertQuery) {
|
|||
})
|
||||
|
||||
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
vals := make([]bob.Expression, 36)
|
||||
vals := make([]bob.Expression, 38)
|
||||
if s.ID.IsValue() {
|
||||
vals[0] = psql.Arg(s.ID.MustGet())
|
||||
} else {
|
||||
|
|
@ -669,6 +690,18 @@ func (s *PublicreportWaterSetter) Apply(q *dialect.InsertQuery) {
|
|||
vals[35] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.Reviewed.IsUnset() {
|
||||
vals[36] = psql.Arg(s.Reviewed.MustGetNull())
|
||||
} else {
|
||||
vals[36] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.ReviewerID.IsUnset() {
|
||||
vals[37] = psql.Arg(s.ReviewerID.MustGetNull())
|
||||
} else {
|
||||
vals[37] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
|
@ -678,7 +711,7 @@ func (s PublicreportWaterSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|||
}
|
||||
|
||||
func (s PublicreportWaterSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 36)
|
||||
exprs := make([]bob.Expression, 0, 38)
|
||||
|
||||
if s.ID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
|
|
@ -932,6 +965,20 @@ func (s PublicreportWaterSetter) Expressions(prefix ...string) []bob.Expression
|
|||
}})
|
||||
}
|
||||
|
||||
if !s.Reviewed.IsUnset() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "reviewed")...),
|
||||
psql.Arg(s.Reviewed),
|
||||
}})
|
||||
}
|
||||
|
||||
if !s.ReviewerID.IsUnset() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "reviewer_id")...),
|
||||
psql.Arg(s.ReviewerID),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
|
|
@ -1254,6 +1301,30 @@ func (os PublicreportWaterSlice) Organization(mods ...bob.Mod[*dialect.SelectQue
|
|||
)...)
|
||||
}
|
||||
|
||||
// ReviewerUser starts a query for related objects on user_
|
||||
func (o *PublicreportWater) ReviewerUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
|
||||
return Users.Query(append(mods,
|
||||
sm.Where(Users.Columns.ID.EQ(psql.Arg(o.ReviewerID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os PublicreportWaterSlice) ReviewerUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
|
||||
pkReviewerID := make(pgtypes.Array[null.Val[int32]], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkReviewerID = append(pkReviewerID, o.ReviewerID)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkReviewerID), "integer[]")),
|
||||
))
|
||||
|
||||
return Users.Query(append(mods,
|
||||
sm.Where(psql.Group(Users.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// Images starts a query for related objects on publicreport.image
|
||||
func (o *PublicreportWater) Images(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportImagesQuery {
|
||||
return PublicreportImages.Query(append(mods,
|
||||
|
|
@ -1515,6 +1586,54 @@ func (publicreportWater0 *PublicreportWater) AttachOrganization(ctx context.Cont
|
|||
return nil
|
||||
}
|
||||
|
||||
func attachPublicreportWaterReviewerUser0(ctx context.Context, exec bob.Executor, count int, publicreportWater0 *PublicreportWater, user1 *User) (*PublicreportWater, error) {
|
||||
setter := &PublicreportWaterSetter{
|
||||
ReviewerID: omitnull.From(user1.ID),
|
||||
}
|
||||
|
||||
err := publicreportWater0.Update(ctx, exec, setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachPublicreportWaterReviewerUser0: %w", err)
|
||||
}
|
||||
|
||||
return publicreportWater0, nil
|
||||
}
|
||||
|
||||
func (publicreportWater0 *PublicreportWater) InsertReviewerUser(ctx context.Context, exec bob.Executor, related *UserSetter) error {
|
||||
var err error
|
||||
|
||||
user1, err := Users.Insert(related).One(ctx, exec)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inserting related objects: %w", err)
|
||||
}
|
||||
|
||||
_, err = attachPublicreportWaterReviewerUser0(ctx, exec, 1, publicreportWater0, user1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportWater0.R.ReviewerUser = user1
|
||||
|
||||
user1.R.ReviewerWaters = append(user1.R.ReviewerWaters, publicreportWater0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (publicreportWater0 *PublicreportWater) AttachReviewerUser(ctx context.Context, exec bob.Executor, user1 *User) error {
|
||||
var err error
|
||||
|
||||
_, err = attachPublicreportWaterReviewerUser0(ctx, exec, 1, publicreportWater0, user1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
publicreportWater0.R.ReviewerUser = user1
|
||||
|
||||
user1.R.ReviewerWaters = append(user1.R.ReviewerWaters, publicreportWater0)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func attachPublicreportWaterImages0(ctx context.Context, exec bob.Executor, count int, publicreportWater0 *PublicreportWater, publicreportImages2 PublicreportImageSlice) (PublicreportWaterImageSlice, error) {
|
||||
setters := make([]*PublicreportWaterImageSetter, count)
|
||||
for i := range count {
|
||||
|
|
@ -1617,6 +1736,8 @@ type publicreportWaterWhere[Q psql.Filterable] struct {
|
|||
Location psql.WhereNullMod[Q, string]
|
||||
AddressNumber psql.WhereMod[Q, string]
|
||||
AddressID psql.WhereNullMod[Q, int32]
|
||||
Reviewed psql.WhereNullMod[Q, time.Time]
|
||||
ReviewerID psql.WhereNullMod[Q, int32]
|
||||
}
|
||||
|
||||
func (publicreportWaterWhere[Q]) AliasedAs(alias string) publicreportWaterWhere[Q] {
|
||||
|
|
@ -1661,6 +1782,8 @@ func buildPublicreportWaterWhere[Q psql.Filterable](cols publicreportWaterColumn
|
|||
Location: psql.WhereNull[Q, string](cols.Location),
|
||||
AddressNumber: psql.Where[Q, string](cols.AddressNumber),
|
||||
AddressID: psql.WhereNull[Q, int32](cols.AddressID),
|
||||
Reviewed: psql.WhereNull[Q, time.Time](cols.Reviewed),
|
||||
ReviewerID: psql.WhereNull[Q, int32](cols.ReviewerID),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1722,6 +1845,18 @@ func (o *PublicreportWater) Preload(name string, retrieved any) error {
|
|||
rel.R.Waters = PublicreportWaterSlice{o}
|
||||
}
|
||||
return nil
|
||||
case "ReviewerUser":
|
||||
rel, ok := retrieved.(*User)
|
||||
if !ok {
|
||||
return fmt.Errorf("publicreportWater cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.ReviewerUser = rel
|
||||
|
||||
if rel != nil {
|
||||
rel.R.ReviewerWaters = PublicreportWaterSlice{o}
|
||||
}
|
||||
return nil
|
||||
case "Images":
|
||||
rels, ok := retrieved.(PublicreportImageSlice)
|
||||
if !ok {
|
||||
|
|
@ -1744,6 +1879,7 @@ func (o *PublicreportWater) Preload(name string, retrieved any) error {
|
|||
type publicreportWaterPreloader struct {
|
||||
Address func(...psql.PreloadOption) psql.Preloader
|
||||
Organization func(...psql.PreloadOption) psql.Preloader
|
||||
ReviewerUser func(...psql.PreloadOption) psql.Preloader
|
||||
}
|
||||
|
||||
func buildPublicreportWaterPreloader() publicreportWaterPreloader {
|
||||
|
|
@ -1774,6 +1910,19 @@ func buildPublicreportWaterPreloader() publicreportWaterPreloader {
|
|||
},
|
||||
}, Organizations.Columns.Names(), opts...)
|
||||
},
|
||||
ReviewerUser: func(opts ...psql.PreloadOption) psql.Preloader {
|
||||
return psql.Preload[*User, UserSlice](psql.PreloadRel{
|
||||
Name: "ReviewerUser",
|
||||
Sides: []psql.PreloadSide{
|
||||
{
|
||||
From: PublicreportWaters,
|
||||
To: Users,
|
||||
FromColumns: []string{"reviewer_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, Users.Columns.Names(), opts...)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1782,6 +1931,7 @@ type publicreportWaterThenLoader[Q orm.Loadable] struct {
|
|||
NotifyPhoneWaters func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Address func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Organization func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
ReviewerUser func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
Images func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
}
|
||||
|
||||
|
|
@ -1798,6 +1948,9 @@ func buildPublicreportWaterThenLoader[Q orm.Loadable]() publicreportWaterThenLoa
|
|||
type OrganizationLoadInterface interface {
|
||||
LoadOrganization(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type ReviewerUserLoadInterface interface {
|
||||
LoadReviewerUser(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type ImagesLoadInterface interface {
|
||||
LoadImages(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
|
@ -1827,6 +1980,12 @@ func buildPublicreportWaterThenLoader[Q orm.Loadable]() publicreportWaterThenLoa
|
|||
return retrieved.LoadOrganization(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
ReviewerUser: thenLoadBuilder[Q](
|
||||
"ReviewerUser",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ReviewerUserLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadReviewerUser(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
Images: thenLoadBuilder[Q](
|
||||
"Images",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ImagesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
|
|
@ -2068,6 +2227,61 @@ func (os PublicreportWaterSlice) LoadOrganization(ctx context.Context, exec bob.
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadReviewerUser loads the publicreportWater's ReviewerUser into the .R struct
|
||||
func (o *PublicreportWater) LoadReviewerUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.ReviewerUser = nil
|
||||
|
||||
related, err := o.ReviewerUser(mods...).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
related.R.ReviewerWaters = PublicreportWaterSlice{o}
|
||||
|
||||
o.R.ReviewerUser = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadReviewerUser loads the publicreportWater's ReviewerUser into the .R struct
|
||||
func (os PublicreportWaterSlice) LoadReviewerUser(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
users, err := os.ReviewerUser(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range users {
|
||||
if !o.ReviewerID.IsValue() {
|
||||
continue
|
||||
}
|
||||
|
||||
if !(o.ReviewerID.IsValue() && o.ReviewerID.MustGet() == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.ReviewerWaters = append(rel.R.ReviewerWaters, o)
|
||||
|
||||
o.R.ReviewerUser = rel
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadImages loads the publicreportWater's Images into the .R struct
|
||||
func (o *PublicreportWater) LoadImages(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ type Resident struct {
|
|||
Name string `db:"name" `
|
||||
PhoneMobile null.Val[string] `db:"phone_mobile" `
|
||||
SiteID int32 `db:"site_id" `
|
||||
SiteVersion int32 `db:"site_version" `
|
||||
|
||||
R residentR `db:"-" `
|
||||
}
|
||||
|
|
@ -52,13 +51,13 @@ type residentR struct {
|
|||
Address *Address // resident.resident_address_id_fkey
|
||||
CreatorUser *User // resident.resident_creator_fkey
|
||||
PhoneMobilePhone *CommsPhone // resident.resident_phone_mobile_fkey
|
||||
Site *Site // resident.resident_site_id_site_version_fkey
|
||||
Site *Site // resident.resident_site_id_fkey
|
||||
}
|
||||
|
||||
func buildResidentColumns(alias string) residentColumns {
|
||||
return residentColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"address_id", "created", "creator", "id", "name", "phone_mobile", "site_id", "site_version",
|
||||
"address_id", "created", "creator", "id", "name", "phone_mobile", "site_id",
|
||||
).WithParent("resident"),
|
||||
tableAlias: alias,
|
||||
AddressID: psql.Quote(alias, "address_id"),
|
||||
|
|
@ -68,7 +67,6 @@ func buildResidentColumns(alias string) residentColumns {
|
|||
Name: psql.Quote(alias, "name"),
|
||||
PhoneMobile: psql.Quote(alias, "phone_mobile"),
|
||||
SiteID: psql.Quote(alias, "site_id"),
|
||||
SiteVersion: psql.Quote(alias, "site_version"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +80,6 @@ type residentColumns struct {
|
|||
Name psql.Expression
|
||||
PhoneMobile psql.Expression
|
||||
SiteID psql.Expression
|
||||
SiteVersion psql.Expression
|
||||
}
|
||||
|
||||
func (c residentColumns) Alias() string {
|
||||
|
|
@ -104,11 +101,10 @@ type ResidentSetter struct {
|
|||
Name omit.Val[string] `db:"name" `
|
||||
PhoneMobile omitnull.Val[string] `db:"phone_mobile" `
|
||||
SiteID omit.Val[int32] `db:"site_id" `
|
||||
SiteVersion omit.Val[int32] `db:"site_version" `
|
||||
}
|
||||
|
||||
func (s ResidentSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 8)
|
||||
vals := make([]string, 0, 7)
|
||||
if s.AddressID.IsValue() {
|
||||
vals = append(vals, "address_id")
|
||||
}
|
||||
|
|
@ -130,9 +126,6 @@ func (s ResidentSetter) SetColumns() []string {
|
|||
if s.SiteID.IsValue() {
|
||||
vals = append(vals, "site_id")
|
||||
}
|
||||
if s.SiteVersion.IsValue() {
|
||||
vals = append(vals, "site_version")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
|
|
@ -158,9 +151,6 @@ func (s ResidentSetter) Overwrite(t *Resident) {
|
|||
if s.SiteID.IsValue() {
|
||||
t.SiteID = s.SiteID.MustGet()
|
||||
}
|
||||
if s.SiteVersion.IsValue() {
|
||||
t.SiteVersion = s.SiteVersion.MustGet()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ResidentSetter) Apply(q *dialect.InsertQuery) {
|
||||
|
|
@ -169,7 +159,7 @@ func (s *ResidentSetter) Apply(q *dialect.InsertQuery) {
|
|||
})
|
||||
|
||||
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
vals := make([]bob.Expression, 8)
|
||||
vals := make([]bob.Expression, 7)
|
||||
if s.AddressID.IsValue() {
|
||||
vals[0] = psql.Arg(s.AddressID.MustGet())
|
||||
} else {
|
||||
|
|
@ -212,12 +202,6 @@ func (s *ResidentSetter) Apply(q *dialect.InsertQuery) {
|
|||
vals[6] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.SiteVersion.IsValue() {
|
||||
vals[7] = psql.Arg(s.SiteVersion.MustGet())
|
||||
} else {
|
||||
vals[7] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
|
@ -227,7 +211,7 @@ func (s ResidentSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|||
}
|
||||
|
||||
func (s ResidentSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 8)
|
||||
exprs := make([]bob.Expression, 0, 7)
|
||||
|
||||
if s.AddressID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
|
|
@ -278,13 +262,6 @@ func (s ResidentSetter) Expressions(prefix ...string) []bob.Expression {
|
|||
}})
|
||||
}
|
||||
|
||||
if s.SiteVersion.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "site_version")...),
|
||||
psql.Arg(s.SiteVersion),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
|
|
@ -586,28 +563,24 @@ func (os ResidentSlice) PhoneMobilePhone(mods ...bob.Mod[*dialect.SelectQuery])
|
|||
// Site starts a query for related objects on site
|
||||
func (o *Resident) Site(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
|
||||
return Sites.Query(append(mods,
|
||||
sm.Where(Sites.Columns.ID.EQ(psql.Arg(o.SiteID))), sm.Where(Sites.Columns.Version.EQ(psql.Arg(o.SiteVersion))),
|
||||
sm.Where(Sites.Columns.ID.EQ(psql.Arg(o.SiteID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os ResidentSlice) Site(mods ...bob.Mod[*dialect.SelectQuery]) SitesQuery {
|
||||
pkSiteID := make(pgtypes.Array[int32], 0, len(os))
|
||||
|
||||
pkSiteVersion := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkSiteID = append(pkSiteID, o.SiteID)
|
||||
pkSiteVersion = append(pkSiteVersion, o.SiteVersion)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkSiteID), "integer[]")),
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkSiteVersion), "integer[]")),
|
||||
))
|
||||
|
||||
return Sites.Query(append(mods,
|
||||
sm.Where(psql.Group(Sites.Columns.ID, Sites.Columns.Version).OP("IN", PKArgExpr)),
|
||||
sm.Where(psql.Group(Sites.Columns.ID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
|
|
@ -758,7 +731,6 @@ func (resident0 *Resident) AttachPhoneMobilePhone(ctx context.Context, exec bob.
|
|||
func attachResidentSite0(ctx context.Context, exec bob.Executor, count int, resident0 *Resident, site1 *Site) (*Resident, error) {
|
||||
setter := &ResidentSetter{
|
||||
SiteID: omit.From(site1.ID),
|
||||
SiteVersion: omit.From(site1.Version),
|
||||
}
|
||||
|
||||
err := resident0.Update(ctx, exec, setter)
|
||||
|
|
@ -812,7 +784,6 @@ type residentWhere[Q psql.Filterable] struct {
|
|||
Name psql.WhereMod[Q, string]
|
||||
PhoneMobile psql.WhereNullMod[Q, string]
|
||||
SiteID psql.WhereMod[Q, int32]
|
||||
SiteVersion psql.WhereMod[Q, int32]
|
||||
}
|
||||
|
||||
func (residentWhere[Q]) AliasedAs(alias string) residentWhere[Q] {
|
||||
|
|
@ -828,7 +799,6 @@ func buildResidentWhere[Q psql.Filterable](cols residentColumns) residentWhere[Q
|
|||
Name: psql.Where[Q, string](cols.Name),
|
||||
PhoneMobile: psql.WhereNull[Q, string](cols.PhoneMobile),
|
||||
SiteID: psql.Where[Q, int32](cols.SiteID),
|
||||
SiteVersion: psql.Where[Q, int32](cols.SiteVersion),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -946,8 +916,8 @@ func buildResidentPreloader() residentPreloader {
|
|||
{
|
||||
From: Residents,
|
||||
To: Sites,
|
||||
FromColumns: []string{"site_id", "site_version"},
|
||||
ToColumns: []string{"id", "version"},
|
||||
FromColumns: []string{"site_id"},
|
||||
ToColumns: []string{"id"},
|
||||
},
|
||||
},
|
||||
}, Sites.Columns.Names(), opts...)
|
||||
|
|
@ -1205,10 +1175,6 @@ func (os ResidentSlice) LoadSite(ctx context.Context, exec bob.Executor, mods ..
|
|||
continue
|
||||
}
|
||||
|
||||
if !(o.SiteVersion == rel.Version) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.Residents = append(rel.R.Residents, o)
|
||||
|
||||
o.R.Site = rel
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ type Site struct {
|
|||
ParcelID null.Val[int32] `db:"parcel_id" `
|
||||
ResidentOwned null.Val[bool] `db:"resident_owned" `
|
||||
Tags pgtypes.HStore `db:"tags" `
|
||||
Version int32 `db:"version,pk" `
|
||||
Version int32 `db:"version" `
|
||||
|
||||
R siteR `db:"-" `
|
||||
}
|
||||
|
|
@ -54,9 +54,9 @@ type SitesQuery = *psql.ViewQuery[*Site, SiteSlice]
|
|||
|
||||
// siteR is where relationships are stored.
|
||||
type siteR struct {
|
||||
Features FeatureSlice // feature.feature_site_id_site_version_fkey
|
||||
Leads LeadSlice // lead.lead_site_id_site_version_fkey
|
||||
Residents ResidentSlice // resident.resident_site_id_site_version_fkey
|
||||
Features FeatureSlice // feature.feature_site_id_fkey
|
||||
Leads LeadSlice // lead.lead_site_id_fkey
|
||||
Residents ResidentSlice // resident.resident_site_id_fkey
|
||||
Address *Address // site.site_address_id_fkey
|
||||
CreatorUser *User // site.site_creator_id_fkey
|
||||
File *FileuploadFile // site.site_file_id_fkey
|
||||
|
|
@ -127,7 +127,7 @@ type SiteSetter struct {
|
|||
ParcelID omitnull.Val[int32] `db:"parcel_id" `
|
||||
ResidentOwned omitnull.Val[bool] `db:"resident_owned" `
|
||||
Tags omit.Val[pgtypes.HStore] `db:"tags" `
|
||||
Version omit.Val[int32] `db:"version,pk" `
|
||||
Version omit.Val[int32] `db:"version" `
|
||||
}
|
||||
|
||||
func (s SiteSetter) SetColumns() []string {
|
||||
|
|
@ -408,26 +408,23 @@ func (s SiteSetter) Expressions(prefix ...string) []bob.Expression {
|
|||
|
||||
// FindSite retrieves a single record by primary key
|
||||
// If cols is empty Find will return all columns.
|
||||
func FindSite(ctx context.Context, exec bob.Executor, IDPK int32, VersionPK int32, cols ...string) (*Site, error) {
|
||||
func FindSite(ctx context.Context, exec bob.Executor, IDPK int32, cols ...string) (*Site, error) {
|
||||
if len(cols) == 0 {
|
||||
return Sites.Query(
|
||||
sm.Where(Sites.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
sm.Where(Sites.Columns.Version.EQ(psql.Arg(VersionPK))),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
return Sites.Query(
|
||||
sm.Where(Sites.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
sm.Where(Sites.Columns.Version.EQ(psql.Arg(VersionPK))),
|
||||
sm.Columns(Sites.Columns.Only(cols...)),
|
||||
).One(ctx, exec)
|
||||
}
|
||||
|
||||
// SiteExists checks the presence of a single record by primary key
|
||||
func SiteExists(ctx context.Context, exec bob.Executor, IDPK int32, VersionPK int32) (bool, error) {
|
||||
func SiteExists(ctx context.Context, exec bob.Executor, IDPK int32) (bool, error) {
|
||||
return Sites.Query(
|
||||
sm.Where(Sites.Columns.ID.EQ(psql.Arg(IDPK))),
|
||||
sm.Where(Sites.Columns.Version.EQ(psql.Arg(VersionPK))),
|
||||
).Exists(ctx, exec)
|
||||
}
|
||||
|
||||
|
|
@ -451,14 +448,11 @@ func (o *Site) AfterQueryHook(ctx context.Context, exec bob.Executor, queryType
|
|||
|
||||
// primaryKeyVals returns the primary key values of the Site
|
||||
func (o *Site) primaryKeyVals() bob.Expression {
|
||||
return psql.ArgGroup(
|
||||
o.ID,
|
||||
o.Version,
|
||||
)
|
||||
return psql.Arg(o.ID)
|
||||
}
|
||||
|
||||
func (o *Site) pkEQ() dialect.Expression {
|
||||
return psql.Group(psql.Quote("site", "id"), psql.Quote("site", "version")).EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
return psql.Quote("site", "id").EQ(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
return o.primaryKeyVals().WriteSQL(ctx, w, d, start)
|
||||
}))
|
||||
}
|
||||
|
|
@ -486,7 +480,6 @@ func (o *Site) Delete(ctx context.Context, exec bob.Executor) error {
|
|||
func (o *Site) Reload(ctx context.Context, exec bob.Executor) error {
|
||||
o2, err := Sites.Query(
|
||||
sm.Where(Sites.Columns.ID.EQ(psql.Arg(o.ID))),
|
||||
sm.Where(Sites.Columns.Version.EQ(psql.Arg(o.Version))),
|
||||
).One(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -520,7 +513,7 @@ func (o SiteSlice) pkIN() dialect.Expression {
|
|||
return psql.Raw("NULL")
|
||||
}
|
||||
|
||||
return psql.Group(psql.Quote("site", "id"), psql.Quote("site", "version")).In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
return psql.Quote("site", "id").In(bob.ExpressionFunc(func(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
|
||||
pkPairs := make([]bob.Expression, len(o))
|
||||
for i, row := range o {
|
||||
pkPairs[i] = row.primaryKeyVals()
|
||||
|
|
@ -538,9 +531,6 @@ func (o SiteSlice) copyMatchingRows(from ...*Site) {
|
|||
if new.ID != old.ID {
|
||||
continue
|
||||
}
|
||||
if new.Version != old.Version {
|
||||
continue
|
||||
}
|
||||
new.R = old.R
|
||||
o[i] = new
|
||||
break
|
||||
|
|
@ -642,84 +632,72 @@ func (o SiteSlice) ReloadAll(ctx context.Context, exec bob.Executor) error {
|
|||
// Features starts a query for related objects on feature
|
||||
func (o *Site) Features(mods ...bob.Mod[*dialect.SelectQuery]) FeaturesQuery {
|
||||
return Features.Query(append(mods,
|
||||
sm.Where(Features.Columns.SiteID.EQ(psql.Arg(o.ID))), sm.Where(Features.Columns.SiteVersion.EQ(psql.Arg(o.Version))),
|
||||
sm.Where(Features.Columns.SiteID.EQ(psql.Arg(o.ID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os SiteSlice) Features(mods ...bob.Mod[*dialect.SelectQuery]) FeaturesQuery {
|
||||
pkID := make(pgtypes.Array[int32], 0, len(os))
|
||||
|
||||
pkVersion := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkID = append(pkID, o.ID)
|
||||
pkVersion = append(pkVersion, o.Version)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkVersion), "integer[]")),
|
||||
))
|
||||
|
||||
return Features.Query(append(mods,
|
||||
sm.Where(psql.Group(Features.Columns.SiteID, Features.Columns.SiteVersion).OP("IN", PKArgExpr)),
|
||||
sm.Where(psql.Group(Features.Columns.SiteID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// Leads starts a query for related objects on lead
|
||||
func (o *Site) Leads(mods ...bob.Mod[*dialect.SelectQuery]) LeadsQuery {
|
||||
return Leads.Query(append(mods,
|
||||
sm.Where(Leads.Columns.SiteID.EQ(psql.Arg(o.ID))), sm.Where(Leads.Columns.SiteVersion.EQ(psql.Arg(o.Version))),
|
||||
sm.Where(Leads.Columns.SiteID.EQ(psql.Arg(o.ID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os SiteSlice) Leads(mods ...bob.Mod[*dialect.SelectQuery]) LeadsQuery {
|
||||
pkID := make(pgtypes.Array[int32], 0, len(os))
|
||||
|
||||
pkVersion := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkID = append(pkID, o.ID)
|
||||
pkVersion = append(pkVersion, o.Version)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkVersion), "integer[]")),
|
||||
))
|
||||
|
||||
return Leads.Query(append(mods,
|
||||
sm.Where(psql.Group(Leads.Columns.SiteID, Leads.Columns.SiteVersion).OP("IN", PKArgExpr)),
|
||||
sm.Where(psql.Group(Leads.Columns.SiteID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// Residents starts a query for related objects on resident
|
||||
func (o *Site) Residents(mods ...bob.Mod[*dialect.SelectQuery]) ResidentsQuery {
|
||||
return Residents.Query(append(mods,
|
||||
sm.Where(Residents.Columns.SiteID.EQ(psql.Arg(o.ID))), sm.Where(Residents.Columns.SiteVersion.EQ(psql.Arg(o.Version))),
|
||||
sm.Where(Residents.Columns.SiteID.EQ(psql.Arg(o.ID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os SiteSlice) Residents(mods ...bob.Mod[*dialect.SelectQuery]) ResidentsQuery {
|
||||
pkID := make(pgtypes.Array[int32], 0, len(os))
|
||||
|
||||
pkVersion := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
pkID = append(pkID, o.ID)
|
||||
pkVersion = append(pkVersion, o.Version)
|
||||
}
|
||||
PKArgExpr := psql.Select(sm.Columns(
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkID), "integer[]")),
|
||||
psql.F("unnest", psql.Cast(psql.Arg(pkVersion), "integer[]")),
|
||||
))
|
||||
|
||||
return Residents.Query(append(mods,
|
||||
sm.Where(psql.Group(Residents.Columns.SiteID, Residents.Columns.SiteVersion).OP("IN", PKArgExpr)),
|
||||
sm.Where(psql.Group(Residents.Columns.SiteID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
|
|
@ -822,7 +800,6 @@ func (os SiteSlice) Parcel(mods ...bob.Mod[*dialect.SelectQuery]) ParcelsQuery {
|
|||
func insertSiteFeatures0(ctx context.Context, exec bob.Executor, features1 []*FeatureSetter, site0 *Site) (FeatureSlice, error) {
|
||||
for i := range features1 {
|
||||
features1[i].SiteID = omit.From(site0.ID)
|
||||
features1[i].SiteVersion = omit.From(site0.Version)
|
||||
}
|
||||
|
||||
ret, err := Features.Insert(bob.ToMods(features1...)).All(ctx, exec)
|
||||
|
|
@ -836,7 +813,6 @@ func insertSiteFeatures0(ctx context.Context, exec bob.Executor, features1 []*Fe
|
|||
func attachSiteFeatures0(ctx context.Context, exec bob.Executor, count int, features1 FeatureSlice, site0 *Site) (FeatureSlice, error) {
|
||||
setter := &FeatureSetter{
|
||||
SiteID: omit.From(site0.ID),
|
||||
SiteVersion: omit.From(site0.Version),
|
||||
}
|
||||
|
||||
err := features1.UpdateAll(ctx, exec, *setter)
|
||||
|
|
@ -892,7 +868,6 @@ func (site0 *Site) AttachFeatures(ctx context.Context, exec bob.Executor, relate
|
|||
func insertSiteLeads0(ctx context.Context, exec bob.Executor, leads1 []*LeadSetter, site0 *Site) (LeadSlice, error) {
|
||||
for i := range leads1 {
|
||||
leads1[i].SiteID = omitnull.From(site0.ID)
|
||||
leads1[i].SiteVersion = omitnull.From(site0.Version)
|
||||
}
|
||||
|
||||
ret, err := Leads.Insert(bob.ToMods(leads1...)).All(ctx, exec)
|
||||
|
|
@ -906,7 +881,6 @@ func insertSiteLeads0(ctx context.Context, exec bob.Executor, leads1 []*LeadSett
|
|||
func attachSiteLeads0(ctx context.Context, exec bob.Executor, count int, leads1 LeadSlice, site0 *Site) (LeadSlice, error) {
|
||||
setter := &LeadSetter{
|
||||
SiteID: omitnull.From(site0.ID),
|
||||
SiteVersion: omitnull.From(site0.Version),
|
||||
}
|
||||
|
||||
err := leads1.UpdateAll(ctx, exec, *setter)
|
||||
|
|
@ -962,7 +936,6 @@ func (site0 *Site) AttachLeads(ctx context.Context, exec bob.Executor, related .
|
|||
func insertSiteResidents0(ctx context.Context, exec bob.Executor, residents1 []*ResidentSetter, site0 *Site) (ResidentSlice, error) {
|
||||
for i := range residents1 {
|
||||
residents1[i].SiteID = omit.From(site0.ID)
|
||||
residents1[i].SiteVersion = omit.From(site0.Version)
|
||||
}
|
||||
|
||||
ret, err := Residents.Insert(bob.ToMods(residents1...)).All(ctx, exec)
|
||||
|
|
@ -976,7 +949,6 @@ func insertSiteResidents0(ctx context.Context, exec bob.Executor, residents1 []*
|
|||
func attachSiteResidents0(ctx context.Context, exec bob.Executor, count int, residents1 ResidentSlice, site0 *Site) (ResidentSlice, error) {
|
||||
setter := &ResidentSetter{
|
||||
SiteID: omit.From(site0.ID),
|
||||
SiteVersion: omit.From(site0.Version),
|
||||
}
|
||||
|
||||
err := residents1.UpdateAll(ctx, exec, *setter)
|
||||
|
|
@ -1555,10 +1527,6 @@ func (os SiteSlice) LoadFeatures(ctx context.Context, exec bob.Executor, mods ..
|
|||
continue
|
||||
}
|
||||
|
||||
if !(o.Version == rel.SiteVersion) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.Site = o
|
||||
|
||||
o.R.Features = append(o.R.Features, rel)
|
||||
|
|
@ -1623,13 +1591,6 @@ func (os SiteSlice) LoadLeads(ctx context.Context, exec bob.Executor, mods ...bo
|
|||
continue
|
||||
}
|
||||
|
||||
if !rel.SiteVersion.IsValue() {
|
||||
continue
|
||||
}
|
||||
if !(rel.SiteVersion.IsValue() && o.Version == rel.SiteVersion.MustGet()) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.Site = o
|
||||
|
||||
o.R.Leads = append(o.R.Leads, rel)
|
||||
|
|
@ -1691,10 +1652,6 @@ func (os SiteSlice) LoadResidents(ctx context.Context, exec bob.Executor, mods .
|
|||
continue
|
||||
}
|
||||
|
||||
if !(o.Version == rel.SiteVersion) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.Site = o
|
||||
|
||||
o.R.Residents = append(o.R.Residents, rel)
|
||||
|
|
|
|||
|
|
@ -68,6 +68,8 @@ type userR struct {
|
|||
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
|
||||
ReviewerNuisances PublicreportNuisanceSlice // publicreport.nuisance.nuisance_reviewer_id_fkey
|
||||
ReviewerWaters PublicreportWaterSlice // publicreport.water.water_reviewer_id_fkey
|
||||
CreatorResidents ResidentSlice // resident.resident_creator_fkey
|
||||
CreatorReviewTasks ReviewTaskSlice // review_task.review_task_creator_id_fkey
|
||||
ReviewerReviewTasks ReviewTaskSlice // review_task.review_task_reviewer_id_fkey
|
||||
|
|
@ -955,6 +957,54 @@ func (os UserSlice) UserNotifications(mods ...bob.Mod[*dialect.SelectQuery]) Not
|
|||
)...)
|
||||
}
|
||||
|
||||
// ReviewerNuisances starts a query for related objects on publicreport.nuisance
|
||||
func (o *User) ReviewerNuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisancesQuery {
|
||||
return PublicreportNuisances.Query(append(mods,
|
||||
sm.Where(PublicreportNuisances.Columns.ReviewerID.EQ(psql.Arg(o.ID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os UserSlice) ReviewerNuisances(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportNuisancesQuery {
|
||||
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 PublicreportNuisances.Query(append(mods,
|
||||
sm.Where(psql.Group(PublicreportNuisances.Columns.ReviewerID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// ReviewerWaters starts a query for related objects on publicreport.water
|
||||
func (o *User) ReviewerWaters(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWatersQuery {
|
||||
return PublicreportWaters.Query(append(mods,
|
||||
sm.Where(PublicreportWaters.Columns.ReviewerID.EQ(psql.Arg(o.ID))),
|
||||
)...)
|
||||
}
|
||||
|
||||
func (os UserSlice) ReviewerWaters(mods ...bob.Mod[*dialect.SelectQuery]) PublicreportWatersQuery {
|
||||
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 PublicreportWaters.Query(append(mods,
|
||||
sm.Where(psql.Group(PublicreportWaters.Columns.ReviewerID).OP("IN", PKArgExpr)),
|
||||
)...)
|
||||
}
|
||||
|
||||
// CreatorResidents starts a query for related objects on resident
|
||||
func (o *User) CreatorResidents(mods ...bob.Mod[*dialect.SelectQuery]) ResidentsQuery {
|
||||
return Residents.Query(append(mods,
|
||||
|
|
@ -2007,6 +2057,142 @@ func (user0 *User) AttachUserNotifications(ctx context.Context, exec bob.Executo
|
|||
return nil
|
||||
}
|
||||
|
||||
func insertUserReviewerNuisances0(ctx context.Context, exec bob.Executor, publicreportNuisances1 []*PublicreportNuisanceSetter, user0 *User) (PublicreportNuisanceSlice, error) {
|
||||
for i := range publicreportNuisances1 {
|
||||
publicreportNuisances1[i].ReviewerID = omitnull.From(user0.ID)
|
||||
}
|
||||
|
||||
ret, err := PublicreportNuisances.Insert(bob.ToMods(publicreportNuisances1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertUserReviewerNuisances0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachUserReviewerNuisances0(ctx context.Context, exec bob.Executor, count int, publicreportNuisances1 PublicreportNuisanceSlice, user0 *User) (PublicreportNuisanceSlice, error) {
|
||||
setter := &PublicreportNuisanceSetter{
|
||||
ReviewerID: omitnull.From(user0.ID),
|
||||
}
|
||||
|
||||
err := publicreportNuisances1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachUserReviewerNuisances0: %w", err)
|
||||
}
|
||||
|
||||
return publicreportNuisances1, nil
|
||||
}
|
||||
|
||||
func (user0 *User) InsertReviewerNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNuisanceSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
publicreportNuisances1, err := insertUserReviewerNuisances0(ctx, exec, related, user0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
user0.R.ReviewerNuisances = append(user0.R.ReviewerNuisances, publicreportNuisances1...)
|
||||
|
||||
for _, rel := range publicreportNuisances1 {
|
||||
rel.R.ReviewerUser = user0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (user0 *User) AttachReviewerNuisances(ctx context.Context, exec bob.Executor, related ...*PublicreportNuisance) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
publicreportNuisances1 := PublicreportNuisanceSlice(related)
|
||||
|
||||
_, err = attachUserReviewerNuisances0(ctx, exec, len(related), publicreportNuisances1, user0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
user0.R.ReviewerNuisances = append(user0.R.ReviewerNuisances, publicreportNuisances1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.ReviewerUser = user0
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertUserReviewerWaters0(ctx context.Context, exec bob.Executor, publicreportWaters1 []*PublicreportWaterSetter, user0 *User) (PublicreportWaterSlice, error) {
|
||||
for i := range publicreportWaters1 {
|
||||
publicreportWaters1[i].ReviewerID = omitnull.From(user0.ID)
|
||||
}
|
||||
|
||||
ret, err := PublicreportWaters.Insert(bob.ToMods(publicreportWaters1...)).All(ctx, exec)
|
||||
if err != nil {
|
||||
return ret, fmt.Errorf("insertUserReviewerWaters0: %w", err)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func attachUserReviewerWaters0(ctx context.Context, exec bob.Executor, count int, publicreportWaters1 PublicreportWaterSlice, user0 *User) (PublicreportWaterSlice, error) {
|
||||
setter := &PublicreportWaterSetter{
|
||||
ReviewerID: omitnull.From(user0.ID),
|
||||
}
|
||||
|
||||
err := publicreportWaters1.UpdateAll(ctx, exec, *setter)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("attachUserReviewerWaters0: %w", err)
|
||||
}
|
||||
|
||||
return publicreportWaters1, nil
|
||||
}
|
||||
|
||||
func (user0 *User) InsertReviewerWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportWaterSetter) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
publicreportWaters1, err := insertUserReviewerWaters0(ctx, exec, related, user0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
user0.R.ReviewerWaters = append(user0.R.ReviewerWaters, publicreportWaters1...)
|
||||
|
||||
for _, rel := range publicreportWaters1 {
|
||||
rel.R.ReviewerUser = user0
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (user0 *User) AttachReviewerWaters(ctx context.Context, exec bob.Executor, related ...*PublicreportWater) error {
|
||||
if len(related) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
publicreportWaters1 := PublicreportWaterSlice(related)
|
||||
|
||||
_, err = attachUserReviewerWaters0(ctx, exec, len(related), publicreportWaters1, user0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
user0.R.ReviewerWaters = append(user0.R.ReviewerWaters, publicreportWaters1...)
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.ReviewerUser = user0
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertUserCreatorResidents0(ctx context.Context, exec bob.Executor, residents1 []*ResidentSetter, user0 *User) (ResidentSlice, error) {
|
||||
for i := range residents1 {
|
||||
residents1[i].Creator = omit.From(user0.ID)
|
||||
|
|
@ -2689,6 +2875,34 @@ func (o *User) Preload(name string, retrieved any) error {
|
|||
}
|
||||
}
|
||||
return nil
|
||||
case "ReviewerNuisances":
|
||||
rels, ok := retrieved.(PublicreportNuisanceSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("user cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.ReviewerNuisances = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
rel.R.ReviewerUser = o
|
||||
}
|
||||
}
|
||||
return nil
|
||||
case "ReviewerWaters":
|
||||
rels, ok := retrieved.(PublicreportWaterSlice)
|
||||
if !ok {
|
||||
return fmt.Errorf("user cannot load %T as %q", retrieved, name)
|
||||
}
|
||||
|
||||
o.R.ReviewerWaters = rels
|
||||
|
||||
for _, rel := range rels {
|
||||
if rel != nil {
|
||||
rel.R.ReviewerUser = o
|
||||
}
|
||||
}
|
||||
return nil
|
||||
case "CreatorResidents":
|
||||
rels, ok := retrieved.(ResidentSlice)
|
||||
if !ok {
|
||||
|
|
@ -2826,6 +3040,8 @@ type userThenLoader[Q orm.Loadable] struct {
|
|||
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]
|
||||
ReviewerNuisances func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
ReviewerWaters func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
CreatorResidents func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
CreatorReviewTasks func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
ReviewerReviewTasks func(...bob.Mod[*dialect.SelectQuery]) orm.Loader[Q]
|
||||
|
|
@ -2875,6 +3091,12 @@ func buildUserThenLoader[Q orm.Loadable]() userThenLoader[Q] {
|
|||
type UserNotificationsLoadInterface interface {
|
||||
LoadUserNotifications(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type ReviewerNuisancesLoadInterface interface {
|
||||
LoadReviewerNuisances(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type ReviewerWatersLoadInterface interface {
|
||||
LoadReviewerWaters(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
type CreatorResidentsLoadInterface interface {
|
||||
LoadCreatorResidents(context.Context, bob.Executor, ...bob.Mod[*dialect.SelectQuery]) error
|
||||
}
|
||||
|
|
@ -2976,6 +3198,18 @@ func buildUserThenLoader[Q orm.Loadable]() userThenLoader[Q] {
|
|||
return retrieved.LoadUserNotifications(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
ReviewerNuisances: thenLoadBuilder[Q](
|
||||
"ReviewerNuisances",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ReviewerNuisancesLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadReviewerNuisances(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
ReviewerWaters: thenLoadBuilder[Q](
|
||||
"ReviewerWaters",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved ReviewerWatersLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
return retrieved.LoadReviewerWaters(ctx, exec, mods...)
|
||||
},
|
||||
),
|
||||
CreatorResidents: thenLoadBuilder[Q](
|
||||
"CreatorResidents",
|
||||
func(ctx context.Context, exec bob.Executor, retrieved CreatorResidentsLoadInterface, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
|
|
@ -3823,6 +4057,134 @@ func (os UserSlice) LoadUserNotifications(ctx context.Context, exec bob.Executor
|
|||
return nil
|
||||
}
|
||||
|
||||
// LoadReviewerNuisances loads the user's ReviewerNuisances into the .R struct
|
||||
func (o *User) LoadReviewerNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.ReviewerNuisances = nil
|
||||
|
||||
related, err := o.ReviewerNuisances(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.ReviewerUser = o
|
||||
}
|
||||
|
||||
o.R.ReviewerNuisances = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadReviewerNuisances loads the user's ReviewerNuisances into the .R struct
|
||||
func (os UserSlice) LoadReviewerNuisances(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
publicreportNuisances, err := os.ReviewerNuisances(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
o.R.ReviewerNuisances = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range publicreportNuisances {
|
||||
|
||||
if !rel.ReviewerID.IsValue() {
|
||||
continue
|
||||
}
|
||||
if !(rel.ReviewerID.IsValue() && o.ID == rel.ReviewerID.MustGet()) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.ReviewerUser = o
|
||||
|
||||
o.R.ReviewerNuisances = append(o.R.ReviewerNuisances, rel)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadReviewerWaters loads the user's ReviewerWaters into the .R struct
|
||||
func (o *User) LoadReviewerWaters(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset the relationship
|
||||
o.R.ReviewerWaters = nil
|
||||
|
||||
related, err := o.ReviewerWaters(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, rel := range related {
|
||||
rel.R.ReviewerUser = o
|
||||
}
|
||||
|
||||
o.R.ReviewerWaters = related
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadReviewerWaters loads the user's ReviewerWaters into the .R struct
|
||||
func (os UserSlice) LoadReviewerWaters(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if len(os) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
publicreportWaters, err := os.ReviewerWaters(mods...).All(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
o.R.ReviewerWaters = nil
|
||||
}
|
||||
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, rel := range publicreportWaters {
|
||||
|
||||
if !rel.ReviewerID.IsValue() {
|
||||
continue
|
||||
}
|
||||
if !(rel.ReviewerID.IsValue() && o.ID == rel.ReviewerID.MustGet()) {
|
||||
continue
|
||||
}
|
||||
|
||||
rel.R.ReviewerUser = o
|
||||
|
||||
o.R.ReviewerWaters = append(o.R.ReviewerWaters, rel)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadCreatorResidents loads the user's CreatorResidents into the .R struct
|
||||
func (o *User) LoadCreatorResidents(ctx context.Context, exec bob.Executor, mods ...bob.Mod[*dialect.SelectQuery]) error {
|
||||
if o == nil {
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
-- UserByUsername
|
||||
SELECT * FROM public.user_ WHERE
|
||||
username = $1 AND
|
||||
password_hash_type = 'bcrypt-14';
|
||||
Loading…
Add table
Add a link
Reference in a new issue