diff --git a/backend/db.go b/backend/db.go
index 6a70b50..f207084 100644
--- a/backend/db.go
+++ b/backend/db.go
@@ -1,6 +1,7 @@
package main
import (
+ "encoding/json"
"fmt"
"log"
@@ -46,3 +47,22 @@ func (db *DB) Read(table string, key string, value interface{}) error {
}
return nil
}
+
+func (db *DB) loadHeats() []Heat {
+ records, err := db.Db.ReadAll("Heat")
+ if err != nil {
+ fmt.Printf("read error: %+v", err)
+ }
+
+ heats := make([]Heat, 0)
+ for _, record := range records {
+ var heat Heat
+ err = json.Unmarshal([]byte(record), &heat)
+ if err != nil {
+ fmt.Printf("decode error: %+v", err)
+ }
+ heats = append(heats, heat)
+ }
+
+ return heats
+}
diff --git a/backend/heats.go b/backend/heats.go
new file mode 100644
index 0000000..b62e39f
--- /dev/null
+++ b/backend/heats.go
@@ -0,0 +1,65 @@
+package main
+
+import (
+ "fmt"
+ "log"
+ "net/http"
+ "strings"
+
+ "github.com/gin-gonic/gin"
+)
+
+type Surfer struct {
+ Name string `json:"name"`
+ Color string `json:"color"`
+ Priority string `json:"priority"`
+ Score string `json:"score"`
+}
+
+type Heat struct {
+ Name string `json:"name"`
+ Category string `json:"category"`
+ Number int `json:"number"`
+ Timer int `json:"timer"`
+ Status string `json:"status"`
+ Surfers []Surfer `json:"surfers"`
+}
+
+func heatName(heat Heat) string {
+ str := fmt.Sprintf("%s.%d.%s", heat.Name, heat.Number, heat.Category)
+ strings.ReplaceAll(str, " ", "_")
+ return str
+}
+
+func (app *App) SaveHeat(c *gin.Context) {
+ var heat Heat
+
+ err := c.ShouldBind(&heat)
+
+ if err != nil {
+ log.Printf("req error: %+v", err)
+ c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
+ return
+ }
+
+ log.Printf("heat: %+v", heat)
+
+ heat.Status = "idle"
+
+ err = app.DB.Write("Heat", heatName(heat), heat)
+ if err != nil {
+ log.Printf("set error: %+v", err)
+ c.JSON(http.StatusInternalServerError, gin.H{"status": fmt.Sprintf("Error: %+v", err)})
+ return
+ }
+
+ c.JSON(http.StatusOK, gin.H{"status": "saved"})
+}
+
+func (app *App) LoadHeats(c *gin.Context) {
+ heats := app.DB.loadHeats()
+
+ c.JSON(http.StatusOK, heats)
+
+ log.Printf("heats: %+v", heats)
+}
diff --git a/backend/http.go b/backend/http.go
index eb9ffdc..a751878 100644
--- a/backend/http.go
+++ b/backend/http.go
@@ -86,6 +86,6 @@ func (app *App) RegisterApiRoutes() {
// api.GET("/stopheat", app.StopHeatTimer)
// api.POST("/saveheat", app.SaveHeat)
// api.POST("/deleteheat", app.DeleteHeat)
- // api.GET("/loadheats", app.LoadHeats)
+ api.GET("/loadheats", app.LoadHeats)
// api.GET("/runningheat", app.LoadRunning)
}
diff --git a/frontend/src/routes/priority/+page.svelte b/frontend/src/routes/priority/+page.svelte
new file mode 100644
index 0000000..244fbe9
--- /dev/null
+++ b/frontend/src/routes/priority/+page.svelte
@@ -0,0 +1,399 @@
+
+
+