build uppon paramParser
This commit is contained in:
@@ -2,14 +2,15 @@ package endpoints
|
||||
|
||||
import (
|
||||
"arbeitszeitmessung/helper"
|
||||
"arbeitszeitmessung/helper/paramParser"
|
||||
"arbeitszeitmessung/models"
|
||||
"arbeitszeitmessung/templates"
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
@@ -67,26 +68,15 @@ func getBookings(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, "/user/login", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
pp := paramParser.New(r.URL.Query())
|
||||
|
||||
// TODO add config for timeoffset
|
||||
tsFrom, err := parseTimestamp(r, "time_from", time.Now().AddDate(0, -1, 0).Format(time.DateOnly))
|
||||
if err != nil {
|
||||
log.Println("Error parsing 'from' time", err)
|
||||
http.Error(w, "Timestamp 'from' cannot be parsed!", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
tsTo, err := parseTimestamp(r, "time_to", time.Now().Format(time.DateOnly))
|
||||
if err != nil {
|
||||
log.Println("Error parsing 'to' time", err)
|
||||
http.Error(w, "Timestamp 'to' cannot be parsed!", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
tsFrom := pp.ParseTimestampFallback("time_from", time.DateOnly, time.Now().AddDate(0, -1, 0))
|
||||
tsTo := pp.ParseTimestampFallback("time_to", time.DateOnly, time.Now())
|
||||
|
||||
tsTo = tsTo.AddDate(0, 0, 1) // so that today is inside
|
||||
|
||||
days := models.GetDays(user, tsFrom, tsTo, true)
|
||||
sort.Slice(days, func(i, j int) bool {
|
||||
return days[i].Date().After(days[j].Date())
|
||||
})
|
||||
|
||||
lastSub := user.GetLastWorkWeekSubmission()
|
||||
var aggregatedOvertime time.Duration
|
||||
@@ -116,6 +106,7 @@ func getBookings(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func updateBooking(w http.ResponseWriter, r *http.Request) {
|
||||
r.ParseForm()
|
||||
pp := paramParser.New(r.Form)
|
||||
var loc *time.Location
|
||||
loc, err := time.LoadLocation(helper.GetEnv("TZ", "Europe/Berlin"))
|
||||
if err != nil {
|
||||
@@ -136,10 +127,9 @@ func updateBooking(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
var check_in_out int
|
||||
check_in_out, err = strconv.Atoi(r.FormValue("check_in_out"))
|
||||
check_in_out, err := pp.ParseInt("check_in_out")
|
||||
if err != nil {
|
||||
log.Println("Error parsing check_in_out", err)
|
||||
slog.Warn("Error parsing check_in_out")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user