add SysUpdatedOn
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-03-26 13:19:34 +11:00
parent bb999afbb7
commit 6581164fc4
6 changed files with 40 additions and 19 deletions

View File

@@ -0,0 +1,10 @@
-- +goose Up
-- +goose StatementBegin
ALTER TABLE incidents ADD COLUMN updated_at DATETIME;
UPDATE incidents SET updated_at = CURRENT_TIMESTAMP WHERE updated_at IS NULL;
-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
ALTER TABLE incidents DROP COLUMN updated_at;
-- +goose StatementEnd

View File

@@ -23,6 +23,7 @@ type Incident struct {
Category sql.NullString
SubCategory sql.NullString
SysID sql.NullString
UpdatedAt sql.NullTime
}
type Incoming struct {

View File

@@ -30,7 +30,7 @@ WHERE sys_id = sqlc.arg('sysId');
-- name: UpdateIncidentState :exec
UPDATE incidents
SET state = sqlc.arg('state')
SET state = sqlc.arg('state'), updated_at = CURRENT_TIMESTAMP
WHERE incident_number = sqlc.arg('incidentNumber');
-- name: UpdateIncident :exec
@@ -45,7 +45,8 @@ SET
assignment_group = ?,
assigned_to = ?,
category = ?,
sub_category = ?
sub_category = ?,
updated_at = CURRENT_TIMESTAMP
WHERE incident_number = ?;
-- name: GetIncident :one

View File

@@ -16,7 +16,7 @@ INSERT INTO incidents (
) VALUES(
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
)
RETURNING id, external_id, created_at, incident_number, description, short_description, urgency, impact, state, assignment_group, assigned_to, category, sub_category, sys_id
RETURNING id, external_id, created_at, incident_number, description, short_description, urgency, impact, state, assignment_group, assigned_to, category, sub_category, sys_id, updated_at
`
type CreateIncidentParams struct {
@@ -65,6 +65,7 @@ func (q *Queries) CreateIncident(ctx context.Context, arg CreateIncidentParams)
&i.Category,
&i.SubCategory,
&i.SysID,
&i.UpdatedAt,
)
return i, err
}
@@ -157,7 +158,7 @@ func (q *Queries) CreateWorkNote(ctx context.Context, arg CreateWorkNoteParams)
}
const getIncident = `-- name: GetIncident :one
SELECT id, external_id, created_at, incident_number, description, short_description, urgency, impact, state, assignment_group, assigned_to, category, sub_category, sys_id from incidents
SELECT id, external_id, created_at, incident_number, description, short_description, urgency, impact, state, assignment_group, assigned_to, category, sub_category, sys_id, updated_at from incidents
WHERE incident_number = ?1
`
@@ -179,12 +180,13 @@ func (q *Queries) GetIncident(ctx context.Context, incidentnumber sql.NullString
&i.Category,
&i.SubCategory,
&i.SysID,
&i.UpdatedAt,
)
return i, err
}
const getIncidentReport = `-- name: GetIncidentReport :many
SELECT incidents.id, incidents.external_id, incidents.created_at, incidents.incident_number, incidents.description, incidents.short_description, incidents.urgency, incidents.impact, incidents.state, incidents.assignment_group, incidents.assigned_to, incidents.category, incidents.sub_category, incidents.sys_id, IFNULL(GROUP_CONCAT(worknotes.note, '<br />'), ' ') AS all_notes
SELECT incidents.id, incidents.external_id, incidents.created_at, incidents.incident_number, incidents.description, incidents.short_description, incidents.urgency, incidents.impact, incidents.state, incidents.assignment_group, incidents.assigned_to, incidents.category, incidents.sub_category, incidents.sys_id, incidents.updated_at, IFNULL(GROUP_CONCAT(worknotes.note, '<br />'), ' ') AS all_notes
FROM incidents LEFT JOIN worknotes ON incidents.incident_number = worknotes.incident_number
GROUP BY incidents.id
`
@@ -204,6 +206,7 @@ type GetIncidentReportRow struct {
Category sql.NullString
SubCategory sql.NullString
SysID sql.NullString
UpdatedAt sql.NullTime
AllNotes interface{}
}
@@ -231,6 +234,7 @@ func (q *Queries) GetIncidentReport(ctx context.Context) ([]GetIncidentReportRow
&i.Category,
&i.SubCategory,
&i.SysID,
&i.UpdatedAt,
&i.AllNotes,
); err != nil {
return nil, err
@@ -280,7 +284,7 @@ func (q *Queries) GetIncidentWorkNotes(ctx context.Context, incidentnumber strin
}
const listIncidents = `-- name: ListIncidents :many
SELECT id, external_id, created_at, incident_number, description, short_description, urgency, impact, state, assignment_group, assigned_to, category, sub_category, sys_id FROM incidents
SELECT id, external_id, created_at, incident_number, description, short_description, urgency, impact, state, assignment_group, assigned_to, category, sub_category, sys_id, updated_at FROM incidents
`
func (q *Queries) ListIncidents(ctx context.Context) ([]Incident, error) {
@@ -307,6 +311,7 @@ func (q *Queries) ListIncidents(ctx context.Context) ([]Incident, error) {
&i.Category,
&i.SubCategory,
&i.SysID,
&i.UpdatedAt,
); err != nil {
return nil, err
}
@@ -408,7 +413,8 @@ SET
assignment_group = ?,
assigned_to = ?,
category = ?,
sub_category = ?
sub_category = ?,
updated_at = CURRENT_TIMESTAMP
WHERE incident_number = ?
`
@@ -477,7 +483,7 @@ func (q *Queries) UpdateIncidentNumberSysId(ctx context.Context, arg UpdateIncid
const updateIncidentState = `-- name: UpdateIncidentState :exec
UPDATE incidents
SET state = ?1
SET state = ?1, updated_at = CURRENT_TIMESTAMP
WHERE incident_number = ?2
`

View File

@@ -127,6 +127,7 @@ func (h *Handler) GetIncident(w http.ResponseWriter, r *http.Request) {
AssignedTo: inc.AssignedTo.String,
Category: inc.Category.String,
Subcategory: inc.SubCategory.String,
SysUpdatedOn: inc.UpdatedAt.Time.String(),
CommentsAndWorkNotes: strings.Join(wkn, "\n\n"),
// TODO
}
@@ -195,7 +196,7 @@ func (h *Handler) GetIncident(w http.ResponseWriter, r *http.Request) {
func (h *Handler) getSingleIncident(number string, ctx context.Context) ([]byte, error) {
var b []byte
var wkn []string
incResult, err := h.Database.Queries().GetIncident(ctx, nullStr(number))
inc, err := h.Database.Queries().GetIncident(ctx, nullStr(number))
if err != nil {
if errors.Is(err, sql.ErrNoRows) {
h.Logger.Debug("No incident record found", "number", number)
@@ -224,16 +225,17 @@ func (h *Handler) getSingleIncident(number string, ctx context.Context) ([]byte,
// convert from database resposne to expected json format
r := models.SingleIncidentResponse{
Number: incResult.IncidentNumber.String,
SysID: incResult.SysID.String,
IncidentState: strconv.FormatInt(incResult.State.Int64, 10),
State: strconv.FormatInt(incResult.State.Int64, 10),
Impact: strconv.FormatInt(incResult.Impact.Int64, 10),
Urgency: strconv.FormatInt(incResult.Urgency.Int64, 10),
ShortDescription: incResult.ShortDescription.String,
AssignedTo: incResult.AssignedTo.String,
Category: incResult.Category.String,
Subcategory: incResult.SubCategory.String,
Number: inc.IncidentNumber.String,
SysID: inc.SysID.String,
IncidentState: strconv.FormatInt(inc.State.Int64, 10),
State: strconv.FormatInt(inc.State.Int64, 10),
Impact: strconv.FormatInt(inc.Impact.Int64, 10),
Urgency: strconv.FormatInt(inc.Urgency.Int64, 10),
ShortDescription: inc.ShortDescription.String,
AssignedTo: inc.AssignedTo.String,
Category: inc.Category.String,
Subcategory: inc.SubCategory.String,
SysUpdatedOn: inc.UpdatedAt.Time.String(),
CommentsAndWorkNotes: strings.Join(wkn, "\n\n"),
// TODO
}

View File

@@ -30,6 +30,7 @@ type SingleIncidentResponse struct {
Category string `json:"category"`
Subcategory string `json:"subcategory"`
CommentsAndWorkNotes string `json:"comments_and_work_notes"`
SysUpdatedOn string `json:"sys_updated_on"`
// TODO - unvalidated from here on
// Associated DeviceID (UUID from CPDB)