diff --git a/db/dbinfo/publicreport.compliance.bob.go b/db/dbinfo/publicreport.compliance.bob.go index 990a92ff..439afaff 100644 --- a/db/dbinfo/publicreport.compliance.bob.go +++ b/db/dbinfo/publicreport.compliance.bob.go @@ -96,6 +96,15 @@ var PublicreportCompliances = Table[ Generated: false, AutoIncr: false, }, + Submitted: column{ + Name: "submitted", + DBType: "timestamp without time zone", + Default: "NULL", + Comment: "", + Nullable: true, + Generated: false, + AutoIncr: false, + }, }, Indexes: publicreportComplianceIndexes{ CompliancePkey: index{ @@ -146,11 +155,12 @@ type publicreportComplianceColumns struct { ReportID column ReportPhoneCanText column WantsScheduled column + Submitted column } func (c publicreportComplianceColumns) AsSlice() []column { return []column{ - c.AccessInstructions, c.AvailabilityNotes, c.Comments, c.GateCode, c.HasDog, c.PermissionType, c.ReportID, c.ReportPhoneCanText, c.WantsScheduled, + c.AccessInstructions, c.AvailabilityNotes, c.Comments, c.GateCode, c.HasDog, c.PermissionType, c.ReportID, c.ReportPhoneCanText, c.WantsScheduled, c.Submitted, } } diff --git a/db/migrations/00146_publicreport_compliance_submitted.sql b/db/migrations/00146_publicreport_compliance_submitted.sql new file mode 100644 index 00000000..46d685bd --- /dev/null +++ b/db/migrations/00146_publicreport_compliance_submitted.sql @@ -0,0 +1,4 @@ +-- +goose Up +ALTER TABLE publicreport.compliance ADD COLUMN submitted TIMESTAMP WITHOUT TIME ZONE; +-- +goose Down +ALTER TABLE publicreport.compliance DROP COLUMN submitted; diff --git a/db/models/publicreport.compliance.bob.go b/db/models/publicreport.compliance.bob.go index 35a8946a..3fe11332 100644 --- a/db/models/publicreport.compliance.bob.go +++ b/db/models/publicreport.compliance.bob.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "io" + "time" "github.com/Gleipnir-Technology/bob" "github.com/Gleipnir-Technology/bob/dialect/psql" @@ -34,6 +35,7 @@ type PublicreportCompliance struct { ReportID int32 `db:"report_id,pk" ` ReportPhoneCanText null.Val[bool] `db:"report_phone_can_text" ` WantsScheduled null.Val[bool] `db:"wants_scheduled" ` + Submitted null.Val[time.Time] `db:"submitted" ` R publicreportComplianceR `db:"-" ` } @@ -56,7 +58,7 @@ type publicreportComplianceR struct { func buildPublicreportComplianceColumns(alias string) publicreportComplianceColumns { return publicreportComplianceColumns{ ColumnsExpr: expr.NewColumnsExpr( - "access_instructions", "availability_notes", "comments", "gate_code", "has_dog", "permission_type", "report_id", "report_phone_can_text", "wants_scheduled", + "access_instructions", "availability_notes", "comments", "gate_code", "has_dog", "permission_type", "report_id", "report_phone_can_text", "wants_scheduled", "submitted", ).WithParent("publicreport.compliance"), tableAlias: alias, AccessInstructions: psql.Quote(alias, "access_instructions"), @@ -68,6 +70,7 @@ func buildPublicreportComplianceColumns(alias string) publicreportComplianceColu ReportID: psql.Quote(alias, "report_id"), ReportPhoneCanText: psql.Quote(alias, "report_phone_can_text"), WantsScheduled: psql.Quote(alias, "wants_scheduled"), + Submitted: psql.Quote(alias, "submitted"), } } @@ -83,6 +86,7 @@ type publicreportComplianceColumns struct { ReportID psql.Expression ReportPhoneCanText psql.Expression WantsScheduled psql.Expression + Submitted psql.Expression } func (c publicreportComplianceColumns) Alias() string { @@ -106,10 +110,11 @@ type PublicreportComplianceSetter struct { ReportID omit.Val[int32] `db:"report_id,pk" ` ReportPhoneCanText omitnull.Val[bool] `db:"report_phone_can_text" ` WantsScheduled omitnull.Val[bool] `db:"wants_scheduled" ` + Submitted omitnull.Val[time.Time] `db:"submitted" ` } func (s PublicreportComplianceSetter) SetColumns() []string { - vals := make([]string, 0, 9) + vals := make([]string, 0, 10) if s.AccessInstructions.IsValue() { vals = append(vals, "access_instructions") } @@ -137,6 +142,9 @@ func (s PublicreportComplianceSetter) SetColumns() []string { if !s.WantsScheduled.IsUnset() { vals = append(vals, "wants_scheduled") } + if !s.Submitted.IsUnset() { + vals = append(vals, "submitted") + } return vals } @@ -168,6 +176,9 @@ func (s PublicreportComplianceSetter) Overwrite(t *PublicreportCompliance) { if !s.WantsScheduled.IsUnset() { t.WantsScheduled = s.WantsScheduled.MustGetNull() } + if !s.Submitted.IsUnset() { + t.Submitted = s.Submitted.MustGetNull() + } } func (s *PublicreportComplianceSetter) Apply(q *dialect.InsertQuery) { @@ -176,7 +187,7 @@ func (s *PublicreportComplianceSetter) 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, 9) + vals := make([]bob.Expression, 10) if s.AccessInstructions.IsValue() { vals[0] = psql.Arg(s.AccessInstructions.MustGet()) } else { @@ -231,6 +242,12 @@ func (s *PublicreportComplianceSetter) Apply(q *dialect.InsertQuery) { vals[8] = psql.Raw("DEFAULT") } + if !s.Submitted.IsUnset() { + vals[9] = psql.Arg(s.Submitted.MustGetNull()) + } else { + vals[9] = psql.Raw("DEFAULT") + } + return bob.ExpressSlice(ctx, w, d, start, vals, "", ", ", "") })) } @@ -240,7 +257,7 @@ func (s PublicreportComplianceSetter) UpdateMod() bob.Mod[*dialect.UpdateQuery] } func (s PublicreportComplianceSetter) Expressions(prefix ...string) []bob.Expression { - exprs := make([]bob.Expression, 0, 9) + exprs := make([]bob.Expression, 0, 10) if s.AccessInstructions.IsValue() { exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ @@ -305,6 +322,13 @@ func (s PublicreportComplianceSetter) Expressions(prefix ...string) []bob.Expres }}) } + if !s.Submitted.IsUnset() { + exprs = append(exprs, expr.Join{Sep: " = ", Exprs: []bob.Expression{ + psql.Quote(append(prefix, "submitted")...), + psql.Arg(s.Submitted), + }}) + } + return exprs } @@ -613,6 +637,7 @@ type publicreportComplianceWhere[Q psql.Filterable] struct { ReportID psql.WhereMod[Q, int32] ReportPhoneCanText psql.WhereNullMod[Q, bool] WantsScheduled psql.WhereNullMod[Q, bool] + Submitted psql.WhereNullMod[Q, time.Time] } func (publicreportComplianceWhere[Q]) AliasedAs(alias string) publicreportComplianceWhere[Q] { @@ -630,6 +655,7 @@ func buildPublicreportComplianceWhere[Q psql.Filterable](cols publicreportCompli ReportID: psql.Where[Q, int32](cols.ReportID), ReportPhoneCanText: psql.WhereNull[Q, bool](cols.ReportPhoneCanText), WantsScheduled: psql.WhereNull[Q, bool](cols.WantsScheduled), + Submitted: psql.WhereNull[Q, time.Time](cols.Submitted), } } diff --git a/platform/publicreport.go b/platform/publicreport.go index ae70cd6d..939cdb7e 100644 --- a/platform/publicreport.go +++ b/platform/publicreport.go @@ -81,6 +81,21 @@ func PublicreportByIDNuisance(ctx context.Context, report_id string) (*types.Pub func PublicreportByIDWater(ctx context.Context, report_id string) (*types.PublicReportWater, error) { return publicreport.ByIDWater(ctx, report_id) } +func PublicreportComplianceSubmit(ctx context.Context, report_id string) (*types.PublicReportCompliance, error) { + report, err := publicreport.ByIDCompliance(ctx, report_id) + if err != nil { + return nil, fmt.Errorf("byidcompliance: %w", err) + } + _, err = psql.Update( + um.Table(models.PublicreportCompliances.NameAs()), + um.SetCol(models.PublicreportCompliances.Columns.Submitted.String()).ToArg(time.Now()), + um.Where(models.PublicreportCompliances.Columns.ReportID.EQ(psql.Arg(report.ReportID))), + ).Exec(ctx, db.PGInstance.BobDB) + if err != nil { + return nil, fmt.Errorf("update report submitted: %w", err) + } + return publicreport.ByIDCompliance(ctx, report_id) +} func PublicreportInvalid(ctx context.Context, user User, public_id string) error { report, err := publicReportFromID(ctx, public_id) if err != nil { diff --git a/platform/types/publicreport.go b/platform/types/publicreport.go index d7661bbf..7591a863 100644 --- a/platform/types/publicreport.go +++ b/platform/types/publicreport.go @@ -23,15 +23,16 @@ type PublicReport struct { type PublicReportCompliance struct { PublicReport - AccessInstructions string `db:"access_instructions" json:"access_instructions"` - AvailabilityNotes string `db:"availability_notes" json:"availability_notes"` - Comments string `db:"comments" json:"comments"` - GateCode string `db:"gate_code" json:"gate_code"` - HasDog *bool `db:"has_dog" json:"has_dog"` - PermissionType string `db:"permission_type" json:"permission_type"` - ReportID int32 `db:"report_id" json:"-"` - ReportPhoneCanText *bool `db:"report_phone_can_text" json:"can_text"` - WantsScheduled *bool `db:"wants_scheduled" json:"wants_scheduled"` + AccessInstructions string `db:"access_instructions" json:"access_instructions"` + AvailabilityNotes string `db:"availability_notes" json:"availability_notes"` + Comments string `db:"comments" json:"comments"` + GateCode string `db:"gate_code" json:"gate_code"` + HasDog *bool `db:"has_dog" json:"has_dog"` + PermissionType string `db:"permission_type" json:"permission_type"` + ReportID int32 `db:"report_id" json:"-"` + ReportPhoneCanText *bool `db:"report_phone_can_text" json:"can_text"` + Submitted *time.Time `db:"submitted" json:"submitted"` + WantsScheduled *bool `db:"wants_scheduled" json:"wants_scheduled"` } type PublicReportNuisance struct { PublicReport diff --git a/resource/publicreport_compliance.go b/resource/publicreport_compliance.go index 90d63202..1f2f8bf7 100644 --- a/resource/publicreport_compliance.go +++ b/resource/publicreport_compliance.go @@ -212,6 +212,23 @@ func (res *complianceR) Update(ctx context.Context, r *http.Request, prf publicr } return res.complianceHydrate(report) } + +type publicreportComplianceFormSubmit struct { + ClientID uuid.UUID `schema:"client_id" json:"client_id"` +} + +func (res *complianceR) Submit(ctx context.Context, r *http.Request, prf publicreportComplianceForm) (*types.PublicReportCompliance, *nhttp.ErrorWithStatus) { + vars := mux.Vars(r) + public_id := vars["id"] + if public_id == "" { + return nil, nhttp.NewBadRequest("You must provide an ID") + } + report, err := platform.PublicreportComplianceSubmit(ctx, public_id) + if err != nil { + return nil, nhttp.NewError("submit report: %w", err) + } + return report, nil +} func (res *complianceR) complianceHydrate(report *types.PublicReportCompliance) (*types.PublicReportCompliance, *nhttp.ErrorWithStatus) { populateDistrictURI(&report.PublicReport, res.router) populateReportURI(&report.PublicReport, res.router)