Add 'submitted' field to compliance reports

This commit is contained in:
Eli Ribble 2026-04-27 16:23:16 +00:00
parent 8a05ba2faf
commit be8d92d7ae
No known key found for this signature in database
6 changed files with 87 additions and 14 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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