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:
@@ -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
|
||||
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
|
||||
r := models.SingleIncidentResponse{
|
||||
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,
|
||||
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,
|
||||
CommentsAndWorkNotes: strings.Join(wkn, "\n\n"),
|
||||
// TODO
|
||||
}
|
||||
// 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) {
|
||||
var b []byte
|
||||
var wkn []string
|
||||
incResult, 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)
|
||||
} 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
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
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: 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,
|
||||
CommentsAndWorkNotes: strings.Join(wkn, "\n\n"),
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user