nidus-sync/db/query/comms/contact_phone.go
Eli Ribble f1fe8b4d2b
Add contacts, rework comms schema
This in a pretty huge change. At a high level we're adding the concept
of a 'contact' which is a person or organization that has zero or more
contact methods (email, phone). This ended up cascading a number of
changes, including critically to the publicreprt schema. In the end it
seemed safer to get to the point where I'm confident we aren't using any
of the old fields for storing reporter information (though I haven't
deleted the columns yet) so I removed the code for defining those
columns.

At this point I think it's not possible for me to regenerate the bob
schema due to the interdependencies between my various schemas, so the
migration is well-and-truly happening.
2026-05-15 16:58:28 +00:00

59 lines
2.3 KiB
Go

package comms
import (
"context"
//"github.com/Gleipnir-Technology/bob"
"github.com/Gleipnir-Technology/nidus-sync/db"
//"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/public/enum"
"github.com/Gleipnir-Technology/jet/postgres"
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/comms/model"
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/comms/table"
)
func ContactPhoneInsert(ctx context.Context, txn db.Ex, m model.ContactPhone) (model.ContactPhone, error) {
statement := table.ContactPhone.INSERT(table.ContactPhone.MutableColumns).
MODEL(m).
RETURNING(table.ContactPhone.AllColumns)
return db.ExecuteOneTx[model.ContactPhone](ctx, txn, statement)
}
func ContactPhoneFromE164(ctx context.Context, txn db.Ex, e164 string) (model.ContactPhone, error) {
statement := table.ContactPhone.SELECT(
table.ContactPhone.AllColumns,
).FROM(table.ContactPhone).
WHERE(table.ContactPhone.E164.EQ(postgres.String(e164)))
return db.ExecuteOneTx[model.ContactPhone](ctx, txn, statement)
}
func ContactPhoneUpdateConfirmedMessageID(ctx context.Context, txn db.Ex, e164 string, message_id *int32) error {
statement := table.ContactPhone.UPDATE().
SET(table.ContactPhone.ConfirmedMessageID.SET(postgres.IntExp(postgres.NULL))).
WHERE(table.ContactPhone.E164.EQ(postgres.String(e164)))
return db.ExecuteNoneTx(ctx, txn, statement)
}
func ContactPhoneUpdateStopMessageID(ctx context.Context, txn db.Ex, e164 string, message_id *int32) error {
/*
m := model.ContactPhone{}
m.StopMessageID = message_id
statement := table.ContactPhone.UPDATE(
table.ContactPhone.StopMessageID,
).MODEL(m).
WHERE(table.ContactPhone.E164.EQ(postgres.String(e164)))
*/
statement := table.ContactPhone.UPDATE().
SET(table.ContactPhone.StopMessageID.SET(postgres.IntExp(postgres.NULL))).
WHERE(table.ContactPhone.E164.EQ(postgres.String(e164)))
return db.ExecuteNoneTx(ctx, txn, statement)
}
/*
func ContactPhonesFromAddress(ctx context.Context, address string) ([]model.ContactPhone, error) {
statement := table.ContactPhone.SELECT(
table.ContactPhone.AllColumns,
).FROM(table.ContactPhone).
WHERE(table.ContactPhone.Source.EQ(postgres.String(address)).OR(
table.ContactPhone.Destination.EQ(postgres.String(address))))
return db.ExecuteMany[model.ContactPhone](ctx, statement)
}
*/