Compare commits
No commits in common. "1b6fac331310061eea9e069049947542522f54a1" and "61ad3fbe457ce298f40c20ca77d6f67c7dfad9f3" have entirely different histories.
1b6fac3313
...
61ad3fbe45
21 changed files with 91 additions and 260 deletions
|
|
@ -44,22 +44,14 @@ func ExecuteNone(ctx context.Context, stmt postgres.Statement) error {
|
||||||
func ExecuteNoneTx(ctx context.Context, txn Ex, stmt postgres.Statement) error {
|
func ExecuteNoneTx(ctx context.Context, txn Ex, stmt postgres.Statement) error {
|
||||||
query, args := stmt.Sql()
|
query, args := stmt.Sql()
|
||||||
|
|
||||||
r, err := txn.Query(ctx, query, args...)
|
_, err := txn.Query(ctx, query, args...)
|
||||||
if err != nil {
|
return err
|
||||||
return fmt.Errorf("query: %w", err)
|
|
||||||
}
|
|
||||||
r.Close()
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
func ExecuteNoneTxBob(ctx context.Context, txn bob.Tx, stmt postgres.Statement) error {
|
func ExecuteNoneTxBob(ctx context.Context, txn bob.Tx, stmt postgres.Statement) error {
|
||||||
query, args := stmt.Sql()
|
query, args := stmt.Sql()
|
||||||
|
|
||||||
r, err := txn.QueryContext(ctx, query, args...)
|
_, err := txn.QueryContext(ctx, query, args...)
|
||||||
if err != nil {
|
return err
|
||||||
return fmt.Errorf("query: %w", err)
|
|
||||||
}
|
|
||||||
r.Close()
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
func ExecuteOne[T any](ctx context.Context, stmt postgres.Statement) (T, error) {
|
func ExecuteOne[T any](ctx context.Context, stmt postgres.Statement) (T, error) {
|
||||||
query, args := stmt.Sql()
|
query, args := stmt.Sql()
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ func AccountFromID(ctx context.Context, org_id string) (model.Account, error) {
|
||||||
return db.ExecuteOne[model.Account](ctx, statement)
|
return db.ExecuteOne[model.Account](ctx, statement)
|
||||||
}
|
}
|
||||||
func AccountInsert(ctx context.Context, txn bob.Tx, m *model.Account) (model.Account, error) {
|
func AccountInsert(ctx context.Context, txn bob.Tx, m *model.Account) (model.Account, error) {
|
||||||
statement := table.Account.INSERT(table.Account.MutableColumns).
|
statement := table.Account.INSERT(table.Account.AllColumns).
|
||||||
MODEL(m).
|
MODEL(m).
|
||||||
RETURNING(table.Account.AllColumns)
|
RETURNING(table.Account.AllColumns)
|
||||||
return db.ExecuteOneTxBob[model.Account](ctx, txn, statement)
|
return db.ExecuteOneTxBob[model.Account](ctx, txn, statement)
|
||||||
|
|
|
||||||
|
|
@ -52,9 +52,6 @@ func AddressFromID(ctx context.Context, txn db.Ex, comm_id int64) (model.Address
|
||||||
return db.ExecuteOne[model.Address](ctx, statement)
|
return db.ExecuteOne[model.Address](ctx, statement)
|
||||||
}
|
}
|
||||||
func AddressesFromIDs(ctx context.Context, txn db.Ex, address_ids []int64) ([]model.Address, error) {
|
func AddressesFromIDs(ctx context.Context, txn db.Ex, address_ids []int64) ([]model.Address, error) {
|
||||||
if len(address_ids) == 0 {
|
|
||||||
return []model.Address{}, nil
|
|
||||||
}
|
|
||||||
sql_ids := make([]postgres.Expression, len(address_ids))
|
sql_ids := make([]postgres.Expression, len(address_ids))
|
||||||
for i, address_id := range address_ids {
|
for i, address_id := range address_ids {
|
||||||
sql_ids[i] = postgres.Int(address_id)
|
sql_ids[i] = postgres.Int(address_id)
|
||||||
|
|
|
||||||
|
|
@ -13,16 +13,9 @@ import (
|
||||||
|
|
||||||
type ComplianceUpdater = db.Updater[table.ComplianceTable, model.Compliance]
|
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] {
|
func NewUpdaterCompliance() db.Updater[table.ComplianceTable, model.Compliance] {
|
||||||
return db.NewUpdater[table.ComplianceTable, model.Compliance](
|
return db.NewUpdater[table.ComplianceTable, model.Compliance](
|
||||||
table.Compliance,
|
*table.Compliance,
|
||||||
table.Compliance.ReportID,
|
table.Compliance.ReportID,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func ImageInsert(ctx context.Context, txn db.Ex, m model.Image) (model.Image, error) {
|
func ImageInsert(ctx context.Context, txn db.Ex, m model.Image) (model.Image, error) {
|
||||||
statement := table.Image.INSERT(table.Image.MutableColumns).
|
statement := table.Image.INSERT(table.Image.AllColumns).
|
||||||
MODEL(m).
|
MODEL(m).
|
||||||
RETURNING(table.Image.AllColumns)
|
RETURNING(table.Image.AllColumns)
|
||||||
return db.ExecuteOneTx[model.Image](ctx, txn, statement)
|
return db.ExecuteOneTx[model.Image](ctx, txn, statement)
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func NuisanceInsert(ctx context.Context, txn db.Ex, m model.Nuisance) (model.Nuisance, error) {
|
func NuisanceInsert(ctx context.Context, txn db.Ex, m model.Nuisance) (model.Nuisance, error) {
|
||||||
statement := table.Nuisance.INSERT(table.Nuisance.MutableColumns).
|
statement := table.Nuisance.INSERT(table.Nuisance.AllColumns).
|
||||||
MODEL(m).
|
MODEL(m).
|
||||||
RETURNING(table.Nuisance.AllColumns)
|
RETURNING(table.Nuisance.AllColumns)
|
||||||
return db.ExecuteOneTx[model.Nuisance](ctx, txn, statement)
|
return db.ExecuteOneTx[model.Nuisance](ctx, txn, statement)
|
||||||
|
|
|
||||||
|
|
@ -15,15 +15,8 @@ import (
|
||||||
|
|
||||||
type ReportUpdater = db.Updater[table.ReportTable, model.Report]
|
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) {
|
func ReportInsert(ctx context.Context, txn db.Ex, m model.Report) (model.Report, error) {
|
||||||
statement := table.Report.INSERT(table.Report.MutableColumns).
|
statement := table.Report.INSERT(table.Report.AllColumns).
|
||||||
MODEL(m).
|
MODEL(m).
|
||||||
RETURNING(table.Report.AllColumns)
|
RETURNING(table.Report.AllColumns)
|
||||||
return db.ExecuteOneTx[model.Report](ctx, txn, statement)
|
return db.ExecuteOneTx[model.Report](ctx, txn, statement)
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func ReportImageInsert(ctx context.Context, txn db.Ex, m model.ReportImage) (model.ReportImage, error) {
|
func ReportImageInsert(ctx context.Context, txn db.Ex, m model.ReportImage) (model.ReportImage, error) {
|
||||||
statement := table.ReportImage.INSERT(table.ReportImage.MutableColumns).
|
statement := table.ReportImage.INSERT(table.ReportImage.AllColumns).
|
||||||
MODEL(m).
|
MODEL(m).
|
||||||
RETURNING(table.ReportImage.AllColumns)
|
RETURNING(table.ReportImage.AllColumns)
|
||||||
return db.ExecuteOneTx[model.ReportImage](ctx, txn, statement)
|
return db.ExecuteOneTx[model.ReportImage](ctx, txn, statement)
|
||||||
}
|
}
|
||||||
func ReportImagesInsert(ctx context.Context, txn db.Ex, m []model.ReportImage) ([]model.ReportImage, error) {
|
func ReportImagesInsert(ctx context.Context, txn db.Ex, m []model.ReportImage) ([]model.ReportImage, error) {
|
||||||
statement := table.ReportImage.INSERT(table.ReportImage.MutableColumns).
|
statement := table.ReportImage.INSERT(table.ReportImage.AllColumns).
|
||||||
MODELS(m).
|
MODELS(m).
|
||||||
RETURNING(table.ReportImage.AllColumns)
|
RETURNING(table.ReportImage.AllColumns)
|
||||||
return db.ExecuteManyTx[model.ReportImage](ctx, txn, statement)
|
return db.ExecuteManyTx[model.ReportImage](ctx, txn, statement)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func ReportLogInsert(ctx context.Context, txn db.Ex, m model.ReportLog) (model.ReportLog, error) {
|
func ReportLogInsert(ctx context.Context, txn db.Ex, m model.ReportLog) (model.ReportLog, error) {
|
||||||
statement := table.ReportLog.INSERT(table.ReportLog.MutableColumns).
|
statement := table.ReportLog.INSERT(table.ReportLog.AllColumns).
|
||||||
MODEL(m).
|
MODEL(m).
|
||||||
RETURNING(table.ReportLog.AllColumns)
|
RETURNING(table.ReportLog.AllColumns)
|
||||||
return db.ExecuteOneTx[model.ReportLog](ctx, txn, statement)
|
return db.ExecuteOneTx[model.ReportLog](ctx, txn, statement)
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func WaterInsert(ctx context.Context, txn db.Ex, m model.Water) (model.Water, error) {
|
func WaterInsert(ctx context.Context, txn db.Ex, m model.Water) (model.Water, error) {
|
||||||
statement := table.Water.INSERT(table.Water.MutableColumns).
|
statement := table.Water.INSERT(table.Water.AllColumns).
|
||||||
MODEL(m).
|
MODEL(m).
|
||||||
RETURNING(table.Water.AllColumns)
|
RETURNING(table.Water.AllColumns)
|
||||||
return db.ExecuteOneTx[model.Water](ctx, txn, statement)
|
return db.ExecuteOneTx[model.Water](ctx, txn, statement)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package db
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
//"github.com/go-jet/jet/v2"
|
//"github.com/go-jet/jet/v2"
|
||||||
"github.com/go-jet/jet/v2/postgres"
|
"github.com/go-jet/jet/v2/postgres"
|
||||||
|
|
@ -18,13 +17,6 @@ type Updater[T postgres.Table, M any] struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u Updater[T, M]) Execute(ctx context.Context, txn Ex, pk_values ...interface{}) error {
|
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.
|
statement := u.Table.
|
||||||
UPDATE(u.Columns).
|
UPDATE(u.Columns).
|
||||||
MODEL(u.Model).
|
MODEL(u.Model).
|
||||||
|
|
@ -55,12 +47,12 @@ func (u *Updater[T, M]) Unset(c postgres.Column) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func NewUpdater[T postgres.Table, M any](
|
func NewUpdater[T postgres.Table, M any](
|
||||||
table *T,
|
table T,
|
||||||
pk_columns ...postgres.ColumnInteger,
|
pk_columns ...postgres.ColumnInteger,
|
||||||
) Updater[T, M] {
|
) Updater[T, M] {
|
||||||
return Updater[T, M]{
|
return Updater[T, M]{
|
||||||
Columns: postgres.ColumnList{},
|
Columns: postgres.ColumnList{},
|
||||||
Table: *table,
|
Table: table,
|
||||||
buildWhere: func(pk_values ...interface{}) postgres.BoolExpression {
|
buildWhere: func(pk_values ...interface{}) postgres.BoolExpression {
|
||||||
conditions := make([]postgres.BoolExpression, len(pk_columns))
|
conditions := make([]postgres.BoolExpression, len(pk_columns))
|
||||||
for i, col := range 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()
|
now := time.Now()
|
||||||
report_updater := querypublicreport.NewReportUpdater()
|
report_updater := querypublicreport.ReportUpdater{}
|
||||||
report_updater.Model.Reviewed = &now
|
report_updater.Model.Reviewed = &now
|
||||||
report_updater.Set(tablepublicreport.Report.Reviewed)
|
report_updater.Set(tablepublicreport.Report.Reviewed)
|
||||||
reporter_id := int32(user.ID)
|
reporter_id := int32(user.ID)
|
||||||
|
|
@ -187,12 +187,6 @@ func PublicReportUpdateCompliance(ctx context.Context, public_id string, report_
|
||||||
}
|
}
|
||||||
|
|
||||||
// Avoid attempting to perform an empty update
|
// Avoid attempting to perform an empty update
|
||||||
if address != nil {
|
|
||||||
report_updates.Model.AddressGid = address.GID
|
|
||||||
report_updates.Set(tablepublicreport.Report.AddressGid)
|
|
||||||
report_updates.Model.AddressRaw = address.Raw
|
|
||||||
report_updates.Set(tablepublicreport.Report.AddressRaw)
|
|
||||||
}
|
|
||||||
err = report_updates.Execute(ctx, txn, int64(report.ID))
|
err = report_updates.Execute(ctx, txn, int64(report.ID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("update report: %w", err)
|
return fmt.Errorf("update report: %w", err)
|
||||||
|
|
@ -202,7 +196,7 @@ func PublicReportUpdateCompliance(ctx context.Context, public_id string, report_
|
||||||
return fmt.Errorf("update compliance: %w", err)
|
return fmt.Errorf("update compliance: %w", err)
|
||||||
}
|
}
|
||||||
if address != nil {
|
if address != nil {
|
||||||
err = publicReportUpdateAddressID(ctx, txn, report, *address)
|
err = publicReportUpdateAddress(ctx, txn, report, *address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("update address: %w", err)
|
return fmt.Errorf("update address: %w", err)
|
||||||
}
|
}
|
||||||
|
|
@ -230,7 +224,7 @@ func PublicReportComplianceCreate(ctx context.Context, setter_report modelpublic
|
||||||
setter_compliance.ReportID = report_id
|
setter_compliance.ReportID = report_id
|
||||||
_, err := querypublicreport.ComplianceInsert(ctx, txn, setter_compliance)
|
_, err := querypublicreport.ComplianceInsert(ctx, txn, setter_compliance)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to create compliance database record: %w", err)
|
return fmt.Errorf("Failed to create nuisance database record: %w", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
@ -412,23 +406,23 @@ func publicReportCreate(ctx context.Context, setter_report modelpublicreport.Rep
|
||||||
)
|
)
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
func publicReportUpdateAddressID(ctx context.Context, txn db.Tx, report *modelpublicreport.Report, address types.Address) error {
|
func publicReportUpdateAddress(ctx context.Context, txn db.Tx, report *modelpublicreport.Report, address types.Address) error {
|
||||||
var err error
|
|
||||||
if address.GID == "" && address.Raw != "" {
|
|
||||||
geo_res, err := geocode.GeocodeRaw(ctx, nil, address.Raw)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Failed to geocode raw: %w", err)
|
|
||||||
}
|
|
||||||
statement := tablepublicreport.Report.UPDATE(
|
statement := tablepublicreport.Report.UPDATE(
|
||||||
tablepublicreport.Report.AddressID,
|
tablepublicreport.Report.AddressGid,
|
||||||
|
tablepublicreport.Report.AddressRaw,
|
||||||
).SET(
|
).SET(
|
||||||
tablepublicreport.Report.AddressID.SET(postgres.Int(int64(*geo_res.Address.ID))),
|
postgres.String(address.GID),
|
||||||
).WHERE(
|
postgres.String(address.Raw),
|
||||||
|
).FROM(tablepublic.Address).
|
||||||
|
WHERE(
|
||||||
tablepublicreport.Report.ID.EQ(postgres.Int(int64(report.ID))),
|
tablepublicreport.Report.ID.EQ(postgres.Int(int64(report.ID))),
|
||||||
)
|
)
|
||||||
err = db.ExecuteNoneTx(ctx, txn, statement)
|
err := db.ExecuteNoneTx(ctx, txn, statement)
|
||||||
} else {
|
|
||||||
statement := tablepublicreport.Report.UPDATE(
|
if err != nil {
|
||||||
|
return fmt.Errorf("update report: %w", err)
|
||||||
|
}
|
||||||
|
statement = tablepublicreport.Report.UPDATE(
|
||||||
tablepublicreport.Report.AddressID,
|
tablepublicreport.Report.AddressID,
|
||||||
).SET(
|
).SET(
|
||||||
tablepublic.Address.SELECT(
|
tablepublic.Address.SELECT(
|
||||||
|
|
@ -440,7 +434,6 @@ func publicReportUpdateAddressID(ctx context.Context, txn db.Tx, report *modelpu
|
||||||
tablepublicreport.Report.ID.EQ(postgres.Int(int64(report.ID))),
|
tablepublicreport.Report.ID.EQ(postgres.Int(int64(report.ID))),
|
||||||
)
|
)
|
||||||
err = db.ExecuteNoneTx(ctx, txn, statement)
|
err = db.ExecuteNoneTx(ctx, txn, statement)
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("update report address_id: %w", err)
|
return fmt.Errorf("update report address_id: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,10 @@ import (
|
||||||
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
"github.com/Gleipnir-Technology/bob/dialect/psql"
|
||||||
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
|
"github.com/Gleipnir-Technology/bob/dialect/psql/sm"
|
||||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||||
modelpublic "github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/public/model"
|
|
||||||
modelpublicreport "github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/publicreport/model"
|
|
||||||
querypublic "github.com/Gleipnir-Technology/nidus-sync/db/query/public"
|
querypublic "github.com/Gleipnir-Technology/nidus-sync/db/query/public"
|
||||||
querypublicreport "github.com/Gleipnir-Technology/nidus-sync/db/query/publicreport"
|
querypublicreport "github.com/Gleipnir-Technology/nidus-sync/db/query/publicreport"
|
||||||
|
modelpublic "github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/public/model"
|
||||||
|
modelpublicreport "github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/publicreport/model"
|
||||||
"github.com/Gleipnir-Technology/nidus-sync/platform/types"
|
"github.com/Gleipnir-Technology/nidus-sync/platform/types"
|
||||||
//"github.com/google/uuid"
|
//"github.com/google/uuid"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
|
@ -80,8 +80,6 @@ func reportQueryToRows(ctx context.Context, reports []modelpublicreport.Report,
|
||||||
report_ids[i] = report.ID
|
report_ids[i] = report.ID
|
||||||
if report.AddressID != nil {
|
if report.AddressID != nil {
|
||||||
address_ids = append(address_ids, int64(*report.AddressID))
|
address_ids = append(address_ids, int64(*report.AddressID))
|
||||||
} else {
|
|
||||||
log.Debug().Int32("id", report.ID).Msg("has no address")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
images_by_id, err := loadImagesForReport(ctx, report_ids)
|
images_by_id, err := loadImagesForReport(ctx, report_ids)
|
||||||
|
|
@ -126,11 +124,7 @@ func reportQueryToRows(ctx context.Context, reports []modelpublicreport.Report,
|
||||||
address = &a
|
address = &a
|
||||||
}
|
}
|
||||||
if address == nil {
|
if address == nil {
|
||||||
address = &types.Address{
|
return nil, fmt.Errorf("nil address: %w", err)
|
||||||
ID: row.AddressID,
|
|
||||||
GID: row.AddressGid,
|
|
||||||
Raw: row.AddressRaw,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
results[i] = types.PublicReport{
|
results[i] = types.PublicReport{
|
||||||
Address: *address,
|
Address: *address,
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ func SignalCreateFromPublicreport(ctx context.Context, user User, report_id stri
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("create signal: %w", err)
|
return nil, fmt.Errorf("create signal: %w", err)
|
||||||
}
|
}
|
||||||
report_updater := querypublicreport.NewReportUpdater()
|
report_updater := querypublicreport.ReportUpdater{}
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
report_updater.Model.Reviewed = &now
|
report_updater.Model.Reviewed = &now
|
||||||
report_updater.Set(tablepublicreport.Report.Reviewed)
|
report_updater.Set(tablepublicreport.Report.Reviewed)
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/Gleipnir-Technology/nidus-sync/config"
|
"github.com/Gleipnir-Technology/nidus-sync/config"
|
||||||
modelpublic "github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/public/model"
|
modelpublic "github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/public/model"
|
||||||
|
|
@ -27,13 +26,12 @@ func Communication(r *router) *communicationR {
|
||||||
}
|
}
|
||||||
|
|
||||||
type communicationLog struct {
|
type communicationLog struct {
|
||||||
Created time.Time `json:"created"`
|
Created string `json:"string"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
User string `json:"user"`
|
User string `json:"user"`
|
||||||
}
|
}
|
||||||
type communication struct {
|
type communication struct {
|
||||||
Created time.Time `json:"created"`
|
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Log []communicationLog `json:"log"`
|
Log []communicationLog `json:"log"`
|
||||||
Response string `json:"response"`
|
Response string `json:"response"`
|
||||||
|
|
@ -42,14 +40,6 @@ type communication struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
URI string `json:"uri"`
|
URI string `json:"uri"`
|
||||||
}
|
}
|
||||||
type communicationStub struct {
|
|
||||||
Created time.Time `json:"created"`
|
|
||||||
ID string `json:"id"`
|
|
||||||
Source string `json:"source"`
|
|
||||||
Status string `json:"status"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
URI string `json:"uri"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func toImageURLs(m map[string][]uuid.UUID, id string) []string {
|
func toImageURLs(m map[string][]uuid.UUID, id string) []string {
|
||||||
uuids, ok := m[id]
|
uuids, ok := m[id]
|
||||||
|
|
@ -65,7 +55,7 @@ func toImageURLs(m map[string][]uuid.UUID, id string) []string {
|
||||||
func (res *communicationR) Get(ctx context.Context, r *http.Request, user platform.User, query QueryParams) (*communication, *nhttp.ErrorWithStatus) {
|
func (res *communicationR) Get(ctx context.Context, r *http.Request, user platform.User, query QueryParams) (*communication, *nhttp.ErrorWithStatus) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
func (res *communicationR) List(ctx context.Context, r *http.Request, user platform.User, query QueryParams) ([]communicationStub, *nhttp.ErrorWithStatus) {
|
func (res *communicationR) List(ctx context.Context, r *http.Request, user platform.User, query QueryParams) ([]communication, *nhttp.ErrorWithStatus) {
|
||||||
comms, err := platform.CommunicationsForOrganization(ctx, int64(user.Organization.ID))
|
comms, err := platform.CommunicationsForOrganization(ctx, int64(user.Organization.ID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nhttp.NewError("nuisance report query: %w", err)
|
return nil, nhttp.NewError("nuisance report query: %w", err)
|
||||||
|
|
@ -84,13 +74,13 @@ func (res *communicationR) List(ctx context.Context, r *http.Request, user platf
|
||||||
for _, pr := range public_reports {
|
for _, pr := range public_reports {
|
||||||
public_report_id_to_report[pr.ID] = pr
|
public_report_id_to_report[pr.ID] = pr
|
||||||
}
|
}
|
||||||
result := make([]communicationStub, len(comms))
|
result := make([]communication, len(comms))
|
||||||
for i, comm := range comms {
|
for i, comm := range comms {
|
||||||
public_report, ok := public_report_id_to_report[*comm.SourceReportID]
|
public_report, ok := public_report_id_to_report[*comm.SourceReportID]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, nhttp.NewError("lookup report id %d failed", comm.SourceReportID)
|
return nil, nhttp.NewError("lookup report id %d failed", comm.SourceReportID)
|
||||||
}
|
}
|
||||||
c, err := res.hydrateCommunicationStub(comm, &public_report)
|
c, err := res.hydrateCommunication(comm, &public_report)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -114,61 +104,39 @@ func (res *communicationR) MarkPossibleResolved(ctx context.Context, r *http.Req
|
||||||
return res.markCommunication(ctx, r, user, "possible-resolved", platform.CommunicationMarkPossibleResolved)
|
return res.markCommunication(ctx, r, user, "possible-resolved", platform.CommunicationMarkPossibleResolved)
|
||||||
}
|
}
|
||||||
func (res *communicationR) hydrateCommunication(comm modelpublic.Communication, public_report *modelpublicreport.Report) (communication, *nhttp.ErrorWithStatus) {
|
func (res *communicationR) hydrateCommunication(comm modelpublic.Communication, public_report *modelpublicreport.Report) (communication, *nhttp.ErrorWithStatus) {
|
||||||
var err error
|
|
||||||
stub, err := res.hydrateCommunicationStub(comm, public_report)
|
|
||||||
if err != nil {
|
|
||||||
return communication{}, nhttp.NewError("hydrate stub: %w", err)
|
|
||||||
}
|
|
||||||
response, err := responseURI(*res.router, comm)
|
|
||||||
if err != nil {
|
|
||||||
return communication{}, nhttp.NewError("gen response URI: %w", err)
|
|
||||||
}
|
|
||||||
return communication{
|
|
||||||
Created: stub.Created,
|
|
||||||
ID: stub.ID,
|
|
||||||
Response: response,
|
|
||||||
Source: stub.Source,
|
|
||||||
Status: stub.Status,
|
|
||||||
Type: stub.Type,
|
|
||||||
URI: stub.URI,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
func (res *communicationR) hydrateCommunicationStub(comm modelpublic.Communication, public_report *modelpublicreport.Report) (communicationStub, *nhttp.ErrorWithStatus) {
|
|
||||||
var err error
|
var err error
|
||||||
source_uri := "unknown"
|
source_uri := "unknown"
|
||||||
type_ := "unknown"
|
type_ := "unknown"
|
||||||
if comm.SourceReportID != nil && public_report != nil {
|
if comm.SourceReportID != nil && public_report != nil {
|
||||||
source_uri, err = reportURI(res.router, "", public_report.PublicID)
|
source_uri, err = reportURI(res.router, "", public_report.PublicID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return communicationStub{}, nhttp.NewError("gen report URI: %w", err)
|
return communication{}, nhttp.NewError("gen report URI: %w", err)
|
||||||
}
|
}
|
||||||
type_ = "publicreport." + public_report.ReportType.String()
|
type_ = "publicreport." + public_report.ReportType.String()
|
||||||
} else if comm.SourceEmailLogID != nil {
|
} else if comm.SourceEmailLogID != nil {
|
||||||
source_uri, err = emailURI(*res.router, *comm.SourceEmailLogID)
|
source_uri, err = emailURI(*res.router, *comm.SourceEmailLogID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return communicationStub{}, nhttp.NewError("gen email URI: %w", err)
|
return communication{}, nhttp.NewError("gen email URI: %w", err)
|
||||||
}
|
}
|
||||||
type_ = "email"
|
type_ = "email"
|
||||||
} else if comm.SourceTextLogID != nil {
|
} else if comm.SourceTextLogID != nil {
|
||||||
source_uri, err = textURI(*res.router, *comm.SourceTextLogID)
|
source_uri, err = textURI(*res.router, *comm.SourceTextLogID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return communicationStub{}, nhttp.NewError("gen email URI: %w", err)
|
return communication{}, nhttp.NewError("gen email URI: %w", err)
|
||||||
}
|
}
|
||||||
source_uri = "text"
|
source_uri = "text"
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
response, err := responseURI(*res.router, comm)
|
response, err := responseURI(*res.router, comm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return communicationStub{}, nhttp.NewError("gen response URI: %w", err)
|
return communication{}, nhttp.NewError("gen response URI: %w", err)
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
uri, err := res.router.IDToURI("communication.ByIDGet", int(comm.ID))
|
uri, err := res.router.IDToURI("communication.ByIDGet", int(comm.ID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return communicationStub{}, nhttp.NewError("gen comm uri: %w", err)
|
return communication{}, nhttp.NewError("gen comm uri: %w", err)
|
||||||
}
|
}
|
||||||
return communicationStub{
|
return communication{
|
||||||
Created: comm.Created,
|
|
||||||
ID: strconv.Itoa(int(comm.ID)),
|
ID: strconv.Itoa(int(comm.ID)),
|
||||||
|
Response: response,
|
||||||
Source: source_uri,
|
Source: source_uri,
|
||||||
Status: comm.Status.String(),
|
Status: comm.Status.String(),
|
||||||
Type: type_,
|
Type: type_,
|
||||||
|
|
|
||||||
|
|
@ -152,9 +152,9 @@ func (res *complianceR) Update(ctx context.Context, r *http.Request, prf publicR
|
||||||
if public_id == "" {
|
if public_id == "" {
|
||||||
return nil, nhttp.NewBadRequest("You must provide an ID")
|
return nil, nhttp.NewBadRequest("You must provide an ID")
|
||||||
}
|
}
|
||||||
report_updater := querypublicreport.NewReportUpdater()
|
report_updater := querypublicreport.ReportUpdater{}
|
||||||
//report_setter := models.PublicreportReportSetter{}
|
//report_setter := models.PublicreportReportSetter{}
|
||||||
compliance_updater := querypublicreport.NewComplianceUpdater()
|
compliance_updater := querypublicreport.ComplianceUpdater{}
|
||||||
//compliance_setter := models.PublicreportComplianceSetter{}
|
//compliance_setter := models.PublicreportComplianceSetter{}
|
||||||
var location *types.Location
|
var location *types.Location
|
||||||
if prf.Location.IsValue() {
|
if prf.Location.IsValue() {
|
||||||
|
|
|
||||||
|
|
@ -1,50 +1,14 @@
|
||||||
<style>
|
|
||||||
.global-error-toast {
|
|
||||||
position: fixed;
|
|
||||||
top: 20px;
|
|
||||||
right: 20px;
|
|
||||||
background: #c00;
|
|
||||||
color: white;
|
|
||||||
padding: 16px 20px;
|
|
||||||
border-radius: 8px;
|
|
||||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
|
||||||
z-index: 9999;
|
|
||||||
max-width: 400px;
|
|
||||||
animation: slideIn 0.3s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes slideIn {
|
|
||||||
from {
|
|
||||||
transform: translateX(400px);
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
to {
|
|
||||||
transform: translateX(0);
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div id="app">
|
|
||||||
<div v-if="error" class="global-error-toast">
|
|
||||||
{{ error.message }}
|
|
||||||
<button @click="errorClear">x</button>
|
|
||||||
</div>
|
|
||||||
<router-view />
|
<router-view />
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onMounted } from "vue";
|
import { onMounted } from "vue";
|
||||||
import { apiClient } from "@/client";
|
import { apiClient } from "@/client";
|
||||||
import router from "@/route/config";
|
import router from "@/route/config";
|
||||||
import { useErrorHandler } from "@/composable/error-handler";
|
|
||||||
|
|
||||||
import { SSEManager, type SSEMessageResource } from "@/SSEManager";
|
import { SSEManager, type SSEMessageResource } from "@/SSEManager";
|
||||||
|
|
||||||
const { error, errorClear } = useErrorHandler();
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
SSEManager.connect("/api/events");
|
SSEManager.connect("/api/events");
|
||||||
SSEManager.subscribe((msg: SSEMessageResource) => {
|
SSEManager.subscribe((msg: SSEMessageResource) => {
|
||||||
|
|
|
||||||
|
|
@ -1,29 +0,0 @@
|
||||||
import { ref } from "vue";
|
|
||||||
|
|
||||||
interface ErrorState {
|
|
||||||
hasError: boolean;
|
|
||||||
message: string;
|
|
||||||
timestamp: Date;
|
|
||||||
}
|
|
||||||
|
|
||||||
const globalError = ref<ErrorState | null>(null);
|
|
||||||
|
|
||||||
export function useErrorHandler() {
|
|
||||||
const setError = (error: Error) => {
|
|
||||||
globalError.value = {
|
|
||||||
hasError: true,
|
|
||||||
message: error.message,
|
|
||||||
timestamp: new Date(),
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const errorClear = () => {
|
|
||||||
globalError.value = null;
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
error: globalError,
|
|
||||||
setError,
|
|
||||||
errorClear,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
@ -174,13 +174,8 @@ function updateModel(
|
||||||
emit("update:modelValue", newLocator);
|
emit("update:modelValue", newLocator);
|
||||||
}
|
}
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
const geo_config = {
|
|
||||||
enableHighAccuracy: true,
|
|
||||||
maximumAge: Infinity,
|
|
||||||
timeout: 10000,
|
|
||||||
};
|
|
||||||
storeLocation
|
storeLocation
|
||||||
.get(geo_config)
|
.get()
|
||||||
.then((loc: GeolocationPosition) => {
|
.then((loc: GeolocationPosition) => {
|
||||||
console.log("user geolocation", loc);
|
console.log("user geolocation", loc);
|
||||||
const coords = loc.coords;
|
const coords = loc.coords;
|
||||||
|
|
|
||||||
|
|
@ -15,14 +15,10 @@ export const useStoreLocation = defineStore("location", () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default options if none provided
|
// Default options if none provided
|
||||||
const geolocationOptions =
|
const geolocationOptions = options || {
|
||||||
options ||
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
enableHighAccuracy: true,
|
enableHighAccuracy: true,
|
||||||
timeout: 60000,
|
timeout: 5000,
|
||||||
maximumAge: 0,
|
maximumAge: 0,
|
||||||
*/
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Call the geolocation API
|
// Call the geolocation API
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import App from "@/AppSync.vue";
|
||||||
import * as config from "@/config";
|
import * as config from "@/config";
|
||||||
import router from "@/route/config";
|
import router from "@/route/config";
|
||||||
import * as sentry from "@/sentry";
|
import * as sentry from "@/sentry";
|
||||||
import { useErrorHandler } from "@/composable/error-handler";
|
|
||||||
|
|
||||||
import "maplibre-gl/dist/maplibre-gl.css";
|
import "maplibre-gl/dist/maplibre-gl.css";
|
||||||
|
|
||||||
|
|
@ -19,24 +18,8 @@ import "@/gen/custom-icons.scss";
|
||||||
import * as bootstrap from "bootstrap";
|
import * as bootstrap from "bootstrap";
|
||||||
window.bootstrap = bootstrap;
|
window.bootstrap = bootstrap;
|
||||||
|
|
||||||
const { setError } = useErrorHandler();
|
|
||||||
|
|
||||||
const pinia = createPinia();
|
const pinia = createPinia();
|
||||||
const app = createApp(App);
|
const app = createApp(App);
|
||||||
app.config.errorHandler = (err, instance, info) => {
|
|
||||||
// err: the error object
|
|
||||||
// instance: the component instance where error occurred
|
|
||||||
// info: Vue-specific error info, e.g., lifecycle hook
|
|
||||||
|
|
||||||
console.error("Global error:", err);
|
|
||||||
console.error("Error info:", info);
|
|
||||||
console.error("Error instance:", instance);
|
|
||||||
|
|
||||||
// You could dispatch to a store, send to error tracking service, etc.
|
|
||||||
// For example, trigger a global error state
|
|
||||||
setError(err);
|
|
||||||
};
|
|
||||||
|
|
||||||
app.use(pinia);
|
app.use(pinia);
|
||||||
app.use(router);
|
app.use(router);
|
||||||
sentry.Init(app, pinia).then(() => {
|
sentry.Init(app, pinia).then(() => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue