idk random shit

This commit is contained in:
2024-04-16 23:45:34 +02:00
parent cac8554b0b
commit db00bfb79a
4 changed files with 14 additions and 8 deletions

View File

@ -1,8 +1,5 @@
body { body {
font-size: 16px; font-size: 16px;
}
* {
font-family: sans-serif; font-family: sans-serif;
} }

BIN
timer.db

Binary file not shown.

View File

@ -438,7 +438,16 @@ func (server *MyServer) handleDeleteTimer(w http.ResponseWriter, r *http.Request
} }
} }
func (server *MyServer) handlePutTimer(w http.ResponseWriter, r *http.Request) { func parseNumber(s string) (int64, error) {
s = strings.TrimSpace(s)
if len(s) == 0 {
s = "0"
}
return strconv.ParseInt(s, 10, 64)
}
func (server *MyServer) handleCreateTimer(w http.ResponseWriter, r *http.Request) {
timerName := strings.TrimSpace(r.FormValue("timerName")) timerName := strings.TrimSpace(r.FormValue("timerName"))
user := server.findCurrentUser(w, r) user := server.findCurrentUser(w, r)
@ -448,14 +457,14 @@ func (server *MyServer) handlePutTimer(w http.ResponseWriter, r *http.Request) {
return return
} }
days, err := strconv.ParseInt(strings.TrimSpace(r.FormValue("days")), 10, 32) days, err := parseNumber(r.FormValue("days"))
if err != nil { if err != nil {
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
view.TimerCreateForm(timerName, "Error parsing days").Render(context.Background(), w) view.TimerCreateForm(timerName, "Error parsing days").Render(context.Background(), w)
return return
} }
hours, err := strconv.ParseInt(strings.TrimSpace(r.FormValue("hours")), 10, 32) hours, err := parseNumber(r.FormValue("hours"))
if err != nil { if err != nil {
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
view.TimerCreateForm(timerName, "Error parsing hours").Render(context.Background(), w) view.TimerCreateForm(timerName, "Error parsing hours").Render(context.Background(), w)
@ -563,7 +572,7 @@ func main() {
http.HandleFunc("DELETE /timer/{timerId}", myServer.handleDeleteTimer) http.HandleFunc("DELETE /timer/{timerId}", myServer.handleDeleteTimer)
http.HandleFunc("POST /timer/{timerId}/resetToken", myServer.handleResetTimerToken) http.HandleFunc("POST /timer/{timerId}/resetToken", myServer.handleResetTimerToken)
http.HandleFunc("GET /timer/{timerId}/token", myServer.handleGetTimerToken) http.HandleFunc("GET /timer/{timerId}/token", myServer.handleGetTimerToken)
http.HandleFunc("PUT /timer", myServer.handlePutTimer) http.HandleFunc("PUT /timer", myServer.handleCreateTimer)
http.HandleFunc("GET /", myServer.handleMain) http.HandleFunc("GET /", myServer.handleMain)
log.Println("Started!") log.Println("Started!")

View File

@ -38,7 +38,6 @@ templ timeButton(id model.UUID, value int, unit string) {
templ TimerInfo(timer model.Timer) { templ TimerInfo(timer model.Timer) {
<h1>Timer "{ timer.Name }"</h1> <h1>Timer "{ timer.Name }"</h1>
<p><a href="/">Back to list</a></p>
<p>Start time: <local-date>{ timer.StartTime.AsUTCString() }</local-date></p> <p>Start time: <local-date>{ timer.StartTime.AsUTCString() }</local-date></p>
<p>End time: <local-date>{ timer.EndTime.AsUTCString() }</local-date></p> <p>End time: <local-date>{ timer.EndTime.AsUTCString() }</local-date></p>
<p> <p>
@ -57,6 +56,7 @@ templ TimerInfo(timer model.Timer) {
} }
templ TimerView(timer model.Timer) { templ TimerView(timer model.Timer) {
<p><a href="/">Back to list</a></p>
<div class="timer-info"> <div class="timer-info">
@TimerInfo(timer) @TimerInfo(timer)
</div> </div>