diff --git a/pkg/calls/call.go b/pkg/calls/call.go index 9b8e78d..d7d8c0e 100644 --- a/pkg/calls/call.go +++ b/pkg/calls/call.go @@ -9,6 +9,7 @@ import ( "dynatron.me/x/stillbox/pkg/pb" "dynatron.me/x/stillbox/pkg/talkgroups" + "github.com/google/uuid" "google.golang.org/protobuf/types/known/timestamppb" ) @@ -32,6 +33,7 @@ func (d CallDuration) Seconds() int32 { } type Call struct { + ID uuid.UUID Audio []byte AudioName string AudioType string @@ -68,6 +70,7 @@ func Make(call *Call, dontStore bool) (*Call, error) { } call.shouldStore = dontStore + call.ID = uuid.New() return call, nil } @@ -92,6 +95,7 @@ func toInt32Slice(s []int) []int32 { func (c *Call) ToPB() *pb.Call { return &pb.Call{ + Id: c.ID.String(), AudioName: c.AudioName, AudioType: c.AudioType, DateTime: timestamppb.New(c.DateTime), diff --git a/pkg/database/calls.sql.go b/pkg/database/calls.sql.go index 73f3f71..cfed6e7 100644 --- a/pkg/database/calls.sql.go +++ b/pkg/database/calls.sql.go @@ -52,30 +52,48 @@ func (q *Queries) AddAlert(ctx context.Context, arg AddAlertParams) error { return err } -const addCall = `-- name: AddCall :one +const addCall = `-- name: AddCall :exec INSERT INTO calls ( - id, - submitter, - system, - talkgroup, - call_date, - audio_name, - audio_blob, - audio_type, - audio_url, - duration, - frequency, - frequencies, - patches, - tg_label, - tg_alpha_tag, - tg_group, - source - ) VALUES (gen_random_uuid(), $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16) -RETURNING id +id, +submitter, +system, +talkgroup, +call_date, +audio_name, +audio_blob, +audio_type, +audio_url, +duration, +frequency, +frequencies, +patches, +tg_label, +tg_alpha_tag, +tg_group, +source +) VALUES ( +$1, +$2, +$3, +$4, +$5, +$6, +$7, +$8, +$9, +$10, +$11, +$12, +$13, +$14, +$15, +$16, +$17 +) ` type AddCallParams struct { + ID uuid.UUID `json:"id"` Submitter *int32 `json:"submitter"` System int `json:"system"` Talkgroup int `json:"talkgroup"` @@ -94,8 +112,9 @@ type AddCallParams struct { Source int `json:"source"` } -func (q *Queries) AddCall(ctx context.Context, arg AddCallParams) (uuid.UUID, error) { - row := q.db.QueryRow(ctx, addCall, +func (q *Queries) AddCall(ctx context.Context, arg AddCallParams) error { + _, err := q.db.Exec(ctx, addCall, + arg.ID, arg.Submitter, arg.System, arg.Talkgroup, @@ -113,9 +132,7 @@ func (q *Queries) AddCall(ctx context.Context, arg AddCallParams) (uuid.UUID, er arg.TgGroup, arg.Source, ) - var id uuid.UUID - err := row.Scan(&id) - return id, err + return err } const getDatabaseSize = `-- name: GetDatabaseSize :one diff --git a/pkg/database/querier.go b/pkg/database/querier.go index 9d8d057..ba1ace1 100644 --- a/pkg/database/querier.go +++ b/pkg/database/querier.go @@ -13,7 +13,7 @@ import ( type Querier interface { AddAlert(ctx context.Context, arg AddAlertParams) error - AddCall(ctx context.Context, arg AddCallParams) (uuid.UUID, error) + AddCall(ctx context.Context, arg AddCallParams) error BulkSetTalkgroupTags(ctx context.Context, iD int64, tags []string) error CreateAPIKey(ctx context.Context, owner int, expires pgtype.Timestamp, disabled *bool) (ApiKey, error) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) diff --git a/pkg/pb/stillbox.pb.go b/pkg/pb/stillbox.pb.go index 64329b2..8d29825 100644 --- a/pkg/pb/stillbox.pb.go +++ b/pkg/pb/stillbox.pb.go @@ -288,18 +288,19 @@ type Call struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - AudioName string `protobuf:"bytes,1,opt,name=audioName,proto3" json:"audioName,omitempty"` - AudioType string `protobuf:"bytes,2,opt,name=audioType,proto3" json:"audioType,omitempty"` - DateTime *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=date_time,json=dateTime,proto3" json:"date_time,omitempty"` - System int32 `protobuf:"varint,4,opt,name=system,proto3" json:"system,omitempty"` - Talkgroup int32 `protobuf:"varint,5,opt,name=talkgroup,proto3" json:"talkgroup,omitempty"` - Source int32 `protobuf:"varint,6,opt,name=source,proto3" json:"source,omitempty"` - Frequency int64 `protobuf:"varint,7,opt,name=frequency,proto3" json:"frequency,omitempty"` - Frequencies []int64 `protobuf:"varint,8,rep,packed,name=frequencies,proto3" json:"frequencies,omitempty"` - Patches []int32 `protobuf:"varint,9,rep,packed,name=patches,proto3" json:"patches,omitempty"` - Sources []int32 `protobuf:"varint,10,rep,packed,name=sources,proto3" json:"sources,omitempty"` - Duration *int32 `protobuf:"varint,11,opt,name=duration,proto3,oneof" json:"duration,omitempty"` - Audio []byte `protobuf:"bytes,12,opt,name=audio,proto3" json:"audio,omitempty"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + AudioName string `protobuf:"bytes,2,opt,name=audioName,proto3" json:"audioName,omitempty"` + AudioType string `protobuf:"bytes,3,opt,name=audioType,proto3" json:"audioType,omitempty"` + DateTime *timestamppb.Timestamp `protobuf:"bytes,4,opt,name=date_time,json=dateTime,proto3" json:"date_time,omitempty"` + System int32 `protobuf:"varint,5,opt,name=system,proto3" json:"system,omitempty"` + Talkgroup int32 `protobuf:"varint,6,opt,name=talkgroup,proto3" json:"talkgroup,omitempty"` + Source int32 `protobuf:"varint,7,opt,name=source,proto3" json:"source,omitempty"` + Frequency int64 `protobuf:"varint,8,opt,name=frequency,proto3" json:"frequency,omitempty"` + Frequencies []int64 `protobuf:"varint,9,rep,packed,name=frequencies,proto3" json:"frequencies,omitempty"` + Patches []int32 `protobuf:"varint,10,rep,packed,name=patches,proto3" json:"patches,omitempty"` + Sources []int32 `protobuf:"varint,11,rep,packed,name=sources,proto3" json:"sources,omitempty"` + Duration *int32 `protobuf:"varint,12,opt,name=duration,proto3,oneof" json:"duration,omitempty"` + Audio []byte `protobuf:"bytes,13,opt,name=audio,proto3" json:"audio,omitempty"` } func (x *Call) Reset() { @@ -334,6 +335,13 @@ func (*Call) Descriptor() ([]byte, []int) { return file_stillbox_proto_rawDescGZIP(), []int{2} } +func (x *Call) GetId() string { + if x != nil { + return x.Id + } + return "" +} + func (x *Call) GetAudioName() string { if x != nil { return x.AudioName @@ -1187,29 +1195,30 @@ var file_stillbox_proto_rawDesc = []byte{ 0x6f, 0x75, 0x70, 0x49, 0x6e, 0x66, 0x6f, 0x48, 0x00, 0x52, 0x06, 0x74, 0x67, 0x49, 0x6e, 0x66, 0x6f, 0x42, 0x12, 0x0a, 0x10, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x5f, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x0d, 0x0a, 0x0b, 0x5f, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, - 0x64, 0x5f, 0x69, 0x64, 0x22, 0x81, 0x03, 0x0a, 0x04, 0x43, 0x61, 0x6c, 0x6c, 0x12, 0x1c, 0x0a, - 0x09, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x64, 0x5f, 0x69, 0x64, 0x22, 0x91, 0x03, 0x0a, 0x04, 0x43, 0x61, 0x6c, 0x6c, 0x12, 0x0e, 0x0a, + 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1c, 0x0a, + 0x09, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x61, - 0x75, 0x64, 0x69, 0x6f, 0x54, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, + 0x75, 0x64, 0x69, 0x6f, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x54, 0x79, 0x70, 0x65, 0x12, 0x37, 0x0a, 0x09, 0x64, 0x61, 0x74, - 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, + 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x08, 0x64, 0x61, 0x74, 0x65, 0x54, 0x69, - 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x18, 0x04, 0x20, 0x01, + 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x61, - 0x6c, 0x6b, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x74, + 0x6c, 0x6b, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x74, 0x61, 0x6c, 0x6b, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x6f, 0x75, 0x72, - 0x63, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, - 0x12, 0x1c, 0x0a, 0x09, 0x66, 0x72, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x79, 0x18, 0x07, 0x20, + 0x63, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, + 0x12, 0x1c, 0x0a, 0x09, 0x66, 0x72, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x79, 0x18, 0x08, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x66, 0x72, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x79, 0x12, 0x20, - 0x0a, 0x0b, 0x66, 0x72, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x69, 0x65, 0x73, 0x18, 0x08, 0x20, + 0x0a, 0x0b, 0x66, 0x72, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x69, 0x65, 0x73, 0x18, 0x09, 0x20, 0x03, 0x28, 0x03, 0x52, 0x0b, 0x66, 0x72, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x69, 0x65, 0x73, - 0x12, 0x18, 0x0a, 0x07, 0x70, 0x61, 0x74, 0x63, 0x68, 0x65, 0x73, 0x18, 0x09, 0x20, 0x03, 0x28, + 0x12, 0x18, 0x0a, 0x07, 0x70, 0x61, 0x74, 0x63, 0x68, 0x65, 0x73, 0x18, 0x0a, 0x20, 0x03, 0x28, 0x05, 0x52, 0x07, 0x70, 0x61, 0x74, 0x63, 0x68, 0x65, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x73, 0x6f, - 0x75, 0x72, 0x63, 0x65, 0x73, 0x18, 0x0a, 0x20, 0x03, 0x28, 0x05, 0x52, 0x07, 0x73, 0x6f, 0x75, + 0x75, 0x72, 0x63, 0x65, 0x73, 0x18, 0x0b, 0x20, 0x03, 0x28, 0x05, 0x52, 0x07, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x73, 0x12, 0x1f, 0x0a, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x18, 0x0b, 0x20, 0x01, 0x28, 0x05, 0x48, 0x00, 0x52, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x88, 0x01, 0x01, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x18, 0x0c, + 0x18, 0x0c, 0x20, 0x01, 0x28, 0x05, 0x48, 0x00, 0x52, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x88, 0x01, 0x01, 0x12, 0x14, 0x0a, 0x05, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x61, 0x75, 0x64, 0x69, 0x6f, 0x42, 0x0b, 0x0a, 0x09, 0x5f, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x3e, 0x0a, 0x05, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x12, 0x35, 0x0a, 0x0b, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x69, 0x6e, 0x66, 0x6f, diff --git a/pkg/pb/stillbox.proto b/pkg/pb/stillbox.proto index 99b2bdb..815c9b3 100644 --- a/pkg/pb/stillbox.proto +++ b/pkg/pb/stillbox.proto @@ -24,18 +24,19 @@ message CommandResponse { } message Call { - string audioName = 1; - string audioType = 2; - google.protobuf.Timestamp date_time = 3; - int32 system = 4; - int32 talkgroup = 5; - int32 source = 6; - int64 frequency = 7; - repeated int64 frequencies = 8; - repeated int32 patches = 9; - repeated int32 sources = 10; - optional int32 duration = 11; - bytes audio = 12; + string id = 1; + string audioName = 2; + string audioType = 3; + google.protobuf.Timestamp date_time = 4; + int32 system = 5; + int32 talkgroup = 6; + int32 source = 7; + int64 frequency = 8; + repeated int64 frequencies = 9; + repeated int32 patches = 10; + repeated int32 sources = 11; + optional int32 duration = 12; + bytes audio = 13; } message Hello { diff --git a/pkg/sinks/database.go b/pkg/sinks/database.go index 2cf9d60..61ff7c0 100644 --- a/pkg/sinks/database.go +++ b/pkg/sinks/database.go @@ -26,12 +26,12 @@ func (s *DatabaseSink) Call(ctx context.Context, call *calls.Call) error { return nil } - dbCall, err := s.db.AddCall(ctx, s.toAddCallParams(call)) + err := s.db.AddCall(ctx, s.toAddCallParams(call)) if err != nil { return fmt.Errorf("add call: %w", err) } - log.Debug().Str("id", dbCall.String()).Int("system", call.System).Int("tgid", call.Talkgroup).Msg("stored") + log.Debug().Str("id", call.ID.String()).Int("system", call.System).Int("tgid", call.Talkgroup).Msg("stored") return nil } @@ -42,6 +42,7 @@ func (s *DatabaseSink) SinkType() string { func (s *DatabaseSink) toAddCallParams(call *calls.Call) database.AddCallParams { return database.AddCallParams{ + ID: call.ID, Submitter: call.Submitter.Int32Ptr(), System: call.System, Talkgroup: call.Talkgroup, diff --git a/sql/postgres/queries/calls.sql b/sql/postgres/queries/calls.sql index 9f4ff97..7781ee3 100644 --- a/sql/postgres/queries/calls.sql +++ b/sql/postgres/queries/calls.sql @@ -1,24 +1,41 @@ --- name: AddCall :one +-- name: AddCall :exec INSERT INTO calls ( - id, - submitter, - system, - talkgroup, - call_date, - audio_name, - audio_blob, - audio_type, - audio_url, - duration, - frequency, - frequencies, - patches, - tg_label, - tg_alpha_tag, - tg_group, - source - ) VALUES (gen_random_uuid(), $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16) -RETURNING id; +id, +submitter, +system, +talkgroup, +call_date, +audio_name, +audio_blob, +audio_type, +audio_url, +duration, +frequency, +frequencies, +patches, +tg_label, +tg_alpha_tag, +tg_group, +source +) VALUES ( +@id, +@submitter, +@system, +@talkgroup, +@call_date, +@audio_name, +@audio_blob, +@audio_type, +@audio_url, +@duration, +@frequency, +@frequencies, +@patches, +@tg_label, +@tg_alpha_tag, +@tg_group, +@source +); -- name: SetCallTranscript :exec UPDATE calls SET transcript = $2 WHERE id = $1;