diff --git a/backend/lite.go b/backend/lite.go
new file mode 100644
index 0000000..050c542
--- /dev/null
+++ b/backend/lite.go
@@ -0,0 +1,107 @@
+package main
+
+import (
+ "errors"
+ "github.com/gin-gonic/gin"
+ "net/http"
+ "strconv"
+)
+
+type ViewModel struct {
+ Users []User
+ CurrentUser int
+ Allowances []Allowance
+ Tasks []Task
+ History []History
+}
+
+func renderLite(c *gin.Context) {
+ if c.Query("user") != "" {
+ c.SetCookie("user", c.Query("user"), 3600, "/", "localhost", false, true)
+ c.Redirect(http.StatusFound, "/")
+ return
+ }
+
+ currentUserStr, err := c.Cookie("user")
+ if errors.Is(err, http.ErrNoCookie) {
+ renderNoUser(c)
+ return
+ }
+
+ if err != nil {
+ unsetUserCookie(c)
+ return
+ }
+ currentUser, err := strconv.Atoi(currentUserStr)
+ if err != nil {
+ unsetUserCookie(c)
+ return
+ }
+ userExists, err := db.UserExists(currentUser)
+ if !userExists || err != nil {
+ unsetUserCookie(c)
+ return
+ }
+ renderWithUser(c, currentUser)
+}
+
+func unsetUserCookie(c *gin.Context) {
+ c.SetCookie("user", "", -1, "/", "localhost", false, true)
+ c.Redirect(http.StatusFound, "/")
+}
+
+func renderNoUser(c *gin.Context) {
+ users, err := db.GetUsers()
+ if err != nil {
+ c.HTML(http.StatusInternalServerError, "error.gohtml", gin.H{
+ "error": err.Error(),
+ })
+ return
+ }
+
+ c.HTML(http.StatusOK, "lite.gohtml", ViewModel{
+ Users: users,
+ })
+}
+
+func renderWithUser(c *gin.Context, currentUser int) {
+ users, err := db.GetUsers()
+ if err != nil {
+ c.HTML(http.StatusInternalServerError, "error.gohtml", gin.H{
+ "error": err.Error(),
+ })
+ return
+ }
+
+ allowances, err := db.GetUserAllowances(currentUser)
+ if err != nil {
+ c.HTML(http.StatusInternalServerError, "error.gohtml", gin.H{
+ "error": err.Error(),
+ })
+ return
+ }
+
+ tasks, err := db.GetTasks()
+ if err != nil {
+ c.HTML(http.StatusInternalServerError, "error.gohtml", gin.H{
+ "error": err.Error(),
+ })
+ return
+ }
+
+ history, err := db.GetHistory(currentUser)
+ if err != nil {
+ c.HTML(http.StatusInternalServerError, "error.gohtml", gin.H{
+ "error": err.Error(),
+ })
+ return
+ }
+
+ c.HTML(http.StatusOK, "lite.gohtml", ViewModel{
+ Users: users,
+ CurrentUser: currentUser,
+ Allowances: allowances,
+ Tasks: tasks,
+ History: history,
+ })
+}
diff --git a/backend/lite.gohtml b/backend/lite.gohtml
index 9bb9e0d..9d764b6 100644
--- a/backend/lite.gohtml
+++ b/backend/lite.gohtml
@@ -1,3 +1,4 @@
+{{- /*gotype: allowance_planner.ViewModel*/}}
Allowance Planner 2000
@@ -5,5 +6,83 @@
Allowance Planner 2000
Users
+{{range .Users}}
+ {{if eq $.CurrentUser .ID}}
+ {{.Name}}
+ {{else}}
+ {{.Name}}
+ {{end}}
+{{end}}
+
+{{if ne .CurrentUser 0}}
+ Allowances
+
+
+
+ Name |
+ Progress |
+ Target |
+ Weight |
+
+
+
+ {{range .Allowances}}
+ {{if eq .ID 0}}
+
+ Total |
+ {{.Progress}} |
+ |
+ {{.Weight}} |
+
+ {{else}}
+
+ {{.Name}} |
+ {{.Progress}} |
+ {{.Target}} |
+ {{.Weight}} |
+
+ {{end}}
+ {{end}}
+
+
+
+ Tasks
+
+
+
+ Name |
+ Assigned |
+ Reward |
+
+
+
+ {{range .Tasks}}
+
+ {{.Name}} |
+ {{.Assigned}} |
+ {{.Reward}} |
+
+ {{end}}
+
+
+
+ History
+
+
+
+ Timestamp |
+ Allowance |
+
+
+
+ {{range .History}}
+
+ {{.Timestamp}} |
+ {{.Allowance}} |
+
+ {{end}}
+
+
+{{end}}
diff --git a/backend/main.go b/backend/main.go
index f496614..0e84a94 100644
--- a/backend/main.go
+++ b/backend/main.go
@@ -578,10 +578,6 @@ func getHistory(c *gin.Context) {
c.IndentedJSON(http.StatusOK, history)
}
-func renderLite(c *gin.Context) {
- c.HTML(http.StatusOK, "lite.gohtml", nil)
-}
-
/*
Initialises the database, and then starts the server.
If the context gets cancelled, the server is shutdown and the database is closed.