Return communication database rows from communication API
This is a pretty big refactor of how communication works to start moving us in the direction we want to go long-term. This adds the new communication row and migrates existing reports to add rows for communication. There's also a bunch of automatic fixes from the new linter. I should have added them separately, but whatever.
This commit is contained in:
parent
a6ce0b7e67
commit
a82732a49c
41 changed files with 365 additions and 220 deletions
|
|
@ -792,9 +792,7 @@ func rowmapViaQuery(ctx context.Context, table string, sorted_columns []string,
|
|||
|
||||
// +2 for geometry x and geometry x
|
||||
columnNames := make([]string, len(sorted_columns)+2)
|
||||
for i, c := range sorted_columns {
|
||||
columnNames[i] = c
|
||||
}
|
||||
copy(columnNames, sorted_columns)
|
||||
columnNames[len(sorted_columns)] = "geometry_x"
|
||||
columnNames[len(sorted_columns)+1] = "geometry_y"
|
||||
|
||||
|
|
@ -1031,7 +1029,7 @@ func selectAllFromQueryResult(table string, sorted_columns []string) string {
|
|||
return sb.String()
|
||||
}
|
||||
func toHistoryTable(table string) string {
|
||||
return "History_" + table[3:len(table)]
|
||||
return "History_" + table[3:]
|
||||
}
|
||||
|
||||
func updateRowFromFeatureFS(ctx context.Context, transaction bob.Tx, table string, sorted_columns []string, feature *response.Feature) error {
|
||||
|
|
@ -1618,7 +1616,7 @@ func aggregateAtResolution(ctx context.Context, resolution int, org_id int32, ty
|
|||
if err != nil {
|
||||
return fmt.Errorf("Failed to clear previous aggregation: %w", err)
|
||||
}
|
||||
var to_insert []bob.Mod[*dialect.InsertQuery] = make([]bob.Mod[*dialect.InsertQuery], 0)
|
||||
var to_insert = make([]bob.Mod[*dialect.InsertQuery], 0)
|
||||
to_insert = append(to_insert, im.Into("h3_aggregation", "cell", "resolution", "count_", "type_", "organization_id", "geometry"))
|
||||
for cell, count := range cellToCount {
|
||||
polygon, err := h3utils.CellToPostgisGeometry(cell)
|
||||
|
|
|
|||
12
platform/communication.go
Normal file
12
platform/communication.go
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
package platform
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/gen/nidus-sync/public/model"
|
||||
querypublic "github.com/Gleipnir-Technology/nidus-sync/db/query/public"
|
||||
)
|
||||
|
||||
func CommunicationsForOrganization(ctx context.Context, org_id int64) ([]*model.Communication, error) {
|
||||
return querypublic.CommunicationsFromOrganization(ctx, org_id)
|
||||
}
|
||||
|
|
@ -156,7 +156,7 @@ func geocodePool(ctx context.Context, txn bob.Tx, client *stadia.StadiaMaps, job
|
|||
return nil
|
||||
}
|
||||
if geo.Address.Location == nil {
|
||||
addError(ctx, txn, job.csv, pool.LineNumber, 0, fmt.Sprintf("nil location from geocoding"))
|
||||
addError(ctx, txn, job.csv, pool.LineNumber, 0, "nil location from geocoding")
|
||||
return nil
|
||||
}
|
||||
geom_query := geom.PostgisPointQuery(*geo.Address.Location)
|
||||
|
|
@ -329,7 +329,7 @@ func parseHeaders(row []string) ([]headerPoolEnum, []string) {
|
|||
ht := strings.TrimSpace(h)
|
||||
hl := strings.ToLower(ht)
|
||||
log.Debug().Str("header", hl).Msg("Saw CSV header")
|
||||
var type_ headerPoolEnum = headerPoolTag
|
||||
var type_ = headerPoolTag
|
||||
switch hl {
|
||||
case "city":
|
||||
type_ = headerPoolAddressLocality
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ func createLabelStudioClient() (*labelstudio.Client, error) {
|
|||
// Get and store the access token
|
||||
err := labelStudioClient.GetAccessToken()
|
||||
if err != nil {
|
||||
return nil, errors.New(fmt.Sprintf("Failed to get access token: %v", err))
|
||||
return nil, fmt.Errorf("Failed to get access token: %v", err)
|
||||
}
|
||||
log.Println("Got label studio client access token")
|
||||
|
||||
|
|
@ -116,7 +116,7 @@ func createTask(client *labelstudio.Client, project *labelstudio.Project, minioC
|
|||
return fmt.Errorf("Failed to upload audio: %v", err)
|
||||
}
|
||||
}
|
||||
var transcription string = ""
|
||||
var transcription = ""
|
||||
//if note.Transcription.IsValue() {
|
||||
//transcription = note.Transcription.MustGet()
|
||||
//}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,11 @@ import (
|
|||
"github.com/Gleipnir-Technology/bob/dialect/psql/um"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db"
|
||||
"github.com/Gleipnir-Technology/nidus-sync/db/enums"
|
||||
"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/db/models"
|
||||
querypublic "github.com/Gleipnir-Technology/nidus-sync/db/query/public"
|
||||
querypublicreport "github.com/Gleipnir-Technology/nidus-sync/db/query/publicreport"
|
||||
"github.com/aarondl/opt/omit"
|
||||
"github.com/aarondl/opt/omitnull"
|
||||
//"github.com/Gleipnir-Technology/nidus-sync/platform/background"
|
||||
|
|
@ -214,6 +218,9 @@ func PublicReportReporterUpdated(ctx context.Context, org_id int32, report_id st
|
|||
func PublicReportsForOrganization(ctx context.Context, org_id int32, is_public bool) ([]*types.PublicReport, error) {
|
||||
return publicreport.ReportsForOrganization(ctx, org_id, is_public)
|
||||
}
|
||||
func PublicReportsFromIDs(ctx context.Context, report_ids []int64) ([]*modelpublicreport.Report, error) {
|
||||
return querypublicreport.PublicReportsFromIDs(ctx, report_ids)
|
||||
}
|
||||
func PublicReportComplianceCreate(ctx context.Context, setter_report models.PublicreportReportSetter, setter_compliance models.PublicreportComplianceSetter, org_id int32) (*models.PublicreportReport, error) {
|
||||
return publicReportCreate(ctx, setter_report, nil, nil, nil, org_id, func(ctx context.Context, txn bob.Executor, report_id int32) error {
|
||||
setter_compliance.ReportID = omit.From(report_id)
|
||||
|
|
@ -382,6 +389,15 @@ func publicReportCreate(ctx context.Context, setter_report models.PublicreportRe
|
|||
UserID: omitnull.FromPtr[int32](nil),
|
||||
}).One(ctx, txn)
|
||||
|
||||
comm := &model.Communication{
|
||||
SourceReportID: &result.ID,
|
||||
}
|
||||
comm, err = querypublic.CommunicationInsert(ctx, txn, comm)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("insert communication: %w", err)
|
||||
}
|
||||
log.Debug().Int32("id", comm.ID).Msg("inserted new communication")
|
||||
|
||||
txn.Commit(ctx)
|
||||
|
||||
event.Created(
|
||||
|
|
|
|||
|
|
@ -59,9 +59,7 @@ func logEntriesByReportID(ctx context.Context, report_ids []int32, is_public boo
|
|||
if !ok {
|
||||
return results, fmt.Errorf("no text logs for %d", report_id)
|
||||
}
|
||||
for _, l := range logs {
|
||||
cur_logs = append(cur_logs, l)
|
||||
}
|
||||
cur_logs = append(cur_logs, logs...)
|
||||
results[report_id] = cur_logs
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,10 +38,8 @@ func HandleTextMessage(ctx context.Context, source string, destination string, c
|
|||
if err != nil {
|
||||
return fmt.Errorf("Failed to get phone status")
|
||||
}
|
||||
is_visible_to_llm := true
|
||||
if status == enums.CommsPhonestatustypeUnconfirmed {
|
||||
is_visible_to_llm = false
|
||||
}
|
||||
is_visible_to_llm := !(status == enums.CommsPhonestatustypeUnconfirmed)
|
||||
|
||||
l, err := models.CommsTextLogs.Insert(&models.CommsTextLogSetter{
|
||||
//ID:
|
||||
Content: omit.From(content),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package platform
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
|
|
@ -257,7 +256,7 @@ func toTemplateTrapsNearby(locations []sql.TrapLocationBySourceIDRow, trap_data
|
|||
for _, td := range trap_data {
|
||||
c, ok := count_by_trap_data_id[td.Globalid]
|
||||
if !ok {
|
||||
return results, errors.New(fmt.Sprintf("Failed to find trap count for %s", td.Globalid))
|
||||
return results, fmt.Errorf("Failed to find trap count for %s", td.Globalid)
|
||||
}
|
||||
loc_id := td.LocID
|
||||
count := &TrapCount{
|
||||
|
|
@ -278,7 +277,7 @@ func toTemplateTrapsNearby(locations []sql.TrapLocationBySourceIDRow, trap_data
|
|||
for _, location := range locations {
|
||||
counts, ok := counts_by_location_id[location.TrapLocationGlobalid]
|
||||
if !ok {
|
||||
return results, errors.New(fmt.Sprintf("Failed to find counts for %s", location.TrapLocationGlobalid))
|
||||
return results, fmt.Errorf("Failed to find counts for %s", location.TrapLocationGlobalid)
|
||||
}
|
||||
trap := TrapNearby{
|
||||
Counts: counts,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue