respond correctly to incident update
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:
@@ -19,6 +19,22 @@ import (
|
|||||||
|
|
||||||
// NewSnow receives data from the DMSP Snow New() function
|
// NewSnow receives data from the DMSP Snow New() function
|
||||||
func (h *Handler) NewSnow(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) NewSnow(w http.ResponseWriter, r *http.Request) {
|
||||||
|
h.Logger.Debug("NewSnow Request received", "method", r.Method, "url", r.URL, "path", r.URL.Path, "query", r.URL.Query(), "proto", r.Proto)
|
||||||
|
|
||||||
|
// Print headers
|
||||||
|
for name, values := range r.Header {
|
||||||
|
for _, value := range values {
|
||||||
|
h.Logger.Debug("Header ", "name", name, "value", value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// print query
|
||||||
|
for key, values := range r.URL.Query() {
|
||||||
|
for _, value := range values {
|
||||||
|
h.Logger.Debug("Query Paramater", "key", key, "value", value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var hostname string
|
var hostname string
|
||||||
|
|
||||||
reqBody, err := io.ReadAll(r.Body)
|
reqBody, err := io.ReadAll(r.Body)
|
||||||
@@ -180,7 +196,7 @@ func (h *Handler) NewSnow(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
} else if len(incoming.IncidentNumber) > 0 {
|
} else if len(incoming.IncidentNumber) > 0 {
|
||||||
// Incident already exists because we know the incident number, so update status or worknotes
|
// Incident already exists because we know the incident number, so update status or worknotes
|
||||||
h.Logger.Debug("updating incident database record")
|
h.Logger.Debug("updating incident database record", "number", incoming.IncidentNumber)
|
||||||
|
|
||||||
inc, err := h.Database.Queries().GetIncident(ctx, nullStr(incoming.IncidentNumber))
|
inc, err := h.Database.Queries().GetIncident(ctx, nullStr(incoming.IncidentNumber))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -204,9 +220,9 @@ func (h *Handler) NewSnow(w http.ResponseWriter, r *http.Request) {
|
|||||||
h.Logger.Debug("updated incident database record", "number", incoming.IncidentNumber)
|
h.Logger.Debug("updated incident database record", "number", incoming.IncidentNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO - add any worknotes specified
|
// add any worknotes specified
|
||||||
if len(incoming.WorkNotes) > 0 {
|
if len(incoming.WorkNotes) > 0 {
|
||||||
h.Logger.Debug("TODO add worknotes")
|
//h.Logger.Debug("TODO add worknotes")
|
||||||
|
|
||||||
// Create the worknotes entry
|
// Create the worknotes entry
|
||||||
wnParms := queries.CreateWorkNoteParams{
|
wnParms := queries.CreateWorkNoteParams{
|
||||||
@@ -224,6 +240,24 @@ func (h *Handler) NewSnow(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Respond saying we have updated the record
|
||||||
|
|
||||||
|
response := models.IncidentResponse{
|
||||||
|
StagingTable: "x_dusa2_itom_inc_imp",
|
||||||
|
Result: []models.IncidentResultItem{
|
||||||
|
{
|
||||||
|
DisplayValue: incoming.IncidentNumber,
|
||||||
|
Status: "updated",
|
||||||
|
SysID: inc.SysID.String,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
json.NewEncoder(w).Encode(response)
|
||||||
|
return
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Unexpected condition
|
// Unexpected condition
|
||||||
// TODO - return error
|
// TODO - return error
|
||||||
@@ -237,9 +271,11 @@ func (h *Handler) NewSnow(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
fmt.Fprintf(w, "{\"result\": [{}]}")
|
fmt.Fprintf(w, "{\"result\": [{}]}")
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
func nullStr(s string) sql.NullString {
|
func nullStr(s string) sql.NullString {
|
||||||
|
Reference in New Issue
Block a user