This commit is contained in:
@@ -50,6 +50,10 @@ WHERE incident_number = sqlc.arg('incidentNumber');
|
||||
-- name: ListIncidents :many
|
||||
SELECT * FROM incidents;
|
||||
|
||||
-- name: GetIncidentReport :many
|
||||
SELECT incidents.*, GROUP_CONCAT(worknotes.note, '<br />') AS all_notes
|
||||
FROM incidents LEFT JOIN worknotes ON incidents.incident_number = worknotes.incident_number;
|
||||
|
||||
-- name: CreateWorkNote :one
|
||||
INSERT into worknotes (
|
||||
"incident_number", "note"
|
||||
|
@@ -178,6 +178,68 @@ func (q *Queries) GetIncident(ctx context.Context, incidentnumber sql.NullString
|
||||
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.subcategory, incidents.sys_id, GROUP_CONCAT(worknotes.note, '<br />') AS all_notes
|
||||
FROM incidents LEFT JOIN worknotes ON incidents.incident_number = worknotes.incident_number
|
||||
`
|
||||
|
||||
type GetIncidentReportRow struct {
|
||||
ID int64
|
||||
ExternalID string
|
||||
CreatedAt sql.NullTime
|
||||
IncidentNumber sql.NullString
|
||||
Description sql.NullString
|
||||
ShortDescription sql.NullString
|
||||
Urgency sql.NullInt64
|
||||
Impact sql.NullInt64
|
||||
State sql.NullInt64
|
||||
AssignmentGroup sql.NullString
|
||||
AssignedTo sql.NullString
|
||||
Category sql.NullString
|
||||
Subcategory sql.NullString
|
||||
SysID sql.NullString
|
||||
AllNotes string
|
||||
}
|
||||
|
||||
func (q *Queries) GetIncidentReport(ctx context.Context) ([]GetIncidentReportRow, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getIncidentReport)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []GetIncidentReportRow
|
||||
for rows.Next() {
|
||||
var i GetIncidentReportRow
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.ExternalID,
|
||||
&i.CreatedAt,
|
||||
&i.IncidentNumber,
|
||||
&i.Description,
|
||||
&i.ShortDescription,
|
||||
&i.Urgency,
|
||||
&i.Impact,
|
||||
&i.State,
|
||||
&i.AssignmentGroup,
|
||||
&i.AssignedTo,
|
||||
&i.Category,
|
||||
&i.Subcategory,
|
||||
&i.SysID,
|
||||
&i.AllNotes,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listIncidents = `-- name: ListIncidents :many
|
||||
SELECT id, external_id, created_at, incident_number, description, short_description, urgency, impact, state, assignment_group, assigned_to, category, subcategory, sys_id FROM incidents
|
||||
`
|
||||
@@ -263,6 +325,53 @@ func (q *Queries) ListIncoming(ctx context.Context) ([]Incoming, error) {
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateIncident = `-- name: UpdateIncident :exec
|
||||
UPDATE incidents
|
||||
SET
|
||||
external_id = ?,
|
||||
description = ?,
|
||||
short_description = ?,
|
||||
urgency = ?,
|
||||
impact = ?,
|
||||
state = ?,
|
||||
assignment_group = ?,
|
||||
assigned_to = ?,
|
||||
category = ?,
|
||||
subcategory = ?
|
||||
WHERE incident_number = ?
|
||||
`
|
||||
|
||||
type UpdateIncidentParams struct {
|
||||
ExternalID string
|
||||
Description sql.NullString
|
||||
ShortDescription sql.NullString
|
||||
Urgency sql.NullInt64
|
||||
Impact sql.NullInt64
|
||||
State sql.NullInt64
|
||||
AssignmentGroup sql.NullString
|
||||
AssignedTo sql.NullString
|
||||
Category sql.NullString
|
||||
Subcategory sql.NullString
|
||||
IncidentNumber sql.NullString
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateIncident(ctx context.Context, arg UpdateIncidentParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateIncident,
|
||||
arg.ExternalID,
|
||||
arg.Description,
|
||||
arg.ShortDescription,
|
||||
arg.Urgency,
|
||||
arg.Impact,
|
||||
arg.State,
|
||||
arg.AssignmentGroup,
|
||||
arg.AssignedTo,
|
||||
arg.Category,
|
||||
arg.Subcategory,
|
||||
arg.IncidentNumber,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateIncidentNumber = `-- name: UpdateIncidentNumber :exec
|
||||
UPDATE incidents
|
||||
SET incident_number = ?1
|
||||
|
Reference in New Issue
Block a user