enhance implementation
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -11,16 +11,62 @@ import (
|
||||
)
|
||||
|
||||
const createIncident = `-- name: CreateIncident :one
|
||||
INSERT INTO incidents (external_id)
|
||||
VALUES (?)
|
||||
RETURNING id
|
||||
INSERT INTO incidents (
|
||||
"description", "short_description", "urgency", "impact", "state", "external_id", "assignment_group", "assigned_to", "category", "subcategory", "created_at", "sys_id"
|
||||
) VALUES(
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
||||
)
|
||||
RETURNING id, external_id, created_at, incident_number, description, short_description, urgency, impact, state, assignment_group, assigned_to, category, subcategory, sys_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
|
||||
type CreateIncidentParams struct {
|
||||
Description sql.NullString
|
||||
ShortDescription sql.NullString
|
||||
Urgency sql.NullInt64
|
||||
Impact sql.NullInt64
|
||||
State sql.NullInt64
|
||||
ExternalID string
|
||||
AssignmentGroup sql.NullString
|
||||
AssignedTo sql.NullString
|
||||
Category sql.NullString
|
||||
Subcategory sql.NullString
|
||||
CreatedAt sql.NullTime
|
||||
SysID sql.NullString
|
||||
}
|
||||
|
||||
func (q *Queries) CreateIncident(ctx context.Context, arg CreateIncidentParams) (Incident, error) {
|
||||
row := q.db.QueryRowContext(ctx, createIncident,
|
||||
arg.Description,
|
||||
arg.ShortDescription,
|
||||
arg.Urgency,
|
||||
arg.Impact,
|
||||
arg.State,
|
||||
arg.ExternalID,
|
||||
arg.AssignmentGroup,
|
||||
arg.AssignedTo,
|
||||
arg.Category,
|
||||
arg.Subcategory,
|
||||
arg.CreatedAt,
|
||||
arg.SysID,
|
||||
)
|
||||
var i Incident
|
||||
err := row.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,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createIncoming = `-- name: CreateIncoming :one
|
||||
@@ -84,6 +130,96 @@ func (q *Queries) CreateIncoming(ctx context.Context, arg CreateIncomingParams)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const createWorkNote = `-- name: CreateWorkNote :one
|
||||
INSERT into worknotes (
|
||||
"incident_number", "note"
|
||||
) VALUES(
|
||||
?, ?
|
||||
)
|
||||
RETURNING id, incident_number, note
|
||||
`
|
||||
|
||||
type CreateWorkNoteParams struct {
|
||||
IncidentNumber string
|
||||
Note sql.NullString
|
||||
}
|
||||
|
||||
func (q *Queries) CreateWorkNote(ctx context.Context, arg CreateWorkNoteParams) (Worknote, error) {
|
||||
row := q.db.QueryRowContext(ctx, createWorkNote, arg.IncidentNumber, arg.Note)
|
||||
var i Worknote
|
||||
err := row.Scan(&i.ID, &i.IncidentNumber, &i.Note)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getIncident = `-- name: GetIncident :one
|
||||
SELECT id, external_id, created_at, incident_number, description, short_description, urgency, impact, state, assignment_group, assigned_to, category, subcategory, sys_id from incidents
|
||||
WHERE incident_number = ?1
|
||||
`
|
||||
|
||||
func (q *Queries) GetIncident(ctx context.Context, incidentnumber sql.NullString) (Incident, error) {
|
||||
row := q.db.QueryRowContext(ctx, getIncident, incidentnumber)
|
||||
var i Incident
|
||||
err := row.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,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
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
|
||||
`
|
||||
|
||||
func (q *Queries) ListIncidents(ctx context.Context) ([]Incident, error) {
|
||||
rows, err := q.db.QueryContext(ctx, listIncidents)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []Incident
|
||||
for rows.Next() {
|
||||
var i Incident
|
||||
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,
|
||||
); 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 listIncoming = `-- name: ListIncoming :many
|
||||
SELECT id, incident_number, description, short_description, urgency, impact, state, external_id, work_notes, assignment_group, assigned_to, category, subcategory, created_at FROM "Incoming"
|
||||
ORDER BY "id"
|
||||
@@ -126,3 +262,35 @@ func (q *Queries) ListIncoming(ctx context.Context) ([]Incoming, error) {
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const updateIncidentNumber = `-- name: UpdateIncidentNumber :exec
|
||||
UPDATE incidents
|
||||
SET incident_number = ?1
|
||||
WHERE external_id = ?2
|
||||
`
|
||||
|
||||
type UpdateIncidentNumberParams struct {
|
||||
IncidentNumber sql.NullString
|
||||
ExternalId string
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateIncidentNumber(ctx context.Context, arg UpdateIncidentNumberParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateIncidentNumber, arg.IncidentNumber, arg.ExternalId)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateIncidentState = `-- name: UpdateIncidentState :exec
|
||||
UPDATE incidents
|
||||
SET state = ?1
|
||||
WHERE incident_number = ?2
|
||||
`
|
||||
|
||||
type UpdateIncidentStateParams struct {
|
||||
State sql.NullInt64
|
||||
IncidentNumber sql.NullString
|
||||
}
|
||||
|
||||
func (q *Queries) UpdateIncidentState(ctx context.Context, arg UpdateIncidentStateParams) error {
|
||||
_, err := q.db.ExecContext(ctx, updateIncidentState, arg.State, arg.IncidentNumber)
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user