Pull notifications from the database
Previously we were storing them, just not showing them.
This commit is contained in:
parent
337e5f7a7d
commit
bf3dedf7cd
18 changed files with 905 additions and 586 deletions
|
|
@ -458,9 +458,10 @@ func markTokenFailed(ctx context.Context, oauth *models.OauthToken) {
|
|||
return
|
||||
}
|
||||
notificationSetter := models.NotificationSetter{
|
||||
Message: omitnull.From("Oauth token invalidated"),
|
||||
Link: omitnull.From("/oauth/refresh"),
|
||||
Type: omitnull.From(enums.NotificationtypeOauthTokenInvalidated),
|
||||
Created: omit.From(time.Now()),
|
||||
Message: omit.From("Oauth token invalidated"),
|
||||
Link: omit.From("/oauth/refresh"),
|
||||
Type: omit.From(enums.NotificationtypeOauthTokenInvalidated),
|
||||
}
|
||||
err = user.InsertUserNotifications(ctx, PGInstance.BobDB, ¬ificationSetter)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -429,6 +429,15 @@ var HistoryPolygonlocations = Table[
|
|||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
Created: column{
|
||||
Name: "created",
|
||||
DBType: "timestamp without time zone",
|
||||
Default: "NULL",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
},
|
||||
Indexes: historyPolygonlocationIndexes{
|
||||
HistoryPolygonlocationPkey: index{
|
||||
|
|
@ -521,11 +530,12 @@ type historyPolygonlocationColumns struct {
|
|||
GeometryX column
|
||||
GeometryY column
|
||||
Version column
|
||||
Created column
|
||||
}
|
||||
|
||||
func (c historyPolygonlocationColumns) AsSlice() []column {
|
||||
return []column{
|
||||
c.OrganizationID, c.Accessdesc, c.Acres, c.Active, c.Comments, c.Creationdate, c.Creator, c.Description, c.Externalid, c.Editdate, c.Editor, c.Filter, c.Globalid, c.Habitat, c.Hectares, c.Jurisdiction, c.Larvinspectinterval, c.Lastinspectactiontaken, c.Lastinspectactivity, c.Lastinspectavglarvae, c.Lastinspectavgpupae, c.Lastinspectbreeding, c.Lastinspectconditions, c.Lastinspectdate, c.Lastinspectfieldspecies, c.Lastinspectlstages, c.Lasttreatactivity, c.Lasttreatdate, c.Lasttreatproduct, c.Lasttreatqty, c.Lasttreatqtyunit, c.Locationnumber, c.Name, c.Nextactiondatescheduled, c.Objectid, c.Priority, c.Symbology, c.ShapeArea, c.ShapeLength, c.Usetype, c.Waterorigin, c.Zone, c.Zone2, c.GeometryX, c.GeometryY, c.Version,
|
||||
c.OrganizationID, c.Accessdesc, c.Acres, c.Active, c.Comments, c.Creationdate, c.Creator, c.Description, c.Externalid, c.Editdate, c.Editor, c.Filter, c.Globalid, c.Habitat, c.Hectares, c.Jurisdiction, c.Larvinspectinterval, c.Lastinspectactiontaken, c.Lastinspectactivity, c.Lastinspectavglarvae, c.Lastinspectavgpupae, c.Lastinspectbreeding, c.Lastinspectconditions, c.Lastinspectdate, c.Lastinspectfieldspecies, c.Lastinspectlstages, c.Lasttreatactivity, c.Lasttreatdate, c.Lasttreatproduct, c.Lasttreatqty, c.Lasttreatqtyunit, c.Locationnumber, c.Name, c.Nextactiondatescheduled, c.Objectid, c.Priority, c.Symbology, c.ShapeArea, c.ShapeLength, c.Usetype, c.Waterorigin, c.Zone, c.Zone2, c.GeometryX, c.GeometryY, c.Version, c.Created,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -348,6 +348,15 @@ var HistoryProposedtreatmentareas = Table[
|
|||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
Created: column{
|
||||
Name: "created",
|
||||
DBType: "timestamp without time zone",
|
||||
Default: "NULL",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
},
|
||||
Indexes: historyProposedtreatmentareaIndexes{
|
||||
HistoryProposedtreatmentareaPkey: index{
|
||||
|
|
@ -431,11 +440,12 @@ type historyProposedtreatmentareaColumns struct {
|
|||
GeometryX column
|
||||
GeometryY column
|
||||
Version column
|
||||
Created column
|
||||
}
|
||||
|
||||
func (c historyProposedtreatmentareaColumns) AsSlice() []column {
|
||||
return []column{
|
||||
c.OrganizationID, c.Acres, c.Comments, c.Completed, c.Completedby, c.Completeddate, c.Creationdate, c.Creator, c.Duedate, c.Exported, c.Editdate, c.Editor, c.Globalid, c.Hectares, c.Issprayroute, c.Lasttreatactivity, c.Lasttreatdate, c.Lasttreatproduct, c.Lasttreatqty, c.Lasttreatqtyunit, c.Method, c.Name, c.Objectid, c.Priority, c.Reviewed, c.Reviewedby, c.Revieweddate, c.ShapeArea, c.ShapeLength, c.Targetapprate, c.Targetproduct, c.Targetspecies, c.Zone, c.Zone2, c.GeometryX, c.GeometryY, c.Version,
|
||||
c.OrganizationID, c.Acres, c.Comments, c.Completed, c.Completedby, c.Completeddate, c.Creationdate, c.Creator, c.Duedate, c.Exported, c.Editdate, c.Editor, c.Globalid, c.Hectares, c.Issprayroute, c.Lasttreatactivity, c.Lasttreatdate, c.Lasttreatproduct, c.Lasttreatqty, c.Lasttreatqtyunit, c.Method, c.Name, c.Objectid, c.Priority, c.Reviewed, c.Reviewedby, c.Revieweddate, c.ShapeArea, c.ShapeLength, c.Targetapprate, c.Targetproduct, c.Targetspecies, c.Zone, c.Zone2, c.GeometryX, c.GeometryY, c.Version, c.Created,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -537,6 +537,15 @@ var HistoryTreatments = Table[
|
|||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
Created: column{
|
||||
Name: "created",
|
||||
DBType: "timestamp without time zone",
|
||||
Default: "NULL",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
},
|
||||
Indexes: historyTreatmentIndexes{
|
||||
HistoryTreatmentPkey: index{
|
||||
|
|
@ -641,11 +650,12 @@ type historyTreatmentColumns struct {
|
|||
GeometryY column
|
||||
TempSitecond column
|
||||
Version column
|
||||
Created column
|
||||
}
|
||||
|
||||
func (c historyTreatmentColumns) AsSlice() []column {
|
||||
return []column{
|
||||
c.OrganizationID, c.Activity, c.Areaunit, c.Avetemp, c.Barrierrouteid, c.Cbcount, c.Comments, c.Containercount, c.Creationdate, c.Creator, c.Enddatetime, c.Equiptype, c.Editdate, c.Editor, c.Fieldtech, c.Flowrate, c.Globalid, c.Habitat, c.InspID, c.Invloc, c.Linelocid, c.Locationname, c.Method, c.Objectid, c.Pointlocid, c.Polygonlocid, c.Product, c.Ptaid, c.Qty, c.Qtyunit, c.Raingauge, c.Recordstatus, c.Reviewed, c.Reviewedby, c.Revieweddate, c.Sdid, c.Sitecond, c.Srid, c.Startdatetime, c.Targetspecies, c.Tirecount, c.Treatacres, c.Treatarea, c.Treathectares, c.Treatmenthours, c.Treatmentlength, c.Treatmentlengthunits, c.Totalcostprodcut, c.Ulvrouteid, c.Warningoverride, c.Winddir, c.Windspeed, c.Zone, c.Zone2, c.GeometryX, c.GeometryY, c.TempSitecond, c.Version,
|
||||
c.OrganizationID, c.Activity, c.Areaunit, c.Avetemp, c.Barrierrouteid, c.Cbcount, c.Comments, c.Containercount, c.Creationdate, c.Creator, c.Enddatetime, c.Equiptype, c.Editdate, c.Editor, c.Fieldtech, c.Flowrate, c.Globalid, c.Habitat, c.InspID, c.Invloc, c.Linelocid, c.Locationname, c.Method, c.Objectid, c.Pointlocid, c.Polygonlocid, c.Product, c.Ptaid, c.Qty, c.Qtyunit, c.Raingauge, c.Recordstatus, c.Reviewed, c.Reviewedby, c.Revieweddate, c.Sdid, c.Sitecond, c.Srid, c.Startdatetime, c.Targetspecies, c.Tirecount, c.Treatacres, c.Treatarea, c.Treathectares, c.Treatmenthours, c.Treatmentlength, c.Treatmentlengthunits, c.Totalcostprodcut, c.Ulvrouteid, c.Warningoverride, c.Winddir, c.Windspeed, c.Zone, c.Zone2, c.GeometryX, c.GeometryY, c.TempSitecond, c.Version, c.Created,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,39 +24,48 @@ var Notifications = Table[
|
|||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
UserID: column{
|
||||
Name: "user_id",
|
||||
DBType: "integer",
|
||||
Default: "NULL",
|
||||
Created: column{
|
||||
Name: "created",
|
||||
DBType: "timestamp without time zone",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
Message: column{
|
||||
Name: "message",
|
||||
DBType: "text",
|
||||
Default: "NULL",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
Link: column{
|
||||
Name: "link",
|
||||
DBType: "text",
|
||||
Default: "NULL",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
Message: column{
|
||||
Name: "message",
|
||||
DBType: "text",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
Type: column{
|
||||
Name: "type",
|
||||
DBType: "public.notificationtype",
|
||||
Default: "NULL",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: true,
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
UserID: column{
|
||||
Name: "user_id",
|
||||
DBType: "integer",
|
||||
Default: "",
|
||||
Comment: "",
|
||||
Nullable: false,
|
||||
Generated: false,
|
||||
AutoIncr: false,
|
||||
},
|
||||
|
|
@ -102,15 +111,16 @@ var Notifications = Table[
|
|||
|
||||
type notificationColumns struct {
|
||||
ID column
|
||||
UserID column
|
||||
Message column
|
||||
Created column
|
||||
Link column
|
||||
Message column
|
||||
Type column
|
||||
UserID column
|
||||
}
|
||||
|
||||
func (c notificationColumns) AsSlice() []column {
|
||||
return []column{
|
||||
c.ID, c.UserID, c.Message, c.Link, c.Type,
|
||||
c.ID, c.Created, c.Link, c.Message, c.Type, c.UserID,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2453,6 +2453,7 @@ func (f *Factory) FromExistingHistoryPolygonlocation(m *models.HistoryPolygonloc
|
|||
o.GeometryX = func() null.Val[float64] { return m.GeometryX }
|
||||
o.GeometryY = func() null.Val[float64] { return m.GeometryY }
|
||||
o.Version = func() int32 { return m.Version }
|
||||
o.Created = func() null.Val[time.Time] { return m.Created }
|
||||
|
||||
ctx := context.Background()
|
||||
if m.R.Organization != nil {
|
||||
|
|
@ -2626,6 +2627,7 @@ func (f *Factory) FromExistingHistoryProposedtreatmentarea(m *models.HistoryProp
|
|||
o.GeometryX = func() null.Val[float64] { return m.GeometryX }
|
||||
o.GeometryY = func() null.Val[float64] { return m.GeometryY }
|
||||
o.Version = func() int32 { return m.Version }
|
||||
o.Created = func() null.Val[time.Time] { return m.Created }
|
||||
|
||||
ctx := context.Background()
|
||||
if m.R.Organization != nil {
|
||||
|
|
@ -3438,6 +3440,7 @@ func (f *Factory) FromExistingHistoryTreatment(m *models.HistoryTreatment) *Hist
|
|||
o.GeometryY = func() null.Val[float64] { return m.GeometryY }
|
||||
o.TempSitecond = func() null.Val[string] { return m.TempSitecond }
|
||||
o.Version = func() int32 { return m.Version }
|
||||
o.Created = func() null.Val[time.Time] { return m.Created }
|
||||
|
||||
ctx := context.Background()
|
||||
if m.R.Organization != nil {
|
||||
|
|
@ -3611,10 +3614,11 @@ func (f *Factory) FromExistingNotification(m *models.Notification) *Notification
|
|||
o := &NotificationTemplate{f: f, alreadyPersisted: true}
|
||||
|
||||
o.ID = func() int32 { return m.ID }
|
||||
o.UserID = func() null.Val[int32] { return m.UserID }
|
||||
o.Message = func() null.Val[string] { return m.Message }
|
||||
o.Link = func() null.Val[string] { return m.Link }
|
||||
o.Type = func() null.Val[enums.Notificationtype] { return m.Type }
|
||||
o.Created = func() time.Time { return m.Created }
|
||||
o.Link = func() string { return m.Link }
|
||||
o.Message = func() string { return m.Message }
|
||||
o.Type = func() enums.Notificationtype { return m.Type }
|
||||
o.UserID = func() int32 { return m.UserID }
|
||||
|
||||
ctx := context.Background()
|
||||
if m.R.UserUser != nil {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ package factory
|
|||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
models "github.com/Gleipnir-Technology/nidus-sync/models"
|
||||
"github.com/aarondl/opt/null"
|
||||
|
|
@ -82,6 +83,7 @@ type HistoryPolygonlocationTemplate struct {
|
|||
GeometryX func() null.Val[float64]
|
||||
GeometryY func() null.Val[float64]
|
||||
Version func() int32
|
||||
Created func() null.Val[time.Time]
|
||||
|
||||
r historyPolygonlocationR
|
||||
f *Factory
|
||||
|
|
@ -304,6 +306,10 @@ func (o HistoryPolygonlocationTemplate) BuildSetter() *models.HistoryPolygonloca
|
|||
val := o.Version()
|
||||
m.Version = omit.From(val)
|
||||
}
|
||||
if o.Created != nil {
|
||||
val := o.Created()
|
||||
m.Created = omitnull.FromNull(val)
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
|
@ -464,6 +470,9 @@ func (o HistoryPolygonlocationTemplate) Build() *models.HistoryPolygonlocation {
|
|||
if o.Version != nil {
|
||||
m.Version = o.Version()
|
||||
}
|
||||
if o.Created != nil {
|
||||
m.Created = o.Created()
|
||||
}
|
||||
|
||||
o.setModelRels(m)
|
||||
|
||||
|
|
@ -661,6 +670,7 @@ func (m historyPolygonlocationMods) RandomizeAllColumns(f *faker.Faker) HistoryP
|
|||
HistoryPolygonlocationMods.RandomGeometryX(f),
|
||||
HistoryPolygonlocationMods.RandomGeometryY(f),
|
||||
HistoryPolygonlocationMods.RandomVersion(f),
|
||||
HistoryPolygonlocationMods.RandomCreated(f),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -3036,6 +3046,59 @@ func (m historyPolygonlocationMods) RandomVersion(f *faker.Faker) HistoryPolygon
|
|||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m historyPolygonlocationMods) Created(val null.Val[time.Time]) HistoryPolygonlocationMod {
|
||||
return HistoryPolygonlocationModFunc(func(_ context.Context, o *HistoryPolygonlocationTemplate) {
|
||||
o.Created = func() null.Val[time.Time] { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m historyPolygonlocationMods) CreatedFunc(f func() null.Val[time.Time]) HistoryPolygonlocationMod {
|
||||
return HistoryPolygonlocationModFunc(func(_ context.Context, o *HistoryPolygonlocationTemplate) {
|
||||
o.Created = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m historyPolygonlocationMods) UnsetCreated() HistoryPolygonlocationMod {
|
||||
return HistoryPolygonlocationModFunc(func(_ context.Context, o *HistoryPolygonlocationTemplate) {
|
||||
o.Created = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is sometimes null
|
||||
func (m historyPolygonlocationMods) RandomCreated(f *faker.Faker) HistoryPolygonlocationMod {
|
||||
return HistoryPolygonlocationModFunc(func(_ context.Context, o *HistoryPolygonlocationTemplate) {
|
||||
o.Created = func() null.Val[time.Time] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_time_Time(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is never null
|
||||
func (m historyPolygonlocationMods) RandomCreatedNotNull(f *faker.Faker) HistoryPolygonlocationMod {
|
||||
return HistoryPolygonlocationModFunc(func(_ context.Context, o *HistoryPolygonlocationTemplate) {
|
||||
o.Created = func() null.Val[time.Time] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_time_Time(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m historyPolygonlocationMods) WithParentsCascading() HistoryPolygonlocationMod {
|
||||
return HistoryPolygonlocationModFunc(func(ctx context.Context, o *HistoryPolygonlocationTemplate) {
|
||||
if isDone, _ := historyPolygonlocationWithParentsCascadingCtx.Value(ctx); isDone {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ package factory
|
|||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
models "github.com/Gleipnir-Technology/nidus-sync/models"
|
||||
"github.com/aarondl/opt/null"
|
||||
|
|
@ -73,6 +74,7 @@ type HistoryProposedtreatmentareaTemplate struct {
|
|||
GeometryX func() null.Val[float64]
|
||||
GeometryY func() null.Val[float64]
|
||||
Version func() int32
|
||||
Created func() null.Val[time.Time]
|
||||
|
||||
r historyProposedtreatmentareaR
|
||||
f *Factory
|
||||
|
|
@ -259,6 +261,10 @@ func (o HistoryProposedtreatmentareaTemplate) BuildSetter() *models.HistoryPropo
|
|||
val := o.Version()
|
||||
m.Version = omit.From(val)
|
||||
}
|
||||
if o.Created != nil {
|
||||
val := o.Created()
|
||||
m.Created = omitnull.FromNull(val)
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
|
@ -392,6 +398,9 @@ func (o HistoryProposedtreatmentareaTemplate) Build() *models.HistoryProposedtre
|
|||
if o.Version != nil {
|
||||
m.Version = o.Version()
|
||||
}
|
||||
if o.Created != nil {
|
||||
m.Created = o.Created()
|
||||
}
|
||||
|
||||
o.setModelRels(m)
|
||||
|
||||
|
|
@ -580,6 +589,7 @@ func (m historyProposedtreatmentareaMods) RandomizeAllColumns(f *faker.Faker) Hi
|
|||
HistoryProposedtreatmentareaMods.RandomGeometryX(f),
|
||||
HistoryProposedtreatmentareaMods.RandomGeometryY(f),
|
||||
HistoryProposedtreatmentareaMods.RandomVersion(f),
|
||||
HistoryProposedtreatmentareaMods.RandomCreated(f),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2478,6 +2488,59 @@ func (m historyProposedtreatmentareaMods) RandomVersion(f *faker.Faker) HistoryP
|
|||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m historyProposedtreatmentareaMods) Created(val null.Val[time.Time]) HistoryProposedtreatmentareaMod {
|
||||
return HistoryProposedtreatmentareaModFunc(func(_ context.Context, o *HistoryProposedtreatmentareaTemplate) {
|
||||
o.Created = func() null.Val[time.Time] { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m historyProposedtreatmentareaMods) CreatedFunc(f func() null.Val[time.Time]) HistoryProposedtreatmentareaMod {
|
||||
return HistoryProposedtreatmentareaModFunc(func(_ context.Context, o *HistoryProposedtreatmentareaTemplate) {
|
||||
o.Created = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m historyProposedtreatmentareaMods) UnsetCreated() HistoryProposedtreatmentareaMod {
|
||||
return HistoryProposedtreatmentareaModFunc(func(_ context.Context, o *HistoryProposedtreatmentareaTemplate) {
|
||||
o.Created = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is sometimes null
|
||||
func (m historyProposedtreatmentareaMods) RandomCreated(f *faker.Faker) HistoryProposedtreatmentareaMod {
|
||||
return HistoryProposedtreatmentareaModFunc(func(_ context.Context, o *HistoryProposedtreatmentareaTemplate) {
|
||||
o.Created = func() null.Val[time.Time] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_time_Time(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is never null
|
||||
func (m historyProposedtreatmentareaMods) RandomCreatedNotNull(f *faker.Faker) HistoryProposedtreatmentareaMod {
|
||||
return HistoryProposedtreatmentareaModFunc(func(_ context.Context, o *HistoryProposedtreatmentareaTemplate) {
|
||||
o.Created = func() null.Val[time.Time] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_time_Time(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m historyProposedtreatmentareaMods) WithParentsCascading() HistoryProposedtreatmentareaMod {
|
||||
return HistoryProposedtreatmentareaModFunc(func(ctx context.Context, o *HistoryProposedtreatmentareaTemplate) {
|
||||
if isDone, _ := historyProposedtreatmentareaWithParentsCascadingCtx.Value(ctx); isDone {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ package factory
|
|||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
models "github.com/Gleipnir-Technology/nidus-sync/models"
|
||||
"github.com/aarondl/opt/null"
|
||||
|
|
@ -94,6 +95,7 @@ type HistoryTreatmentTemplate struct {
|
|||
GeometryY func() null.Val[float64]
|
||||
TempSitecond func() null.Val[string]
|
||||
Version func() int32
|
||||
Created func() null.Val[time.Time]
|
||||
|
||||
r historyTreatmentR
|
||||
f *Factory
|
||||
|
|
@ -364,6 +366,10 @@ func (o HistoryTreatmentTemplate) BuildSetter() *models.HistoryTreatmentSetter {
|
|||
val := o.Version()
|
||||
m.Version = omit.From(val)
|
||||
}
|
||||
if o.Created != nil {
|
||||
val := o.Created()
|
||||
m.Created = omitnull.FromNull(val)
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
|
@ -560,6 +566,9 @@ func (o HistoryTreatmentTemplate) Build() *models.HistoryTreatment {
|
|||
if o.Version != nil {
|
||||
m.Version = o.Version()
|
||||
}
|
||||
if o.Created != nil {
|
||||
m.Created = o.Created()
|
||||
}
|
||||
|
||||
o.setModelRels(m)
|
||||
|
||||
|
|
@ -769,6 +778,7 @@ func (m historyTreatmentMods) RandomizeAllColumns(f *faker.Faker) HistoryTreatme
|
|||
HistoryTreatmentMods.RandomGeometryY(f),
|
||||
HistoryTreatmentMods.RandomTempSitecond(f),
|
||||
HistoryTreatmentMods.RandomVersion(f),
|
||||
HistoryTreatmentMods.RandomCreated(f),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -3780,6 +3790,59 @@ func (m historyTreatmentMods) RandomVersion(f *faker.Faker) HistoryTreatmentMod
|
|||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m historyTreatmentMods) Created(val null.Val[time.Time]) HistoryTreatmentMod {
|
||||
return HistoryTreatmentModFunc(func(_ context.Context, o *HistoryTreatmentTemplate) {
|
||||
o.Created = func() null.Val[time.Time] { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m historyTreatmentMods) CreatedFunc(f func() null.Val[time.Time]) HistoryTreatmentMod {
|
||||
return HistoryTreatmentModFunc(func(_ context.Context, o *HistoryTreatmentTemplate) {
|
||||
o.Created = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m historyTreatmentMods) UnsetCreated() HistoryTreatmentMod {
|
||||
return HistoryTreatmentModFunc(func(_ context.Context, o *HistoryTreatmentTemplate) {
|
||||
o.Created = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is sometimes null
|
||||
func (m historyTreatmentMods) RandomCreated(f *faker.Faker) HistoryTreatmentMod {
|
||||
return HistoryTreatmentModFunc(func(_ context.Context, o *HistoryTreatmentTemplate) {
|
||||
o.Created = func() null.Val[time.Time] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_time_Time(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is never null
|
||||
func (m historyTreatmentMods) RandomCreatedNotNull(f *faker.Faker) HistoryTreatmentMod {
|
||||
return HistoryTreatmentModFunc(func(_ context.Context, o *HistoryTreatmentTemplate) {
|
||||
o.Created = func() null.Val[time.Time] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_time_Time(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (m historyTreatmentMods) WithParentsCascading() HistoryTreatmentMod {
|
||||
return HistoryTreatmentModFunc(func(ctx context.Context, o *HistoryTreatmentTemplate) {
|
||||
if isDone, _ := historyTreatmentWithParentsCascadingCtx.Value(ctx); isDone {
|
||||
|
|
|
|||
|
|
@ -6,12 +6,11 @@ package factory
|
|||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
enums "github.com/Gleipnir-Technology/nidus-sync/enums"
|
||||
models "github.com/Gleipnir-Technology/nidus-sync/models"
|
||||
"github.com/aarondl/opt/null"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/aarondl/opt/omitnull"
|
||||
"github.com/jaswdr/faker/v2"
|
||||
"github.com/stephenafamo/bob"
|
||||
)
|
||||
|
|
@ -38,10 +37,11 @@ func (mods NotificationModSlice) Apply(ctx context.Context, n *NotificationTempl
|
|||
// all columns are optional and should be set by mods
|
||||
type NotificationTemplate struct {
|
||||
ID func() int32
|
||||
UserID func() null.Val[int32]
|
||||
Message func() null.Val[string]
|
||||
Link func() null.Val[string]
|
||||
Type func() null.Val[enums.Notificationtype]
|
||||
Created func() time.Time
|
||||
Link func() string
|
||||
Message func() string
|
||||
Type func() enums.Notificationtype
|
||||
UserID func() int32
|
||||
|
||||
r notificationR
|
||||
f *Factory
|
||||
|
|
@ -70,7 +70,7 @@ func (t NotificationTemplate) setModelRels(o *models.Notification) {
|
|||
if t.r.UserUser != nil {
|
||||
rel := t.r.UserUser.o.Build()
|
||||
rel.R.UserNotifications = append(rel.R.UserNotifications, o)
|
||||
o.UserID = null.From(rel.ID) // h2
|
||||
o.UserID = rel.ID // h2
|
||||
o.R.UserUser = rel
|
||||
}
|
||||
}
|
||||
|
|
@ -84,21 +84,25 @@ func (o NotificationTemplate) BuildSetter() *models.NotificationSetter {
|
|||
val := o.ID()
|
||||
m.ID = omit.From(val)
|
||||
}
|
||||
if o.UserID != nil {
|
||||
val := o.UserID()
|
||||
m.UserID = omitnull.FromNull(val)
|
||||
}
|
||||
if o.Message != nil {
|
||||
val := o.Message()
|
||||
m.Message = omitnull.FromNull(val)
|
||||
if o.Created != nil {
|
||||
val := o.Created()
|
||||
m.Created = omit.From(val)
|
||||
}
|
||||
if o.Link != nil {
|
||||
val := o.Link()
|
||||
m.Link = omitnull.FromNull(val)
|
||||
m.Link = omit.From(val)
|
||||
}
|
||||
if o.Message != nil {
|
||||
val := o.Message()
|
||||
m.Message = omit.From(val)
|
||||
}
|
||||
if o.Type != nil {
|
||||
val := o.Type()
|
||||
m.Type = omitnull.FromNull(val)
|
||||
m.Type = omit.From(val)
|
||||
}
|
||||
if o.UserID != nil {
|
||||
val := o.UserID()
|
||||
m.UserID = omit.From(val)
|
||||
}
|
||||
|
||||
return m
|
||||
|
|
@ -125,18 +129,21 @@ func (o NotificationTemplate) Build() *models.Notification {
|
|||
if o.ID != nil {
|
||||
m.ID = o.ID()
|
||||
}
|
||||
if o.UserID != nil {
|
||||
m.UserID = o.UserID()
|
||||
}
|
||||
if o.Message != nil {
|
||||
m.Message = o.Message()
|
||||
if o.Created != nil {
|
||||
m.Created = o.Created()
|
||||
}
|
||||
if o.Link != nil {
|
||||
m.Link = o.Link()
|
||||
}
|
||||
if o.Message != nil {
|
||||
m.Message = o.Message()
|
||||
}
|
||||
if o.Type != nil {
|
||||
m.Type = o.Type()
|
||||
}
|
||||
if o.UserID != nil {
|
||||
m.UserID = o.UserID()
|
||||
}
|
||||
|
||||
o.setModelRels(m)
|
||||
|
||||
|
|
@ -157,6 +164,26 @@ func (o NotificationTemplate) BuildMany(number int) models.NotificationSlice {
|
|||
}
|
||||
|
||||
func ensureCreatableNotification(m *models.NotificationSetter) {
|
||||
if !(m.Created.IsValue()) {
|
||||
val := random_time_Time(nil)
|
||||
m.Created = omit.From(val)
|
||||
}
|
||||
if !(m.Link.IsValue()) {
|
||||
val := random_string(nil)
|
||||
m.Link = omit.From(val)
|
||||
}
|
||||
if !(m.Message.IsValue()) {
|
||||
val := random_string(nil)
|
||||
m.Message = omit.From(val)
|
||||
}
|
||||
if !(m.Type.IsValue()) {
|
||||
val := random_enums_Notificationtype(nil)
|
||||
m.Type = omit.From(val)
|
||||
}
|
||||
if !(m.UserID.IsValue()) {
|
||||
val := random_int32(nil)
|
||||
m.UserID = omit.From(val)
|
||||
}
|
||||
}
|
||||
|
||||
// insertOptRels creates and inserts any optional the relationships on *models.Notification
|
||||
|
|
@ -165,25 +192,6 @@ func ensureCreatableNotification(m *models.NotificationSetter) {
|
|||
func (o *NotificationTemplate) insertOptRels(ctx context.Context, exec bob.Executor, m *models.Notification) error {
|
||||
var err error
|
||||
|
||||
isUserUserDone, _ := notificationRelUserUserCtx.Value(ctx)
|
||||
if !isUserUserDone && o.r.UserUser != nil {
|
||||
ctx = notificationRelUserUserCtx.WithValue(ctx, true)
|
||||
if o.r.UserUser.o.alreadyPersisted {
|
||||
m.R.UserUser = o.r.UserUser.o.Build()
|
||||
} else {
|
||||
var rel0 *models.User
|
||||
rel0, err = o.r.UserUser.o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = m.AttachUserUser(ctx, exec, rel0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -194,11 +202,30 @@ func (o *NotificationTemplate) Create(ctx context.Context, exec bob.Executor) (*
|
|||
opt := o.BuildSetter()
|
||||
ensureCreatableNotification(opt)
|
||||
|
||||
if o.r.UserUser == nil {
|
||||
NotificationMods.WithNewUserUser().Apply(ctx, o)
|
||||
}
|
||||
|
||||
var rel0 *models.User
|
||||
|
||||
if o.r.UserUser.o.alreadyPersisted {
|
||||
rel0 = o.r.UserUser.o.Build()
|
||||
} else {
|
||||
rel0, err = o.r.UserUser.o.Create(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
opt.UserID = omit.From(rel0.ID)
|
||||
|
||||
m, err := models.Notifications.Insert(opt).One(ctx, exec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m.R.UserUser = rel0
|
||||
|
||||
if err := o.insertOptRels(ctx, exec, m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -277,10 +304,11 @@ type notificationMods struct{}
|
|||
func (m notificationMods) RandomizeAllColumns(f *faker.Faker) NotificationMod {
|
||||
return NotificationModSlice{
|
||||
NotificationMods.RandomID(f),
|
||||
NotificationMods.RandomUserID(f),
|
||||
NotificationMods.RandomMessage(f),
|
||||
NotificationMods.RandomCreated(f),
|
||||
NotificationMods.RandomLink(f),
|
||||
NotificationMods.RandomMessage(f),
|
||||
NotificationMods.RandomType(f),
|
||||
NotificationMods.RandomUserID(f),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -316,120 +344,45 @@ func (m notificationMods) RandomID(f *faker.Faker) NotificationMod {
|
|||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m notificationMods) UserID(val null.Val[int32]) NotificationMod {
|
||||
func (m notificationMods) Created(val time.Time) NotificationMod {
|
||||
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
|
||||
o.UserID = func() null.Val[int32] { return val }
|
||||
o.Created = func() time.Time { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m notificationMods) UserIDFunc(f func() null.Val[int32]) NotificationMod {
|
||||
func (m notificationMods) CreatedFunc(f func() time.Time) NotificationMod {
|
||||
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
|
||||
o.UserID = f
|
||||
o.Created = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m notificationMods) UnsetUserID() NotificationMod {
|
||||
func (m notificationMods) UnsetCreated() NotificationMod {
|
||||
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
|
||||
o.UserID = nil
|
||||
o.Created = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is sometimes null
|
||||
func (m notificationMods) RandomUserID(f *faker.Faker) NotificationMod {
|
||||
func (m notificationMods) RandomCreated(f *faker.Faker) NotificationMod {
|
||||
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
|
||||
o.UserID = func() null.Val[int32] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_int32(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is never null
|
||||
func (m notificationMods) RandomUserIDNotNull(f *faker.Faker) NotificationMod {
|
||||
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
|
||||
o.UserID = func() null.Val[int32] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_int32(f)
|
||||
return null.From(val)
|
||||
o.Created = func() time.Time {
|
||||
return random_time_Time(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m notificationMods) Message(val null.Val[string]) NotificationMod {
|
||||
func (m notificationMods) Link(val string) NotificationMod {
|
||||
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
|
||||
o.Message = func() null.Val[string] { return val }
|
||||
o.Link = func() string { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m notificationMods) MessageFunc(f func() null.Val[string]) NotificationMod {
|
||||
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
|
||||
o.Message = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m notificationMods) UnsetMessage() NotificationMod {
|
||||
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
|
||||
o.Message = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is sometimes null
|
||||
func (m notificationMods) RandomMessage(f *faker.Faker) NotificationMod {
|
||||
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
|
||||
o.Message = func() null.Val[string] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_string(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is never null
|
||||
func (m notificationMods) RandomMessageNotNull(f *faker.Faker) NotificationMod {
|
||||
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
|
||||
o.Message = func() null.Val[string] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_string(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m notificationMods) Link(val null.Val[string]) NotificationMod {
|
||||
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
|
||||
o.Link = func() null.Val[string] { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m notificationMods) LinkFunc(f func() null.Val[string]) NotificationMod {
|
||||
func (m notificationMods) LinkFunc(f func() string) NotificationMod {
|
||||
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
|
||||
o.Link = f
|
||||
})
|
||||
|
|
@ -444,45 +397,54 @@ func (m notificationMods) UnsetLink() NotificationMod {
|
|||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is sometimes null
|
||||
func (m notificationMods) RandomLink(f *faker.Faker) NotificationMod {
|
||||
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
|
||||
o.Link = func() null.Val[string] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_string(f)
|
||||
return null.From(val)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is never null
|
||||
func (m notificationMods) RandomLinkNotNull(f *faker.Faker) NotificationMod {
|
||||
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
|
||||
o.Link = func() null.Val[string] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_string(f)
|
||||
return null.From(val)
|
||||
o.Link = func() string {
|
||||
return random_string(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m notificationMods) Type(val null.Val[enums.Notificationtype]) NotificationMod {
|
||||
func (m notificationMods) Message(val string) NotificationMod {
|
||||
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
|
||||
o.Type = func() null.Val[enums.Notificationtype] { return val }
|
||||
o.Message = func() string { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m notificationMods) TypeFunc(f func() null.Val[enums.Notificationtype]) NotificationMod {
|
||||
func (m notificationMods) MessageFunc(f func() string) NotificationMod {
|
||||
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
|
||||
o.Message = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m notificationMods) UnsetMessage() NotificationMod {
|
||||
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
|
||||
o.Message = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
func (m notificationMods) RandomMessage(f *faker.Faker) NotificationMod {
|
||||
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
|
||||
o.Message = func() string {
|
||||
return random_string(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Set the model columns to this value
|
||||
func (m notificationMods) Type(val enums.Notificationtype) NotificationMod {
|
||||
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
|
||||
o.Type = func() enums.Notificationtype { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m notificationMods) TypeFunc(f func() enums.Notificationtype) NotificationMod {
|
||||
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
|
||||
o.Type = f
|
||||
})
|
||||
|
|
@ -497,32 +459,41 @@ func (m notificationMods) UnsetType() NotificationMod {
|
|||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is sometimes null
|
||||
func (m notificationMods) RandomType(f *faker.Faker) NotificationMod {
|
||||
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
|
||||
o.Type = func() null.Val[enums.Notificationtype] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
o.Type = func() enums.Notificationtype {
|
||||
return random_enums_Notificationtype(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
val := random_enums_Notificationtype(f)
|
||||
return null.From(val)
|
||||
}
|
||||
// Set the model columns to this value
|
||||
func (m notificationMods) UserID(val int32) NotificationMod {
|
||||
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
|
||||
o.UserID = func() int32 { return val }
|
||||
})
|
||||
}
|
||||
|
||||
// Set the Column from the function
|
||||
func (m notificationMods) UserIDFunc(f func() int32) NotificationMod {
|
||||
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
|
||||
o.UserID = f
|
||||
})
|
||||
}
|
||||
|
||||
// Clear any values for the column
|
||||
func (m notificationMods) UnsetUserID() NotificationMod {
|
||||
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
|
||||
o.UserID = nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random value for the column using the given faker
|
||||
// if faker is nil, a default faker is used
|
||||
// The generated value is never null
|
||||
func (m notificationMods) RandomTypeNotNull(f *faker.Faker) NotificationMod {
|
||||
func (m notificationMods) RandomUserID(f *faker.Faker) NotificationMod {
|
||||
return NotificationModFunc(func(_ context.Context, o *NotificationTemplate) {
|
||||
o.Type = func() null.Val[enums.Notificationtype] {
|
||||
if f == nil {
|
||||
f = &defaultFaker
|
||||
}
|
||||
|
||||
val := random_enums_Notificationtype(f)
|
||||
return null.From(val)
|
||||
o.UserID = func() int32 {
|
||||
return random_int32(f)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ func (t UserTemplate) setModelRels(o *models.User) {
|
|||
for _, r := range t.r.UserNotifications {
|
||||
related := r.o.BuildMany(r.number)
|
||||
for _, rel := range related {
|
||||
rel.UserID = null.From(o.ID) // h2
|
||||
rel.UserID = o.ID // h2
|
||||
rel.R.UserUser = o
|
||||
}
|
||||
rel = append(rel, related...)
|
||||
|
|
|
|||
33
html.go
33
html.go
|
|
@ -14,6 +14,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
enums "github.com/Gleipnir-Technology/nidus-sync/enums"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/models"
|
||||
"github.com/aarondl/opt/null"
|
||||
//"github.com/riverqueue/river/rivershared/util/slogutil"
|
||||
|
|
@ -169,7 +170,7 @@ func htmlDashboard(ctx context.Context, w http.ResponseWriter, user *models.User
|
|||
Status: "Completed",
|
||||
})
|
||||
}
|
||||
notifications, err := notificationsForUser(user)
|
||||
notifications, err := notificationsForUser(ctx, user)
|
||||
if err != nil {
|
||||
respondError(w, "Failed to get notifications", err, http.StatusInternalServerError)
|
||||
return
|
||||
|
|
@ -427,15 +428,31 @@ type Notification struct {
|
|||
Type string
|
||||
}
|
||||
|
||||
func notificationsForUser(u *models.User) ([]Notification, error) {
|
||||
return []Notification{Notification{
|
||||
Link: "/foo/bar",
|
||||
Message: "hey, your oauth is broken.",
|
||||
Time: time.Now(),
|
||||
Type: "alert",
|
||||
}}, nil
|
||||
func notificationsForUser(ctx context.Context, u *models.User) ([]Notification, error) {
|
||||
results := make([]Notification, 0)
|
||||
notifications, err := u.UserNotifications().All(ctx, PGInstance.BobDB)
|
||||
if err != nil {
|
||||
return results, fmt.Errorf("Failed to get notifications: %v", err)
|
||||
}
|
||||
for _, n := range notifications {
|
||||
results = append(results, Notification{
|
||||
Link: n.Link,
|
||||
Message: n.Message,
|
||||
Time: n.Created,
|
||||
Type: notificationTypeName(n.Type),
|
||||
})
|
||||
}
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func notificationTypeName(t enums.Notificationtype) string {
|
||||
switch t {
|
||||
case enums.NotificationtypeOauthTokenInvalidated:
|
||||
return "alert"
|
||||
default:
|
||||
return "unknown-type"
|
||||
}
|
||||
}
|
||||
func renderOrError(w http.ResponseWriter, template BuiltTemplate, context interface{}) {
|
||||
buf := &bytes.Buffer{}
|
||||
err := template.ExecuteTemplate(buf, context)
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@ CREATE TYPE NotificationType AS ENUM (
|
|||
|
||||
CREATE TABLE notification (
|
||||
id SERIAL PRIMARY KEY,
|
||||
user_id INTEGER REFERENCES user_(id),
|
||||
message TEXT,
|
||||
link TEXT,
|
||||
type NotificationType);
|
||||
created TIMESTAMP WITHOUT TIME ZONE NOT NULL,
|
||||
link TEXT NOT NULL,
|
||||
message TEXT NOT NULL,
|
||||
type NotificationType NOT NULL,
|
||||
user_id INTEGER REFERENCES user_(id) NOT NULL);
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/aarondl/opt/null"
|
||||
"github.com/aarondl/opt/omit"
|
||||
|
|
@ -71,6 +72,7 @@ type HistoryPolygonlocation struct {
|
|||
GeometryX null.Val[float64] `db:"geometry_x" `
|
||||
GeometryY null.Val[float64] `db:"geometry_y" `
|
||||
Version int32 `db:"version,pk" `
|
||||
Created null.Val[time.Time] `db:"created" `
|
||||
|
||||
R historyPolygonlocationR `db:"-" `
|
||||
}
|
||||
|
|
@ -93,7 +95,7 @@ type historyPolygonlocationR struct {
|
|||
func buildHistoryPolygonlocationColumns(alias string) historyPolygonlocationColumns {
|
||||
return historyPolygonlocationColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"organization_id", "accessdesc", "acres", "active", "comments", "creationdate", "creator", "description", "externalid", "editdate", "editor", "filter", "globalid", "habitat", "hectares", "jurisdiction", "larvinspectinterval", "lastinspectactiontaken", "lastinspectactivity", "lastinspectavglarvae", "lastinspectavgpupae", "lastinspectbreeding", "lastinspectconditions", "lastinspectdate", "lastinspectfieldspecies", "lastinspectlstages", "lasttreatactivity", "lasttreatdate", "lasttreatproduct", "lasttreatqty", "lasttreatqtyunit", "locationnumber", "name", "nextactiondatescheduled", "objectid", "priority", "symbology", "shape__area", "shape__length", "usetype", "waterorigin", "zone", "zone2", "geometry_x", "geometry_y", "version",
|
||||
"organization_id", "accessdesc", "acres", "active", "comments", "creationdate", "creator", "description", "externalid", "editdate", "editor", "filter", "globalid", "habitat", "hectares", "jurisdiction", "larvinspectinterval", "lastinspectactiontaken", "lastinspectactivity", "lastinspectavglarvae", "lastinspectavgpupae", "lastinspectbreeding", "lastinspectconditions", "lastinspectdate", "lastinspectfieldspecies", "lastinspectlstages", "lasttreatactivity", "lasttreatdate", "lasttreatproduct", "lasttreatqty", "lasttreatqtyunit", "locationnumber", "name", "nextactiondatescheduled", "objectid", "priority", "symbology", "shape__area", "shape__length", "usetype", "waterorigin", "zone", "zone2", "geometry_x", "geometry_y", "version", "created",
|
||||
).WithParent("history_polygonlocation"),
|
||||
tableAlias: alias,
|
||||
OrganizationID: psql.Quote(alias, "organization_id"),
|
||||
|
|
@ -142,6 +144,7 @@ func buildHistoryPolygonlocationColumns(alias string) historyPolygonlocationColu
|
|||
GeometryX: psql.Quote(alias, "geometry_x"),
|
||||
GeometryY: psql.Quote(alias, "geometry_y"),
|
||||
Version: psql.Quote(alias, "version"),
|
||||
Created: psql.Quote(alias, "created"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -194,6 +197,7 @@ type historyPolygonlocationColumns struct {
|
|||
GeometryX psql.Expression
|
||||
GeometryY psql.Expression
|
||||
Version psql.Expression
|
||||
Created psql.Expression
|
||||
}
|
||||
|
||||
func (c historyPolygonlocationColumns) Alias() string {
|
||||
|
|
@ -254,10 +258,11 @@ type HistoryPolygonlocationSetter struct {
|
|||
GeometryX omitnull.Val[float64] `db:"geometry_x" `
|
||||
GeometryY omitnull.Val[float64] `db:"geometry_y" `
|
||||
Version omit.Val[int32] `db:"version,pk" `
|
||||
Created omitnull.Val[time.Time] `db:"created" `
|
||||
}
|
||||
|
||||
func (s HistoryPolygonlocationSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 46)
|
||||
vals := make([]string, 0, 47)
|
||||
if s.OrganizationID.IsValue() {
|
||||
vals = append(vals, "organization_id")
|
||||
}
|
||||
|
|
@ -396,6 +401,9 @@ func (s HistoryPolygonlocationSetter) SetColumns() []string {
|
|||
if s.Version.IsValue() {
|
||||
vals = append(vals, "version")
|
||||
}
|
||||
if !s.Created.IsUnset() {
|
||||
vals = append(vals, "created")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
|
|
@ -538,6 +546,9 @@ func (s HistoryPolygonlocationSetter) Overwrite(t *HistoryPolygonlocation) {
|
|||
if s.Version.IsValue() {
|
||||
t.Version = s.Version.MustGet()
|
||||
}
|
||||
if !s.Created.IsUnset() {
|
||||
t.Created = s.Created.MustGetNull()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *HistoryPolygonlocationSetter) Apply(q *dialect.InsertQuery) {
|
||||
|
|
@ -546,7 +557,7 @@ func (s *HistoryPolygonlocationSetter) Apply(q *dialect.InsertQuery) {
|
|||
})
|
||||
|
||||
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.Writer, d bob.Dialect, start int) ([]any, error) {
|
||||
vals := make([]bob.Expression, 46)
|
||||
vals := make([]bob.Expression, 47)
|
||||
if s.OrganizationID.IsValue() {
|
||||
vals[0] = psql.Arg(s.OrganizationID.MustGet())
|
||||
} else {
|
||||
|
|
@ -823,6 +834,12 @@ func (s *HistoryPolygonlocationSetter) Apply(q *dialect.InsertQuery) {
|
|||
vals[45] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.Created.IsUnset() {
|
||||
vals[46] = psql.Arg(s.Created.MustGetNull())
|
||||
} else {
|
||||
vals[46] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
|
@ -832,7 +849,7 @@ func (s HistoryPolygonlocationSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery]
|
|||
}
|
||||
|
||||
func (s HistoryPolygonlocationSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 46)
|
||||
exprs := make([]bob.Expression, 0, 47)
|
||||
|
||||
if s.OrganizationID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
|
|
@ -1156,6 +1173,13 @@ func (s HistoryPolygonlocationSetter) Expressions(prefix ...string) []bob.Expres
|
|||
}})
|
||||
}
|
||||
|
||||
if !s.Created.IsUnset() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "created")...),
|
||||
psql.Arg(s.Created),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
|
|
@ -1511,6 +1535,7 @@ type historyPolygonlocationWhere[Q psql.Filterable] struct {
|
|||
GeometryX psql.WhereNullMod[Q, float64]
|
||||
GeometryY psql.WhereNullMod[Q, float64]
|
||||
Version psql.WhereMod[Q, int32]
|
||||
Created psql.WhereNullMod[Q, time.Time]
|
||||
}
|
||||
|
||||
func (historyPolygonlocationWhere[Q]) AliasedAs(alias string) historyPolygonlocationWhere[Q] {
|
||||
|
|
@ -1565,6 +1590,7 @@ func buildHistoryPolygonlocationWhere[Q psql.Filterable](cols historyPolygonloca
|
|||
GeometryX: psql.WhereNull[Q, float64](cols.GeometryX),
|
||||
GeometryY: psql.WhereNull[Q, float64](cols.GeometryY),
|
||||
Version: psql.Where[Q, int32](cols.Version),
|
||||
Created: psql.WhereNull[Q, time.Time](cols.Created),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/aarondl/opt/null"
|
||||
"github.com/aarondl/opt/omit"
|
||||
|
|
@ -62,6 +63,7 @@ type HistoryProposedtreatmentarea struct {
|
|||
GeometryX null.Val[float64] `db:"geometry_x" `
|
||||
GeometryY null.Val[float64] `db:"geometry_y" `
|
||||
Version int32 `db:"version,pk" `
|
||||
Created null.Val[time.Time] `db:"created" `
|
||||
|
||||
R historyProposedtreatmentareaR `db:"-" `
|
||||
}
|
||||
|
|
@ -84,7 +86,7 @@ type historyProposedtreatmentareaR struct {
|
|||
func buildHistoryProposedtreatmentareaColumns(alias string) historyProposedtreatmentareaColumns {
|
||||
return historyProposedtreatmentareaColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"organization_id", "acres", "comments", "completed", "completedby", "completeddate", "creationdate", "creator", "duedate", "exported", "editdate", "editor", "globalid", "hectares", "issprayroute", "lasttreatactivity", "lasttreatdate", "lasttreatproduct", "lasttreatqty", "lasttreatqtyunit", "method", "name", "objectid", "priority", "reviewed", "reviewedby", "revieweddate", "shape__area", "shape__length", "targetapprate", "targetproduct", "targetspecies", "zone", "zone2", "geometry_x", "geometry_y", "version",
|
||||
"organization_id", "acres", "comments", "completed", "completedby", "completeddate", "creationdate", "creator", "duedate", "exported", "editdate", "editor", "globalid", "hectares", "issprayroute", "lasttreatactivity", "lasttreatdate", "lasttreatproduct", "lasttreatqty", "lasttreatqtyunit", "method", "name", "objectid", "priority", "reviewed", "reviewedby", "revieweddate", "shape__area", "shape__length", "targetapprate", "targetproduct", "targetspecies", "zone", "zone2", "geometry_x", "geometry_y", "version", "created",
|
||||
).WithParent("history_proposedtreatmentarea"),
|
||||
tableAlias: alias,
|
||||
OrganizationID: psql.Quote(alias, "organization_id"),
|
||||
|
|
@ -124,6 +126,7 @@ func buildHistoryProposedtreatmentareaColumns(alias string) historyProposedtreat
|
|||
GeometryX: psql.Quote(alias, "geometry_x"),
|
||||
GeometryY: psql.Quote(alias, "geometry_y"),
|
||||
Version: psql.Quote(alias, "version"),
|
||||
Created: psql.Quote(alias, "created"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -167,6 +170,7 @@ type historyProposedtreatmentareaColumns struct {
|
|||
GeometryX psql.Expression
|
||||
GeometryY psql.Expression
|
||||
Version psql.Expression
|
||||
Created psql.Expression
|
||||
}
|
||||
|
||||
func (c historyProposedtreatmentareaColumns) Alias() string {
|
||||
|
|
@ -218,10 +222,11 @@ type HistoryProposedtreatmentareaSetter struct {
|
|||
GeometryX omitnull.Val[float64] `db:"geometry_x" `
|
||||
GeometryY omitnull.Val[float64] `db:"geometry_y" `
|
||||
Version omit.Val[int32] `db:"version,pk" `
|
||||
Created omitnull.Val[time.Time] `db:"created" `
|
||||
}
|
||||
|
||||
func (s HistoryProposedtreatmentareaSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 37)
|
||||
vals := make([]string, 0, 38)
|
||||
if s.OrganizationID.IsValue() {
|
||||
vals = append(vals, "organization_id")
|
||||
}
|
||||
|
|
@ -333,6 +338,9 @@ func (s HistoryProposedtreatmentareaSetter) SetColumns() []string {
|
|||
if s.Version.IsValue() {
|
||||
vals = append(vals, "version")
|
||||
}
|
||||
if !s.Created.IsUnset() {
|
||||
vals = append(vals, "created")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
|
|
@ -448,6 +456,9 @@ func (s HistoryProposedtreatmentareaSetter) Overwrite(t *HistoryProposedtreatmen
|
|||
if s.Version.IsValue() {
|
||||
t.Version = s.Version.MustGet()
|
||||
}
|
||||
if !s.Created.IsUnset() {
|
||||
t.Created = s.Created.MustGetNull()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *HistoryProposedtreatmentareaSetter) Apply(q *dialect.InsertQuery) {
|
||||
|
|
@ -456,7 +467,7 @@ func (s *HistoryProposedtreatmentareaSetter) Apply(q *dialect.InsertQuery) {
|
|||
})
|
||||
|
||||
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.Writer, d bob.Dialect, start int) ([]any, error) {
|
||||
vals := make([]bob.Expression, 37)
|
||||
vals := make([]bob.Expression, 38)
|
||||
if s.OrganizationID.IsValue() {
|
||||
vals[0] = psql.Arg(s.OrganizationID.MustGet())
|
||||
} else {
|
||||
|
|
@ -679,6 +690,12 @@ func (s *HistoryProposedtreatmentareaSetter) Apply(q *dialect.InsertQuery) {
|
|||
vals[36] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.Created.IsUnset() {
|
||||
vals[37] = psql.Arg(s.Created.MustGetNull())
|
||||
} else {
|
||||
vals[37] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
|
@ -688,7 +705,7 @@ func (s HistoryProposedtreatmentareaSetter) UpdateMod() bob.Mod[*dialect.UpdateQ
|
|||
}
|
||||
|
||||
func (s HistoryProposedtreatmentareaSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 37)
|
||||
exprs := make([]bob.Expression, 0, 38)
|
||||
|
||||
if s.OrganizationID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
|
|
@ -949,6 +966,13 @@ func (s HistoryProposedtreatmentareaSetter) Expressions(prefix ...string) []bob.
|
|||
}})
|
||||
}
|
||||
|
||||
if !s.Created.IsUnset() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "created")...),
|
||||
psql.Arg(s.Created),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
|
|
@ -1295,6 +1319,7 @@ type historyProposedtreatmentareaWhere[Q psql.Filterable] struct {
|
|||
GeometryX psql.WhereNullMod[Q, float64]
|
||||
GeometryY psql.WhereNullMod[Q, float64]
|
||||
Version psql.WhereMod[Q, int32]
|
||||
Created psql.WhereNullMod[Q, time.Time]
|
||||
}
|
||||
|
||||
func (historyProposedtreatmentareaWhere[Q]) AliasedAs(alias string) historyProposedtreatmentareaWhere[Q] {
|
||||
|
|
@ -1340,6 +1365,7 @@ func buildHistoryProposedtreatmentareaWhere[Q psql.Filterable](cols historyPropo
|
|||
GeometryX: psql.WhereNull[Q, float64](cols.GeometryX),
|
||||
GeometryY: psql.WhereNull[Q, float64](cols.GeometryY),
|
||||
Version: psql.Where[Q, int32](cols.Version),
|
||||
Created: psql.WhereNull[Q, time.Time](cols.Created),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/aarondl/opt/null"
|
||||
"github.com/aarondl/opt/omit"
|
||||
|
|
@ -83,6 +84,7 @@ type HistoryTreatment struct {
|
|||
GeometryY null.Val[float64] `db:"geometry_y" `
|
||||
TempSitecond null.Val[string] `db:"temp_sitecond" `
|
||||
Version int32 `db:"version,pk" `
|
||||
Created null.Val[time.Time] `db:"created" `
|
||||
|
||||
R historyTreatmentR `db:"-" `
|
||||
}
|
||||
|
|
@ -105,7 +107,7 @@ type historyTreatmentR struct {
|
|||
func buildHistoryTreatmentColumns(alias string) historyTreatmentColumns {
|
||||
return historyTreatmentColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"organization_id", "activity", "areaunit", "avetemp", "barrierrouteid", "cbcount", "comments", "containercount", "creationdate", "creator", "enddatetime", "equiptype", "editdate", "editor", "fieldtech", "flowrate", "globalid", "habitat", "insp_id", "invloc", "linelocid", "locationname", "method", "objectid", "pointlocid", "polygonlocid", "product", "ptaid", "qty", "qtyunit", "raingauge", "recordstatus", "reviewed", "reviewedby", "revieweddate", "sdid", "sitecond", "srid", "startdatetime", "targetspecies", "tirecount", "treatacres", "treatarea", "treathectares", "treatmenthours", "treatmentlength", "treatmentlengthunits", "totalcostprodcut", "ulvrouteid", "warningoverride", "winddir", "windspeed", "zone", "zone2", "geometry_x", "geometry_y", "temp_sitecond", "version",
|
||||
"organization_id", "activity", "areaunit", "avetemp", "barrierrouteid", "cbcount", "comments", "containercount", "creationdate", "creator", "enddatetime", "equiptype", "editdate", "editor", "fieldtech", "flowrate", "globalid", "habitat", "insp_id", "invloc", "linelocid", "locationname", "method", "objectid", "pointlocid", "polygonlocid", "product", "ptaid", "qty", "qtyunit", "raingauge", "recordstatus", "reviewed", "reviewedby", "revieweddate", "sdid", "sitecond", "srid", "startdatetime", "targetspecies", "tirecount", "treatacres", "treatarea", "treathectares", "treatmenthours", "treatmentlength", "treatmentlengthunits", "totalcostprodcut", "ulvrouteid", "warningoverride", "winddir", "windspeed", "zone", "zone2", "geometry_x", "geometry_y", "temp_sitecond", "version", "created",
|
||||
).WithParent("history_treatment"),
|
||||
tableAlias: alias,
|
||||
OrganizationID: psql.Quote(alias, "organization_id"),
|
||||
|
|
@ -166,6 +168,7 @@ func buildHistoryTreatmentColumns(alias string) historyTreatmentColumns {
|
|||
GeometryY: psql.Quote(alias, "geometry_y"),
|
||||
TempSitecond: psql.Quote(alias, "temp_sitecond"),
|
||||
Version: psql.Quote(alias, "version"),
|
||||
Created: psql.Quote(alias, "created"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -230,6 +233,7 @@ type historyTreatmentColumns struct {
|
|||
GeometryY psql.Expression
|
||||
TempSitecond psql.Expression
|
||||
Version psql.Expression
|
||||
Created psql.Expression
|
||||
}
|
||||
|
||||
func (c historyTreatmentColumns) Alias() string {
|
||||
|
|
@ -302,10 +306,11 @@ type HistoryTreatmentSetter struct {
|
|||
GeometryY omitnull.Val[float64] `db:"geometry_y" `
|
||||
TempSitecond omitnull.Val[string] `db:"temp_sitecond" `
|
||||
Version omit.Val[int32] `db:"version,pk" `
|
||||
Created omitnull.Val[time.Time] `db:"created" `
|
||||
}
|
||||
|
||||
func (s HistoryTreatmentSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 58)
|
||||
vals := make([]string, 0, 59)
|
||||
if s.OrganizationID.IsValue() {
|
||||
vals = append(vals, "organization_id")
|
||||
}
|
||||
|
|
@ -480,6 +485,9 @@ func (s HistoryTreatmentSetter) SetColumns() []string {
|
|||
if s.Version.IsValue() {
|
||||
vals = append(vals, "version")
|
||||
}
|
||||
if !s.Created.IsUnset() {
|
||||
vals = append(vals, "created")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
|
|
@ -658,6 +666,9 @@ func (s HistoryTreatmentSetter) Overwrite(t *HistoryTreatment) {
|
|||
if s.Version.IsValue() {
|
||||
t.Version = s.Version.MustGet()
|
||||
}
|
||||
if !s.Created.IsUnset() {
|
||||
t.Created = s.Created.MustGetNull()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *HistoryTreatmentSetter) Apply(q *dialect.InsertQuery) {
|
||||
|
|
@ -666,7 +677,7 @@ func (s *HistoryTreatmentSetter) Apply(q *dialect.InsertQuery) {
|
|||
})
|
||||
|
||||
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.Writer, d bob.Dialect, start int) ([]any, error) {
|
||||
vals := make([]bob.Expression, 58)
|
||||
vals := make([]bob.Expression, 59)
|
||||
if s.OrganizationID.IsValue() {
|
||||
vals[0] = psql.Arg(s.OrganizationID.MustGet())
|
||||
} else {
|
||||
|
|
@ -1015,6 +1026,12 @@ func (s *HistoryTreatmentSetter) Apply(q *dialect.InsertQuery) {
|
|||
vals[57] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.Created.IsUnset() {
|
||||
vals[58] = psql.Arg(s.Created.MustGetNull())
|
||||
} else {
|
||||
vals[58] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
|
@ -1024,7 +1041,7 @@ func (s HistoryTreatmentSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|||
}
|
||||
|
||||
func (s HistoryTreatmentSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 58)
|
||||
exprs := make([]bob.Expression, 0, 59)
|
||||
|
||||
if s.OrganizationID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
|
|
@ -1432,6 +1449,13 @@ func (s HistoryTreatmentSetter) Expressions(prefix ...string) []bob.Expression {
|
|||
}})
|
||||
}
|
||||
|
||||
if !s.Created.IsUnset() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "created")...),
|
||||
psql.Arg(s.Created),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
|
|
@ -1799,6 +1823,7 @@ type historyTreatmentWhere[Q psql.Filterable] struct {
|
|||
GeometryY psql.WhereNullMod[Q, float64]
|
||||
TempSitecond psql.WhereNullMod[Q, string]
|
||||
Version psql.WhereMod[Q, int32]
|
||||
Created psql.WhereNullMod[Q, time.Time]
|
||||
}
|
||||
|
||||
func (historyTreatmentWhere[Q]) AliasedAs(alias string) historyTreatmentWhere[Q] {
|
||||
|
|
@ -1865,6 +1890,7 @@ func buildHistoryTreatmentWhere[Q psql.Filterable](cols historyTreatmentColumns)
|
|||
GeometryY: psql.WhereNull[Q, float64](cols.GeometryY),
|
||||
TempSitecond: psql.WhereNull[Q, string](cols.TempSitecond),
|
||||
Version: psql.Where[Q, int32](cols.Version),
|
||||
Created: psql.WhereNull[Q, time.Time](cols.Created),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,11 +7,10 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
enums "github.com/Gleipnir-Technology/nidus-sync/enums"
|
||||
"github.com/aarondl/opt/null"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/aarondl/opt/omitnull"
|
||||
"github.com/stephenafamo/bob"
|
||||
"github.com/stephenafamo/bob/dialect/psql"
|
||||
"github.com/stephenafamo/bob/dialect/psql/dialect"
|
||||
|
|
@ -27,10 +26,11 @@ import (
|
|||
// Notification is an object representing the database table.
|
||||
type Notification struct {
|
||||
ID int32 `db:"id,pk" `
|
||||
UserID null.Val[int32] `db:"user_id" `
|
||||
Message null.Val[string] `db:"message" `
|
||||
Link null.Val[string] `db:"link" `
|
||||
Type null.Val[enums.Notificationtype] `db:"type" `
|
||||
Created time.Time `db:"created" `
|
||||
Link string `db:"link" `
|
||||
Message string `db:"message" `
|
||||
Type enums.Notificationtype `db:"type" `
|
||||
UserID int32 `db:"user_id" `
|
||||
|
||||
R notificationR `db:"-" `
|
||||
}
|
||||
|
|
@ -53,14 +53,15 @@ type notificationR struct {
|
|||
func buildNotificationColumns(alias string) notificationColumns {
|
||||
return notificationColumns{
|
||||
ColumnsExpr: expr.NewColumnsExpr(
|
||||
"id", "user_id", "message", "link", "type",
|
||||
"id", "created", "link", "message", "type", "user_id",
|
||||
).WithParent("notification"),
|
||||
tableAlias: alias,
|
||||
ID: psql.Quote(alias, "id"),
|
||||
UserID: psql.Quote(alias, "user_id"),
|
||||
Message: psql.Quote(alias, "message"),
|
||||
Created: psql.Quote(alias, "created"),
|
||||
Link: psql.Quote(alias, "link"),
|
||||
Message: psql.Quote(alias, "message"),
|
||||
Type: psql.Quote(alias, "type"),
|
||||
UserID: psql.Quote(alias, "user_id"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -68,10 +69,11 @@ type notificationColumns struct {
|
|||
expr.ColumnsExpr
|
||||
tableAlias string
|
||||
ID psql.Expression
|
||||
UserID psql.Expression
|
||||
Message psql.Expression
|
||||
Created psql.Expression
|
||||
Link psql.Expression
|
||||
Message psql.Expression
|
||||
Type psql.Expression
|
||||
UserID psql.Expression
|
||||
}
|
||||
|
||||
func (c notificationColumns) Alias() string {
|
||||
|
|
@ -87,29 +89,33 @@ func (notificationColumns) AliasedAs(alias string) notificationColumns {
|
|||
// Generated columns are not included
|
||||
type NotificationSetter struct {
|
||||
ID omit.Val[int32] `db:"id,pk" `
|
||||
UserID omitnull.Val[int32] `db:"user_id" `
|
||||
Message omitnull.Val[string] `db:"message" `
|
||||
Link omitnull.Val[string] `db:"link" `
|
||||
Type omitnull.Val[enums.Notificationtype] `db:"type" `
|
||||
Created omit.Val[time.Time] `db:"created" `
|
||||
Link omit.Val[string] `db:"link" `
|
||||
Message omit.Val[string] `db:"message" `
|
||||
Type omit.Val[enums.Notificationtype] `db:"type" `
|
||||
UserID omit.Val[int32] `db:"user_id" `
|
||||
}
|
||||
|
||||
func (s NotificationSetter) SetColumns() []string {
|
||||
vals := make([]string, 0, 5)
|
||||
vals := make([]string, 0, 6)
|
||||
if s.ID.IsValue() {
|
||||
vals = append(vals, "id")
|
||||
}
|
||||
if !s.UserID.IsUnset() {
|
||||
vals = append(vals, "user_id")
|
||||
if s.Created.IsValue() {
|
||||
vals = append(vals, "created")
|
||||
}
|
||||
if !s.Message.IsUnset() {
|
||||
vals = append(vals, "message")
|
||||
}
|
||||
if !s.Link.IsUnset() {
|
||||
if s.Link.IsValue() {
|
||||
vals = append(vals, "link")
|
||||
}
|
||||
if !s.Type.IsUnset() {
|
||||
if s.Message.IsValue() {
|
||||
vals = append(vals, "message")
|
||||
}
|
||||
if s.Type.IsValue() {
|
||||
vals = append(vals, "type")
|
||||
}
|
||||
if s.UserID.IsValue() {
|
||||
vals = append(vals, "user_id")
|
||||
}
|
||||
return vals
|
||||
}
|
||||
|
||||
|
|
@ -117,17 +123,20 @@ func (s NotificationSetter) Overwrite(t *Notification) {
|
|||
if s.ID.IsValue() {
|
||||
t.ID = s.ID.MustGet()
|
||||
}
|
||||
if !s.UserID.IsUnset() {
|
||||
t.UserID = s.UserID.MustGetNull()
|
||||
if s.Created.IsValue() {
|
||||
t.Created = s.Created.MustGet()
|
||||
}
|
||||
if !s.Message.IsUnset() {
|
||||
t.Message = s.Message.MustGetNull()
|
||||
if s.Link.IsValue() {
|
||||
t.Link = s.Link.MustGet()
|
||||
}
|
||||
if !s.Link.IsUnset() {
|
||||
t.Link = s.Link.MustGetNull()
|
||||
if s.Message.IsValue() {
|
||||
t.Message = s.Message.MustGet()
|
||||
}
|
||||
if !s.Type.IsUnset() {
|
||||
t.Type = s.Type.MustGetNull()
|
||||
if s.Type.IsValue() {
|
||||
t.Type = s.Type.MustGet()
|
||||
}
|
||||
if s.UserID.IsValue() {
|
||||
t.UserID = s.UserID.MustGet()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -137,37 +146,43 @@ func (s *NotificationSetter) Apply(q *dialect.InsertQuery) {
|
|||
})
|
||||
|
||||
q.AppendValues(bob.ExpressionFunc(func(ctx context.Context, w io.Writer, d bob.Dialect, start int) ([]any, error) {
|
||||
vals := make([]bob.Expression, 5)
|
||||
vals := make([]bob.Expression, 6)
|
||||
if s.ID.IsValue() {
|
||||
vals[0] = psql.Arg(s.ID.MustGet())
|
||||
} else {
|
||||
vals[0] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.UserID.IsUnset() {
|
||||
vals[1] = psql.Arg(s.UserID.MustGetNull())
|
||||
if s.Created.IsValue() {
|
||||
vals[1] = psql.Arg(s.Created.MustGet())
|
||||
} else {
|
||||
vals[1] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.Message.IsUnset() {
|
||||
vals[2] = psql.Arg(s.Message.MustGetNull())
|
||||
if s.Link.IsValue() {
|
||||
vals[2] = psql.Arg(s.Link.MustGet())
|
||||
} else {
|
||||
vals[2] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.Link.IsUnset() {
|
||||
vals[3] = psql.Arg(s.Link.MustGetNull())
|
||||
if s.Message.IsValue() {
|
||||
vals[3] = psql.Arg(s.Message.MustGet())
|
||||
} else {
|
||||
vals[3] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if !s.Type.IsUnset() {
|
||||
vals[4] = psql.Arg(s.Type.MustGetNull())
|
||||
if s.Type.IsValue() {
|
||||
vals[4] = psql.Arg(s.Type.MustGet())
|
||||
} else {
|
||||
vals[4] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
if s.UserID.IsValue() {
|
||||
vals[5] = psql.Arg(s.UserID.MustGet())
|
||||
} else {
|
||||
vals[5] = psql.Raw("DEFAULT")
|
||||
}
|
||||
|
||||
return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "")
|
||||
}))
|
||||
}
|
||||
|
|
@ -177,7 +192,7 @@ func (s NotificationSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] {
|
|||
}
|
||||
|
||||
func (s NotificationSetter) Expressions(prefix ...string) []bob.Expression {
|
||||
exprs := make([]bob.Expression, 0, 5)
|
||||
exprs := make([]bob.Expression, 0, 6)
|
||||
|
||||
if s.ID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
|
|
@ -186,34 +201,41 @@ func (s NotificationSetter) Expressions(prefix ...string) []bob.Expression {
|
|||
}})
|
||||
}
|
||||
|
||||
if !s.UserID.IsUnset() {
|
||||
if s.Created.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "user_id")...),
|
||||
psql.Arg(s.UserID),
|
||||
psql.Quote(append(prefix, "created")...),
|
||||
psql.Arg(s.Created),
|
||||
}})
|
||||
}
|
||||
|
||||
if !s.Message.IsUnset() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "message")...),
|
||||
psql.Arg(s.Message),
|
||||
}})
|
||||
}
|
||||
|
||||
if !s.Link.IsUnset() {
|
||||
if s.Link.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "link")...),
|
||||
psql.Arg(s.Link),
|
||||
}})
|
||||
}
|
||||
|
||||
if !s.Type.IsUnset() {
|
||||
if s.Message.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "message")...),
|
||||
psql.Arg(s.Message),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.Type.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "type")...),
|
||||
psql.Arg(s.Type),
|
||||
}})
|
||||
}
|
||||
|
||||
if s.UserID.IsValue() {
|
||||
exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{
|
||||
psql.Quote(append(prefix, "user_id")...),
|
||||
psql.Arg(s.UserID),
|
||||
}})
|
||||
}
|
||||
|
||||
return exprs
|
||||
}
|
||||
|
||||
|
|
@ -448,7 +470,7 @@ func (o *Notification) UserUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuer
|
|||
}
|
||||
|
||||
func (os NotificationSlice) UserUser(mods ...bob.Mod[*dialect.SelectQuery]) UsersQuery {
|
||||
pkUserID := make(pgtypes.Array[null.Val[int32]], 0, len(os))
|
||||
pkUserID := make(pgtypes.Array[int32], 0, len(os))
|
||||
for _, o := range os {
|
||||
if o == nil {
|
||||
continue
|
||||
|
|
@ -466,7 +488,7 @@ func (os NotificationSlice) UserUser(mods ...bob.Mod[*dialect.SelectQuery]) User
|
|||
|
||||
func attachNotificationUserUser0(ctx context.Context, exec bob.Executor, count int, notification0 *Notification, user1 *User) (*Notification, error) {
|
||||
setter := &NotificationSetter{
|
||||
UserID: omitnull.From(user1.ID),
|
||||
UserID: omit.From(user1.ID),
|
||||
}
|
||||
|
||||
err := notification0.Update(ctx, exec, setter)
|
||||
|
|
@ -514,10 +536,11 @@ func (notification0 *Notification) AttachUserUser(ctx context.Context, exec bob.
|
|||
|
||||
type notificationWhere[Q psql.Filterable] struct {
|
||||
ID psql.WhereMod[Q, int32]
|
||||
UserID psql.WhereNullMod[Q, int32]
|
||||
Message psql.WhereNullMod[Q, string]
|
||||
Link psql.WhereNullMod[Q, string]
|
||||
Type psql.WhereNullMod[Q, enums.Notificationtype]
|
||||
Created psql.WhereMod[Q, time.Time]
|
||||
Link psql.WhereMod[Q, string]
|
||||
Message psql.WhereMod[Q, string]
|
||||
Type psql.WhereMod[Q, enums.Notificationtype]
|
||||
UserID psql.WhereMod[Q, int32]
|
||||
}
|
||||
|
||||
func (notificationWhere[Q]) AliasedAs(alias string) notificationWhere[Q] {
|
||||
|
|
@ -527,10 +550,11 @@ func (notificationWhere[Q]) AliasedAs(alias string) notificationWhere[Q] {
|
|||
func buildNotificationWhere[Q psql.Filterable](cols notificationColumns) notificationWhere[Q] {
|
||||
return notificationWhere[Q]{
|
||||
ID: psql.Where[Q, int32](cols.ID),
|
||||
UserID: psql.WhereNull[Q, int32](cols.UserID),
|
||||
Message: psql.WhereNull[Q, string](cols.Message),
|
||||
Link: psql.WhereNull[Q, string](cols.Link),
|
||||
Type: psql.WhereNull[Q, enums.Notificationtype](cols.Type),
|
||||
Created: psql.Where[Q, time.Time](cols.Created),
|
||||
Link: psql.Where[Q, string](cols.Link),
|
||||
Message: psql.Where[Q, string](cols.Message),
|
||||
Type: psql.Where[Q, enums.Notificationtype](cols.Type),
|
||||
UserID: psql.Where[Q, int32](cols.UserID),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -635,11 +659,8 @@ func (os NotificationSlice) LoadUserUser(ctx context.Context, exec bob.Executor,
|
|||
}
|
||||
|
||||
for _, rel := range users {
|
||||
if !o.UserID.IsValue() {
|
||||
continue
|
||||
}
|
||||
|
||||
if !(o.UserID.IsValue() && o.UserID.MustGet() == rel.ID) {
|
||||
if !(o.UserID == rel.ID) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -678,7 +678,7 @@ func (os UserSlice) Organization(mods ...bob.Mod[*dialect.SelectQuery]) Organiza
|
|||
|
||||
func insertUserUserNotifications0(ctx context.Context, exec bob.Executor, notifications1 []*NotificationSetter, user0 *User) (NotificationSlice, error) {
|
||||
for i := range notifications1 {
|
||||
notifications1[i].UserID = omitnull.From(user0.ID)
|
||||
notifications1[i].UserID = omit.From(user0.ID)
|
||||
}
|
||||
|
||||
ret, err := Notifications.Insert(bob.ToMods(notifications1...)).All(ctx, exec)
|
||||
|
|
@ -691,7 +691,7 @@ func insertUserUserNotifications0(ctx context.Context, exec bob.Executor, notifi
|
|||
|
||||
func attachUserUserNotifications0(ctx context.Context, exec bob.Executor, count int, notifications1 NotificationSlice, user0 *User) (NotificationSlice, error) {
|
||||
setter := &NotificationSetter{
|
||||
UserID: omitnull.From(user0.ID),
|
||||
UserID: omit.From(user0.ID),
|
||||
}
|
||||
|
||||
err := notifications1.UpdateAll(ctx, exec, *setter)
|
||||
|
|
@ -1056,10 +1056,7 @@ func (os UserSlice) LoadUserNotifications(ctx context.Context, exec bob.Executor
|
|||
|
||||
for _, rel := range notifications {
|
||||
|
||||
if !rel.UserID.IsValue() {
|
||||
continue
|
||||
}
|
||||
if !(rel.UserID.IsValue() && o.ID == rel.UserID.MustGet()) {
|
||||
if !(o.ID == rel.UserID) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue