add CommentsAndWorkNotes
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:
@@ -66,4 +66,11 @@ INSERT into worknotes (
|
|||||||
) VALUES(
|
) VALUES(
|
||||||
?, ?, CURRENT_TIMESTAMP
|
?, ?, CURRENT_TIMESTAMP
|
||||||
)
|
)
|
||||||
RETURNING *;
|
RETURNING *;
|
||||||
|
|
||||||
|
-- name: GetIncidentWorkNotes :many
|
||||||
|
SELECT * from worknotes
|
||||||
|
WHERE incident_number = sqlc.arg('incidentNumber');
|
||||||
|
|
||||||
|
-- name: ListWorkNotes :many
|
||||||
|
SELECT * from worknotes;
|
@@ -246,6 +246,39 @@ func (q *Queries) GetIncidentReport(ctx context.Context) ([]GetIncidentReportRow
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getIncidentWorkNotes = `-- name: GetIncidentWorkNotes :many
|
||||||
|
SELECT id, incident_number, note, created_at from worknotes
|
||||||
|
WHERE incident_number = ?1
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) GetIncidentWorkNotes(ctx context.Context, incidentnumber string) ([]Worknote, error) {
|
||||||
|
rows, err := q.db.QueryContext(ctx, getIncidentWorkNotes, incidentnumber)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []Worknote
|
||||||
|
for rows.Next() {
|
||||||
|
var i Worknote
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.IncidentNumber,
|
||||||
|
&i.Note,
|
||||||
|
&i.CreatedAt,
|
||||||
|
); 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
|
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 FROM incidents
|
||||||
`
|
`
|
||||||
@@ -331,6 +364,38 @@ func (q *Queries) ListIncoming(ctx context.Context) ([]Incoming, error) {
|
|||||||
return items, nil
|
return items, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const listWorkNotes = `-- name: ListWorkNotes :many
|
||||||
|
SELECT id, incident_number, note, created_at from worknotes
|
||||||
|
`
|
||||||
|
|
||||||
|
func (q *Queries) ListWorkNotes(ctx context.Context) ([]Worknote, error) {
|
||||||
|
rows, err := q.db.QueryContext(ctx, listWorkNotes)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
var items []Worknote
|
||||||
|
for rows.Next() {
|
||||||
|
var i Worknote
|
||||||
|
if err := rows.Scan(
|
||||||
|
&i.ID,
|
||||||
|
&i.IncidentNumber,
|
||||||
|
&i.Note,
|
||||||
|
&i.CreatedAt,
|
||||||
|
); 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 updateIncident = `-- name: UpdateIncident :exec
|
const updateIncident = `-- name: UpdateIncident :exec
|
||||||
UPDATE incidents
|
UPDATE incidents
|
||||||
SET
|
SET
|
||||||
|
@@ -87,20 +87,45 @@ func (h *Handler) GetIncident(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wknList, err := h.Database.Queries().ListWorkNotes(ctx)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, sql.ErrNoRows) {
|
||||||
|
h.Logger.Debug("No incident worknotes found")
|
||||||
|
} else {
|
||||||
|
h.Logger.Error("", "error", err)
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
json.NewEncoder(w).Encode(map[string]string{
|
||||||
|
"status": "ERROR",
|
||||||
|
"message": fmt.Sprintf("Unable to query database for incident worknotes: '%s'", err),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// convert incList into json output
|
// convert incList into json output
|
||||||
for _, inc := range incList {
|
for _, inc := range incList {
|
||||||
|
var wkn []string
|
||||||
|
// get worknotes for this incident
|
||||||
|
for _, note := range wknList {
|
||||||
|
if note.IncidentNumber == inc.IncidentNumber.String {
|
||||||
|
wkn = append(wkn, note.Note.String)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// transform inc to SingleIncidentResponse
|
// transform inc to SingleIncidentResponse
|
||||||
r := models.SingleIncidentResponse{
|
r := models.SingleIncidentResponse{
|
||||||
Number: inc.IncidentNumber.String,
|
Number: inc.IncidentNumber.String,
|
||||||
SysID: inc.SysID.String,
|
SysID: inc.SysID.String,
|
||||||
IncidentState: strconv.FormatInt(inc.State.Int64, 10),
|
IncidentState: strconv.FormatInt(inc.State.Int64, 10),
|
||||||
State: strconv.FormatInt(inc.State.Int64, 10),
|
State: strconv.FormatInt(inc.State.Int64, 10),
|
||||||
Impact: strconv.FormatInt(inc.Impact.Int64, 10),
|
Impact: strconv.FormatInt(inc.Impact.Int64, 10),
|
||||||
Urgency: strconv.FormatInt(inc.Urgency.Int64, 10),
|
Urgency: strconv.FormatInt(inc.Urgency.Int64, 10),
|
||||||
ShortDescription: inc.ShortDescription.String,
|
ShortDescription: inc.ShortDescription.String,
|
||||||
AssignedTo: inc.AssignedTo.String,
|
AssignedTo: inc.AssignedTo.String,
|
||||||
Category: inc.Category.String,
|
Category: inc.Category.String,
|
||||||
Subcategory: inc.SubCategory.String,
|
Subcategory: inc.SubCategory.String,
|
||||||
|
CommentsAndWorkNotes: strings.Join(wkn, "\n\n"),
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
// add to responseList
|
// add to responseList
|
||||||
@@ -167,28 +192,44 @@ 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
|
||||||
incResult, err := h.Database.Queries().GetIncident(ctx, nullStr(number))
|
incResult, 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)
|
||||||
} else {
|
} else {
|
||||||
h.Logger.Error("Unable to query database for incident number", "error", err)
|
h.Logger.Error("Unable to query database for incident number", "number", number, "error", err)
|
||||||
return b, err
|
return b, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wknotes, err := h.Database.Queries().GetIncidentWorkNotes(ctx, number)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, sql.ErrNoRows) {
|
||||||
|
h.Logger.Debug("No incident worknotes found", "number", number)
|
||||||
|
} else {
|
||||||
|
h.Logger.Error("Unable to query database for incident worknotes", "number", number, "error", err)
|
||||||
|
return b, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, note := range wknotes {
|
||||||
|
wkn = append(wkn, note.Note.String)
|
||||||
|
}
|
||||||
|
|
||||||
// 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: incResult.IncidentNumber.String,
|
||||||
SysID: incResult.SysID.String,
|
SysID: incResult.SysID.String,
|
||||||
IncidentState: strconv.FormatInt(incResult.State.Int64, 10),
|
IncidentState: strconv.FormatInt(incResult.State.Int64, 10),
|
||||||
State: strconv.FormatInt(incResult.State.Int64, 10),
|
State: strconv.FormatInt(incResult.State.Int64, 10),
|
||||||
Impact: strconv.FormatInt(incResult.Impact.Int64, 10),
|
Impact: strconv.FormatInt(incResult.Impact.Int64, 10),
|
||||||
Urgency: strconv.FormatInt(incResult.Urgency.Int64, 10),
|
Urgency: strconv.FormatInt(incResult.Urgency.Int64, 10),
|
||||||
ShortDescription: incResult.ShortDescription.String,
|
ShortDescription: incResult.ShortDescription.String,
|
||||||
AssignedTo: incResult.AssignedTo.String,
|
AssignedTo: incResult.AssignedTo.String,
|
||||||
Category: incResult.Category.String,
|
Category: incResult.Category.String,
|
||||||
Subcategory: incResult.SubCategory.String,
|
Subcategory: incResult.SubCategory.String,
|
||||||
|
CommentsAndWorkNotes: strings.Join(wkn, "\n\n"),
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -18,17 +18,18 @@ type IncidentResultItem struct {
|
|||||||
|
|
||||||
// TODO - populate more fields here
|
// TODO - populate more fields here
|
||||||
type SingleIncidentResponse struct {
|
type SingleIncidentResponse struct {
|
||||||
Number string `json:"number"` // corresponds with incident_number
|
Number string `json:"number"` // corresponds with incident_number
|
||||||
SysID string `json:"sys_id,omitempty"`
|
SysID string `json:"sys_id,omitempty"`
|
||||||
IncidentState string `json:"incident_state"` // integer value, 1-6 (6 is resolved)
|
IncidentState string `json:"incident_state"` // integer value, 1-6 (6 is resolved)
|
||||||
State string `json:"state,omitempty"` // unsure how this differs from IncidentState
|
State string `json:"state,omitempty"` // unsure how this differs from IncidentState
|
||||||
ShortDescription string `json:"short_description"`
|
ShortDescription string `json:"short_description"`
|
||||||
AssignedTo interface{} `json:"assigned_to,omitempty"`
|
AssignedTo interface{} `json:"assigned_to,omitempty"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Urgency string `json:"urgency"`
|
Urgency string `json:"urgency"`
|
||||||
Impact string `json:"impact"`
|
Impact string `json:"impact"`
|
||||||
Category string `json:"category"`
|
Category string `json:"category"`
|
||||||
Subcategory string `json:"subcategory"`
|
Subcategory string `json:"subcategory"`
|
||||||
|
CommentsAndWorkNotes string `json:"comments_and_work_notes"`
|
||||||
// TODO - unvalidated from here on
|
// TODO - unvalidated from here on
|
||||||
|
|
||||||
// Associated DeviceID (UUID from CPDB)
|
// Associated DeviceID (UUID from CPDB)
|
||||||
|
Reference in New Issue
Block a user