Added start of balances

This commit is contained in:
2026-03-01 13:07:22 +01:00
parent 54a8292234
commit ddf06554f8
3 changed files with 21 additions and 3 deletions

12
handlers/balance.go Normal file
View File

@@ -0,0 +1,12 @@
package handlers
import "net/http"
func GetBalance(w http.ResponseWriter, r *http.Request) {
query := r.URL.Query()
userParam := query.Get("user")
if userParam == "" {
}
}

View File

@@ -45,18 +45,23 @@ func Expenses(w http.ResponseWriter, r *http.Request) {
share.ID = utils.GenerateUUID()
err := storage.AddShare(&share)
if err != nil {
println(err.Error())
http.Error(w, "Error adding expense", http.StatusBadRequest) // Should never happen
return
}
}
err := storage.AddExpense(&body.Expense)
if err != nil {
println(err.Error())
http.Error(w, "Error adding expense", http.StatusBadRequest)
return
}
w.WriteHeader(http.StatusCreated)
err = json.NewEncoder(w).Encode(map[string]interface{}{
"expense": body.Expense,
"shares": body.Shares,
})
if err != nil {
println(err.Error())
return
}
break
case http.MethodPut: // -> Update Expense
break

View File

@@ -60,6 +60,7 @@ func (server *Server) Run() {
// Login required
mux.Handle("/api/expenses", auth.AuthMiddleware(server.JWTSecret)(http.HandlerFunc(handlers.Expenses)))
mux.Handle("/api/balance", auth.AuthMiddleware(server.JWTSecret)(http.HandlerFunc(handlers.GetBalance)))
mux.Handle("/api/ping", auth.AuthMiddleware(server.JWTSecret)(http.HandlerFunc(handlers.TestHandler)))
// Admin-only