more code

This commit is contained in:
2025-03-22 21:28:09 +11:00
parent a4578fb293
commit 6b2b60b9ef
4 changed files with 41 additions and 4 deletions

View File

@@ -0,0 +1,25 @@
package handler
import (
"fmt"
"net/http"
"strings"
)
// GetIncident responds to the link generated in the response to a New Snow
func (h *Handler) GetIncident(w http.ResponseWriter, r *http.Request) {
// TODO
path := r.URL.Path
// Expected format: /api/now/table/incident/{id}
parts := strings.Split(path, "/")
if len(parts) != 6 || parts[1] != "api" || parts[2] != "now" || parts[3] != "table" || parts[4] != "incident" {
http.NotFound(w, r)
return
}
id := parts[5] // Extract {id}
fmt.Fprintf(w, "Incident ID: %s", id)
}

View File

@@ -9,12 +9,14 @@ import (
"mocksnow/db/queries"
"mocksnow/server/models"
"net/http"
"os"
"github.com/google/uuid"
)
// NewSnow receives data from the DMSP Snow New() function
func (h *Handler) NewSnow(w http.ResponseWriter, r *http.Request) {
var hostname string
reqBody, err := io.ReadAll(r.Body)
if err != nil {
@@ -82,7 +84,15 @@ func (h *Handler) NewSnow(w http.ResponseWriter, r *http.Request) {
// Simulate response
ticket := fmt.Sprintf("TKT%06d", incidentRecord)
sysID := uuid.New().String()
recordLink := "https://server.fqdn.com/api/now/table/incident/" + sysID
// Produce dummy record link
hostname, err = os.Hostname()
if err != nil {
h.Logger.Error("failed to lookup hostname", "error", err)
hostname = "localhost"
}
recordLink := fmt.Sprintf("https://%s/api/now/table/incident/%s", hostname, sysID)
response := models.IncidentResponse{
ImportSet: randomImportSet(),