initial version of endpoint

This commit is contained in:
2025-03-22 21:17:29 +11:00
parent 112ad8da1a
commit a4578fb293
13 changed files with 289 additions and 119 deletions

View File

@@ -0,0 +1,13 @@
-- +goose Up
-- +goose StatementBegin
CREATE TABLE incidents (
id INTEGER PRIMARY KEY AUTOINCREMENT,
external_id TEXT NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
DROP TABLE IF EXISTS incidents;
-- +goose StatementEnd

View File

@@ -8,6 +8,12 @@ import (
"database/sql"
)
type Incident struct {
ID int64
ExternalID string
CreatedAt sql.NullTime
}
type Incoming struct {
ID int64
IncidentNumber sql.NullString
@@ -23,4 +29,4 @@ type Incoming struct {
Category sql.NullString
Subcategory sql.NullString
CreatedAt sql.NullTime
}
}

View File

@@ -9,4 +9,9 @@ INSERT INTO "Incoming" (
) VALUES(
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
)
RETURNING *;
RETURNING *;
-- name: CreateIncident :one
INSERT INTO incidents (external_id)
VALUES (?)
RETURNING id;

View File

@@ -10,6 +10,19 @@ import (
"database/sql"
)
const createIncident = `-- name: CreateIncident :one
INSERT INTO incidents (external_id)
VALUES (?)
RETURNING id
`
func (q *Queries) CreateIncident(ctx context.Context, externalID string) (int64, error) {
row := q.db.QueryRowContext(ctx, createIncident, externalID)
var id int64
err := row.Scan(&id)
return id, err
}
const createIncoming = `-- name: CreateIncoming :one
INSERT INTO "Incoming" (
"incident_number", "description", "short_description", "urgency", "impact", "state", "external_id", "work_notes", "assignment_group", "assigned_to", "category", "subcategory", "created_at"