Start work on populating context of communication at API layer

Remove communication stub, it's a performance enhancement.
This commit is contained in:
Eli Ribble 2026-05-12 17:10:05 +00:00
parent 266004624d
commit e569bb32b7
No known key found for this signature in database
9 changed files with 331 additions and 119 deletions

View file

@ -18,21 +18,6 @@ func CommunicationInsert(ctx context.Context, txn db.Tx, m model.Communication)
RETURNING(table.Communication.AllColumns)
return db.ExecuteOneTx[model.Communication](ctx, txn, statement)
}
func CommunicationFromID(ctx context.Context, comm_id int64) (model.Communication, error) {
statement := table.Communication.SELECT(
table.Communication.AllColumns,
).FROM(table.Communication).
WHERE(table.Communication.ID.EQ(postgres.Int(comm_id)))
return db.ExecuteOne[model.Communication](ctx, statement)
}
func CommunicationsFromOrganization(ctx context.Context, org_id int64) ([]model.Communication, error) {
statement := table.Communication.SELECT(
table.Communication.AllColumns,
).FROM(table.Communication).
WHERE(table.Communication.OrganizationID.EQ(postgres.Int(org_id))).
ORDER_BY(table.Communication.Created.DESC())
return db.ExecuteMany[model.Communication](ctx, statement)
}
func CommunicationSetStatus(ctx context.Context, txn db.Tx, org_id int64, comm_id int64, status model.Communicationstatus) error {
statement := table.Communication.UPDATE().
SET(
@ -51,3 +36,11 @@ func EmailLogFromID(ctx context.Context, id int64) (model.EmailLog, error) {
WHERE(table.EmailLog.ID.EQ(postgres.Int(id)))
return db.ExecuteOne[model.EmailLog](ctx, statement)
}
func EmailLogsFromAddress(ctx context.Context, address string) ([]model.EmailLog, error) {
statement := table.EmailLog.SELECT(
table.EmailLog.AllColumns,
).FROM(table.EmailLog).
WHERE(table.EmailLog.Source.EQ(postgres.String(address)).OR(
table.EmailLog.Destination.EQ(postgres.String(address))))
return db.ExecuteMany[model.EmailLog](ctx, statement)
}

View file

@ -16,3 +16,11 @@ func TextLogFromID(ctx context.Context, id int64) (model.TextLog, error) {
WHERE(table.TextLog.ID.EQ(postgres.Int(id)))
return db.ExecuteOne[model.TextLog](ctx, statement)
}
func TextLogsFromPhoneNumber(ctx context.Context, number string) ([]model.TextLog, error) {
statement := table.TextLog.SELECT(
table.TextLog.AllColumns,
).FROM(table.TextLog).
WHERE(table.TextLog.Source.EQ(postgres.String(number)).OR(
table.TextLog.Destination.EQ(postgres.String(number))))
return db.ExecuteMany[model.TextLog](ctx, statement)
}

View file

@ -28,6 +28,14 @@ func ReportInsert(ctx context.Context, txn db.Ex, m model.Report) (model.Report,
RETURNING(table.Report.AllColumns)
return db.ExecuteOneTx[model.Report](ctx, txn, statement)
}
func ReportsFromAddressID(ctx context.Context, txn db.Ex, org_id int64, address_id int64) ([]model.Report, error) {
statement := table.Report.SELECT(
table.Report.AllColumns,
).FROM(table.Report).
WHERE(table.Report.AddressID.EQ(postgres.Int(address_id)).AND(
table.Report.OrganizationID.EQ(postgres.Int(org_id))))
return db.ExecuteManyTx[model.Report](ctx, txn, statement)
}
func ReportFromID(ctx context.Context, report_id int64) (model.Report, error) {
statement := table.Report.SELECT(
table.Report.AllColumns,
@ -87,6 +95,14 @@ func ReportFromPublicIDForOrg(ctx context.Context, txn db.Ex, public_id string,
}
return &result, nil
}
func ReportsFromReporterName(ctx context.Context, txn db.Ex, org_id int64, name string) ([]model.Report, error) {
statement := table.Report.SELECT(
table.Report.AllColumns,
).FROM(table.Report).
WHERE(table.Report.ReporterName.EQ(postgres.String(name)).AND(
table.Report.OrganizationID.EQ(postgres.Int(org_id))))
return db.ExecuteManyTx[model.Report](ctx, txn, statement)
}
func ReportsUnreviewedForOrganization(ctx context.Context, txn db.Ex, org_id int64) ([]model.Report, error) {
statement := table.Report.SELECT(
table.Report.AllColumns,