rename to mocksnow
This commit is contained in:
@@ -4,9 +4,9 @@ import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"wnzl-snow/db"
|
||||
"wnzl-snow/internal/secrets"
|
||||
"wnzl-snow/internal/settings"
|
||||
"mocksnow/db"
|
||||
"mocksnow/internal/secrets"
|
||||
"mocksnow/internal/settings"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
)
|
||||
|
@@ -6,7 +6,7 @@ import (
|
||||
"net/http"
|
||||
"runtime"
|
||||
"time"
|
||||
"wnzl-snow/components/views"
|
||||
"mocksnow/components/views"
|
||||
)
|
||||
|
||||
// Home handles the home page.
|
||||
|
@@ -5,80 +5,16 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"wnzl-snow/components/views"
|
||||
"mocksnow/components/views"
|
||||
"mocksnow/db/queries"
|
||||
"mocksnow/internal/utils"
|
||||
)
|
||||
|
||||
func (h *Handler) RenderIncomingTable(w http.ResponseWriter, r *http.Request) {
|
||||
/*
|
||||
db, err := sql.Open("sqlite3", "./your.db")
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to connect to the database", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
query := `
|
||||
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 created_at DESC
|
||||
`
|
||||
|
||||
rows, err := db.Query(query)
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to query the database", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var results []views.IncomingRow
|
||||
for rows.Next() {
|
||||
var row views.IncomingRow
|
||||
err := rows.Scan(
|
||||
&row.ID,
|
||||
&row.IncidentNumber,
|
||||
&row.Description,
|
||||
&row.ShortDescription,
|
||||
&row.Urgency,
|
||||
&row.Impact,
|
||||
&row.State,
|
||||
&row.ExternalID,
|
||||
&row.WorkNotes,
|
||||
&row.AssignmentGroup,
|
||||
&row.AssignedTo,
|
||||
&row.Category,
|
||||
&row.Subcategory,
|
||||
&row.CreatedAt,
|
||||
)
|
||||
if err != nil {
|
||||
log.Printf("Scan error: %v", err)
|
||||
continue
|
||||
}
|
||||
results = append(results, row)
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
log.Printf("Row iteration error: %v", err)
|
||||
}
|
||||
*/
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
h.Logger.Debug("Querying updates table")
|
||||
results, err := h.Database.Queries().GetReportUpdates(ctx)
|
||||
results, err := h.Database.Queries().ListIncoming(ctx)
|
||||
if err != nil {
|
||||
h.Logger.Error("Unable to query incoming table", "error", err)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
@@ -101,5 +37,16 @@ func (h *Handler) RenderIncomingTable(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
views.IncomingTable(results).Render(r.Context(), w)
|
||||
views.IncomingTable(ConvertIncomingList(results)).Render(r.Context(), w)
|
||||
}
|
||||
|
||||
// Converts a slice of Incoming to []IncomingRow
|
||||
func ConvertIncomingList(list []queries.Incoming) []views.IncomingRow {
|
||||
rows := make([]views.IncomingRow, 0, len(list))
|
||||
for _, in := range list {
|
||||
var row views.IncomingRow
|
||||
utils.ConvertStruct(in, &row)
|
||||
rows = append(rows, row)
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
@@ -1,9 +1,11 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"mocksnow/server/models"
|
||||
)
|
||||
|
||||
// NewSnow receives data from the DMSP Snow New() function
|
||||
@@ -19,4 +21,15 @@ func (h *Handler) NewSnow(w http.ResponseWriter, r *http.Request) {
|
||||
} else {
|
||||
h.Logger.Debug("received input data", "length", len(reqBody))
|
||||
}
|
||||
|
||||
// Decode the JSON body
|
||||
var inc models.Incident
|
||||
if err := json.Unmarshal(reqBody, &inc); err != nil {
|
||||
h.Logger.Error("unable to decode json", "error", err)
|
||||
http.Error(w, "Invalid JSON body", http.StatusBadRequest)
|
||||
return
|
||||
} else {
|
||||
h.Logger.Debug("successfully decoded JSON")
|
||||
prettyPrint(inc)
|
||||
}
|
||||
}
|
||||
|
@@ -1,61 +0,0 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"wnzl-snow/internal/report"
|
||||
)
|
||||
|
||||
func (h *Handler) InventoryReportDownload(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// Generate the XLSX report
|
||||
reportData, err := report.CreateInventoryReport(h.Logger, h.Database, ctx)
|
||||
if err != nil {
|
||||
h.Logger.Error("Failed to create report", "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 create xlsx report: '%s'", err),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Set HTTP headers to indicate file download
|
||||
w.Header().Set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||
w.Header().Set("Content-Disposition", `attachment; filename="inventory_report.xlsx"`)
|
||||
w.Header().Set("File-Name", "inventory_report.xlsx")
|
||||
|
||||
// Write the XLSX file to the HTTP response
|
||||
w.Write(reportData)
|
||||
}
|
||||
|
||||
func (h *Handler) UpdateReportDownload(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// Generate the XLSX report
|
||||
reportData, err := report.CreateUpdatesReport(h.Logger, h.Database, ctx)
|
||||
if err != nil {
|
||||
h.Logger.Error("Failed to create report", "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 create xlsx report: '%s'", err),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Set HTTP headers to indicate file download
|
||||
w.Header().Set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
||||
w.Header().Set("Content-Disposition", `attachment; filename="updates_report.xlsx"`)
|
||||
w.Header().Set("File-Name", "updates_report.xlsx")
|
||||
|
||||
// Write the XLSX file to the HTTP response
|
||||
w.Write(reportData)
|
||||
}
|
@@ -1,42 +0,0 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// VmUpdate receives the CloudEvent for a VM modification or move
|
||||
func (h *Handler) UpdateCleanup(w http.ResponseWriter, r *http.Request) {
|
||||
/*
|
||||
// Get the current time
|
||||
now := time.Now()
|
||||
// Get the start of the current day (midnight today)
|
||||
midnightToday := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
|
||||
// Convert to Unix time
|
||||
unixTime := midnightToday.Unix()
|
||||
|
||||
// create the database parameters
|
||||
params := queries.CleanupUpdatesParams{
|
||||
UpdateType: "diskchange",
|
||||
UpdateTime: sql.NullInt64{Int64: unixTime, Valid: unixTime > 0},
|
||||
}
|
||||
|
||||
h.Logger.Debug("database params", "params", params)
|
||||
err := h.Database.Queries().CleanupUpdates(context.Background(), params)
|
||||
*/
|
||||
|
||||
//err := h.Database.Queries().InventoryCleanupTemplates(context.Background())
|
||||
err := h.Database.Queries().CleanupUpdatesNullVm(context.Background())
|
||||
|
||||
if err != nil {
|
||||
h.Logger.Error("Error received cleaning updates table", "error", err)
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
fmt.Fprintf(w, "Delete Request unsuccessful %s\n", err)
|
||||
} else {
|
||||
h.Logger.Debug("Processed update cleanup successfully")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
// TODO - return some JSON
|
||||
fmt.Fprintf(w, "Processed update cleanup successfully")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user