Correctly build updaters with New
Otherwise we have nil columns
This commit is contained in:
parent
7da653efc6
commit
24a3610c4c
6 changed files with 29 additions and 7 deletions
|
|
@ -13,9 +13,16 @@ import (
|
|||
|
||||
type ComplianceUpdater = db.Updater[table.ComplianceTable, model.Compliance]
|
||||
|
||||
func NewComplianceUpdater() ComplianceUpdater {
|
||||
return db.NewUpdater[table.ComplianceTable, model.Compliance](
|
||||
table.Compliance,
|
||||
table.Compliance.ReportID,
|
||||
)
|
||||
}
|
||||
|
||||
func NewUpdaterCompliance() db.Updater[table.ComplianceTable, model.Compliance] {
|
||||
return db.NewUpdater[table.ComplianceTable, model.Compliance](
|
||||
*table.Compliance,
|
||||
table.Compliance,
|
||||
table.Compliance.ReportID,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,13 @@ import (
|
|||
|
||||
type ReportUpdater = db.Updater[table.ReportTable, model.Report]
|
||||
|
||||
func NewReportUpdater() ReportUpdater {
|
||||
return db.NewUpdater[table.ReportTable, model.Report](
|
||||
table.Report,
|
||||
table.Report.ID,
|
||||
)
|
||||
}
|
||||
|
||||
func ReportInsert(ctx context.Context, txn db.Ex, m model.Report) (model.Report, error) {
|
||||
statement := table.Report.INSERT(table.Report.MutableColumns).
|
||||
MODEL(m).
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package db
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
//"github.com/go-jet/jet/v2"
|
||||
"github.com/go-jet/jet/v2/postgres"
|
||||
|
|
@ -17,6 +18,13 @@ type Updater[T postgres.Table, M any] struct {
|
|||
}
|
||||
|
||||
func (u Updater[T, M]) Execute(ctx context.Context, txn Ex, pk_values ...interface{}) error {
|
||||
// We get syntax errors from the database if there are no updates to perform
|
||||
if u.Columns == nil {
|
||||
return fmt.Errorf("nil columns")
|
||||
}
|
||||
if len(u.Columns) == 0 {
|
||||
return nil
|
||||
}
|
||||
statement := u.Table.
|
||||
UPDATE(u.Columns).
|
||||
MODEL(u.Model).
|
||||
|
|
@ -47,12 +55,12 @@ func (u *Updater[T, M]) Unset(c postgres.Column) {
|
|||
}
|
||||
}
|
||||
func NewUpdater[T postgres.Table, M any](
|
||||
table T,
|
||||
table *T,
|
||||
pk_columns ...postgres.ColumnInteger,
|
||||
) Updater[T, M] {
|
||||
return Updater[T, M]{
|
||||
Columns: postgres.ColumnList{},
|
||||
Table: table,
|
||||
Table: *table,
|
||||
buildWhere: func(pk_values ...interface{}) postgres.BoolExpression {
|
||||
conditions := make([]postgres.BoolExpression, len(pk_columns))
|
||||
for i, col := range pk_columns {
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ func PublicReportInvalid(ctx context.Context, user User, public_id string) error
|
|||
}
|
||||
|
||||
now := time.Now()
|
||||
report_updater := querypublicreport.ReportUpdater{}
|
||||
report_updater := querypublicreport.NewReportUpdater()
|
||||
report_updater.Model.Reviewed = &now
|
||||
report_updater.Set(tablepublicreport.Report.Reviewed)
|
||||
reporter_id := int32(user.ID)
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ func SignalCreateFromPublicreport(ctx context.Context, user User, report_id stri
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("create signal: %w", err)
|
||||
}
|
||||
report_updater := querypublicreport.ReportUpdater{}
|
||||
report_updater := querypublicreport.NewReportUpdater()
|
||||
now := time.Now()
|
||||
report_updater.Model.Reviewed = &now
|
||||
report_updater.Set(tablepublicreport.Report.Reviewed)
|
||||
|
|
|
|||
|
|
@ -152,9 +152,9 @@ func (res *complianceR) Update(ctx context.Context, r *http.Request, prf publicR
|
|||
if public_id == "" {
|
||||
return nil, nhttp.NewBadRequest("You must provide an ID")
|
||||
}
|
||||
report_updater := querypublicreport.ReportUpdater{}
|
||||
report_updater := querypublicreport.NewReportUpdater()
|
||||
//report_setter := models.PublicreportReportSetter{}
|
||||
compliance_updater := querypublicreport.ComplianceUpdater{}
|
||||
compliance_updater := querypublicreport.NewComplianceUpdater()
|
||||
//compliance_setter := models.PublicreportComplianceSetter{}
|
||||
var location *types.Location
|
||||
if prf.Location.IsValue() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue