Add talkgroup tags
This commit is contained in:
parent
72edd16d7b
commit
c79bfc0fde
6 changed files with 123 additions and 7 deletions
|
@ -20,7 +20,7 @@ func main() {
|
||||||
Use: gordio.AppName,
|
Use: gordio.AppName,
|
||||||
}
|
}
|
||||||
rootCmd.PersistentFlags().StringP("config", "c", "config.yaml", "config file")
|
rootCmd.PersistentFlags().StringP("config", "c", "config.yaml", "config file")
|
||||||
|
|
||||||
err := rootCmd.ParseFlags(os.Args)
|
err := rootCmd.ParseFlags(os.Args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Err(err).Msg("parsing flags")
|
log.Fatal().Err(err).Msg("parsing flags")
|
||||||
|
|
|
@ -67,11 +67,16 @@ type Talkgroup struct {
|
||||||
System int32
|
System int32
|
||||||
Name pgtype.Text
|
Name pgtype.Text
|
||||||
Frequency pgtype.Int4
|
Frequency pgtype.Int4
|
||||||
GroupID pgtype.Int4
|
Tgid int32
|
||||||
AutoCreated pgtype.Bool
|
AutoCreated pgtype.Bool
|
||||||
Metadata []byte
|
Metadata []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TalkgroupsTag struct {
|
||||||
|
TalkgroupID int32
|
||||||
|
Tags []string
|
||||||
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
ID int32
|
ID int32
|
||||||
Username string
|
Username string
|
||||||
|
|
88
pkg/gordio/database/talkgroups.sql.go
Normal file
88
pkg/gordio/database/talkgroups.sql.go
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
// Code generated by sqlc. DO NOT EDIT.
|
||||||
|
// versions:
|
||||||
|
// sqlc v1.26.0
|
||||||
|
// source: talkgroups.sql
|
||||||
|
|
||||||
|
package database
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
)
|
||||||
|
|
||||||
|
const getTalkgroupTags = `-- name: GetTalkgroupTags :one
|
||||||
|
SELECT tags FROM talkgroups_tags
|
||||||
|
WHERE talkgroup_id = $1
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) GetTalkgroupTags(ctx context.Context, talkgroupID int32) ([]string, error) {
|
||||||
|
row := q.db.QueryRow(ctx, getTalkgroupTags, talkgroupID)
|
||||||
|
var tags []string
|
||||||
|
err := row.Scan(&tags)
|
||||||
|
return tags, err
|
||||||
|
}
|
||||||
|
|
||||||
|
const getTalkgroupsWithAllTags = `-- name: GetTalkgroupsWithAllTags :many
|
||||||
|
SELECT talkgroup_id, tags FROM talkgroups_tags
|
||||||
|
WHERE tags && ARRAY[$1]
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) GetTalkgroupsWithAllTags(ctx context.Context, tags []string) ([]TalkgroupsTag, error) {
|
||||||
|
rows, err := q.db.Query(ctx, getTalkgroupsWithAllTags, tags)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []TalkgroupsTag
|
||||||
|
for rows.Next() {
|
||||||
|
var i TalkgroupsTag
|
||||||
|
if err := rows.Scan(&i.TalkgroupID, &i.Tags); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, i)
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
const getTalkgroupsWithAnyTags = `-- name: GetTalkgroupsWithAnyTags :many
|
||||||
|
SELECT talkgroup_id, tags FROM talkgroups_tags
|
||||||
|
WHERE tags @> ARRAY[$1]
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) GetTalkgroupsWithAnyTags(ctx context.Context, tags []string) ([]TalkgroupsTag, error) {
|
||||||
|
rows, err := q.db.Query(ctx, getTalkgroupsWithAnyTags, tags)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []TalkgroupsTag
|
||||||
|
for rows.Next() {
|
||||||
|
var i TalkgroupsTag
|
||||||
|
if err := rows.Scan(&i.TalkgroupID, &i.Tags); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
items = append(items, i)
|
||||||
|
}
|
||||||
|
if err := rows.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return items, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
const setTalkgroupTags = `-- name: SetTalkgroupTags :exec
|
||||||
|
INSERT INTO talkgroups_tags(talkgroup_id, tags) VALUES($1, $2)
|
||||||
|
ON CONFLICT (talkgroup_id) DO UPDATE
|
||||||
|
SET tags = $2
|
||||||
|
`
|
||||||
|
|
||||||
|
type SetTalkgroupTagsParams struct {
|
||||||
|
TalkgroupID int32
|
||||||
|
Tags []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (q *Queries) SetTalkgroupTags(ctx context.Context, arg SetTalkgroupTagsParams) error {
|
||||||
|
_, err := q.db.Exec(ctx, setTalkgroupTags, arg.TalkgroupID, arg.Tags)
|
||||||
|
return err
|
||||||
|
}
|
|
@ -68,11 +68,11 @@ func (s *Server) routeAuth(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
http.SetCookie(w, &http.Cookie{
|
http.SetCookie(w, &http.Cookie{
|
||||||
Name: "jwt",
|
Name: "jwt",
|
||||||
Value: tok,
|
Value: tok,
|
||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
Secure: true,
|
Secure: true,
|
||||||
Domain: s.conf.Domain,
|
Domain: s.conf.Domain,
|
||||||
})
|
})
|
||||||
|
|
||||||
jr := struct {
|
jr := struct {
|
||||||
|
|
|
@ -28,12 +28,19 @@ CREATE TABLE IF NOT EXISTS talkgroups(
|
||||||
system INTEGER REFERENCES systems(id) NOT NULL,
|
system INTEGER REFERENCES systems(id) NOT NULL,
|
||||||
name TEXT,
|
name TEXT,
|
||||||
frequency INTEGER,
|
frequency INTEGER,
|
||||||
group_id INTEGER,
|
tgid INTEGER,
|
||||||
auto_created BOOLEAN,
|
auto_created BOOLEAN,
|
||||||
metadata JSONB,
|
metadata JSONB,
|
||||||
PRIMARY KEY (tgid, system)
|
PRIMARY KEY (tgid, system)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS talkgroups_tags(
|
||||||
|
talkgroup_id INTEGER NOT NULL REFERENCES talkgroups(id),
|
||||||
|
tags TEXT[] NOT NULL DEFAULT '{}'
|
||||||
|
);
|
||||||
|
CREATE UNIQUE INDEX IF NOT EXISTS talkgroups_tags_id_talkgroup_id ON talkgroups_tags(talkgroup_id);
|
||||||
|
CREATE INDEX IF NOT EXISTS talkgroup_tags_id_tags ON talkgroups_tags USING GIN (tags);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS calls(
|
CREATE TABLE IF NOT EXISTS calls(
|
||||||
id UUID PRIMARY KEY,
|
id UUID PRIMARY KEY,
|
||||||
submitter INTEGER REFERENCES api_keys(id) ON DELETE SET NULL,
|
submitter INTEGER REFERENCES api_keys(id) ON DELETE SET NULL,
|
||||||
|
|
16
sql/postgres/queries/talkgroups.sql
Normal file
16
sql/postgres/queries/talkgroups.sql
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
-- name: GetTalkgroupsWithAnyTags :many
|
||||||
|
SELECT * FROM talkgroups_tags
|
||||||
|
WHERE tags @> ARRAY[$1];
|
||||||
|
|
||||||
|
-- name: GetTalkgroupsWithAllTags :many
|
||||||
|
SELECT * FROM talkgroups_tags
|
||||||
|
WHERE tags && ARRAY[$1];
|
||||||
|
|
||||||
|
-- name: GetTalkgroupTags :one
|
||||||
|
SELECT tags FROM talkgroups_tags
|
||||||
|
WHERE talkgroup_id = $1;
|
||||||
|
|
||||||
|
-- name: SetTalkgroupTags :exec
|
||||||
|
INSERT INTO talkgroups_tags(talkgroup_id, tags) VALUES($1, $2)
|
||||||
|
ON CONFLICT (talkgroup_id) DO UPDATE SET tags = $2;
|
||||||
|
|
Loading…
Reference in a new issue