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 Category sql.NullString
SubCategory sql.NullString SubCategory sql.NullString
SysID sql.NullString SysID sql.NullString
UpdatedAt sql.NullTime
} }
type Incoming struct { type Incoming struct {

View File

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

View File

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

View File

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

View File

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