Add mode data to pool upload rows, move to fileupload schema
This allows users to review the data before committing it to the database
This commit is contained in:
parent
135ad2b73e
commit
d06b8f7949
23 changed files with 4285 additions and 3182 deletions
|
|
@ -100,17 +100,22 @@ func ProcessJob(ctx context.Context, file_id int32) error {
|
|||
}
|
||||
return fmt.Errorf("Failed to read all CSV records for file %d: %w", file_id, err)
|
||||
}
|
||||
setter := models.PoolSetter{
|
||||
setter := models.FileuploadPoolSetter{
|
||||
// required fields
|
||||
//AddressCity: omit.From(),
|
||||
//AddressPostalCode: omit.From(),
|
||||
//AddressStreet: omit.From(),
|
||||
Committed: omit.From(false),
|
||||
Condition: omit.From(enums.FileuploadPoolconditiontypeUnknown),
|
||||
Created: omit.From(time.Now()),
|
||||
CreatorID: omit.From(file.CreatorID),
|
||||
Committed: omit.From(false),
|
||||
Condition: omit.From(enums.PoolconditiontypeUnknown),
|
||||
CSVFile: omit.From(file.ID),
|
||||
Deleted: omitnull.FromPtr[time.Time](nil),
|
||||
Geom: omitnull.FromPtr[string](nil),
|
||||
H3cell: omitnull.FromPtr[string](nil),
|
||||
// ID - generated
|
||||
IsInDistrict: omit.From(false),
|
||||
IsNew: omit.From(false),
|
||||
Notes: omit.From(""),
|
||||
OrganizationID: omit.From(file.OrganizationID),
|
||||
PropertyOwnerName: omit.From(""),
|
||||
|
|
@ -129,7 +134,7 @@ func ProcessJob(ctx context.Context, file_id int32) error {
|
|||
case headerAddressStreet:
|
||||
setter.AddressStreet = omit.From(col)
|
||||
case headerCondition:
|
||||
var condition enums.Poolconditiontype
|
||||
var condition enums.FileuploadPoolconditiontype
|
||||
err := condition.Scan(strings.ToLower(col))
|
||||
if err != nil {
|
||||
addError(ctx, txn, c, int32(row_number), int32(i), fmt.Sprintf("'%s' is not a pool condition that we recognize. It should be one of %s", poolConditionValidValues()))
|
||||
|
|
@ -153,7 +158,7 @@ func ProcessJob(ctx context.Context, file_id int32) error {
|
|||
setter.ResidentPhone = omitnull.From(col)
|
||||
}
|
||||
}
|
||||
_, err = models.Pools.Insert(&setter).Exec(ctx, txn)
|
||||
_, err = models.FileuploadPools.Insert(&setter).Exec(ctx, txn)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to create pool: %w", err)
|
||||
}
|
||||
|
|
@ -260,7 +265,7 @@ func missingRequiredHeaders(headers []headerPoolEnum) []headerPoolEnum {
|
|||
}
|
||||
func poolConditionValidValues() string {
|
||||
var b strings.Builder
|
||||
for i, cond := range enums.AllPoolconditiontype() {
|
||||
for i, cond := range enums.AllFileuploadPoolconditiontype() {
|
||||
if i == 0 {
|
||||
fmt.Fprintf(&b, "'%s'", cond)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,16 @@ import (
|
|||
"github.com/stephenafamo/scan"
|
||||
)
|
||||
|
||||
type PoolDetail struct {
|
||||
Created time.Time `db:"created"`
|
||||
ID int32 `db:"id"`
|
||||
Pools []PoolRow
|
||||
Status string `db:"status"`
|
||||
}
|
||||
type PoolRow struct {
|
||||
Street string
|
||||
City string
|
||||
}
|
||||
type PoolUpload struct {
|
||||
Created time.Time `db:"created"`
|
||||
ID int32 `db:"id"`
|
||||
|
|
@ -62,6 +72,35 @@ func NewPoolUpload(ctx context.Context, u *models.User, upload userfile.FileUplo
|
|||
ID: file.ID,
|
||||
}, nil
|
||||
}
|
||||
func GetPoolDetail(ctx context.Context, organization_id int32, file_id int32) (PoolDetail, error) {
|
||||
file, err := models.FindFileuploadFile(ctx, db.PGInstance.BobDB, file_id)
|
||||
if err != nil {
|
||||
return PoolDetail{}, fmt.Errorf("Failed to lookup file %d: %w", file_id, err)
|
||||
}
|
||||
/*
|
||||
csv, err := models.FindFileuploadCSV(ctx, db.PGInstance.BobDB, file_id)
|
||||
if err != nil {
|
||||
return PoolDetail{}, fmt.Errorf("Failed to lookup csv %d: %w", file_id, err)
|
||||
}
|
||||
*/
|
||||
rows, err := models.FileuploadPools.Query(
|
||||
models.SelectWhere.FileuploadPools.CSVFile.EQ(file_id),
|
||||
).All(ctx, db.PGInstance.BobDB)
|
||||
if err != nil {
|
||||
return PoolDetail{}, fmt.Errorf("Failed to query pools for %d: %w", file_id, err)
|
||||
}
|
||||
pools := make([]PoolRow, 0)
|
||||
for _, r := range rows {
|
||||
pools = append(pools, PoolRow{
|
||||
Street: r.AddressStreet,
|
||||
City: r.AddressCity,
|
||||
})
|
||||
}
|
||||
return PoolDetail{
|
||||
Pools: pools,
|
||||
Status: file.Status.String(),
|
||||
}, nil
|
||||
}
|
||||
func PoolUploadList(ctx context.Context, organization_id int32) ([]PoolUpload, error) {
|
||||
results := make([]PoolUpload, 0)
|
||||
rows, err := bob.All(ctx, db.PGInstance.BobDB, psql.Select(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue