/time now also uses workDay instead of grouped booking --> outsourcing

to sql
This commit is contained in:
2025-03-28 13:05:26 +01:00
parent eb45a3ef75
commit 5a696788ed
10 changed files with 225 additions and 178 deletions

View File

@@ -8,6 +8,7 @@ import (
"encoding/json"
"log"
"net/http"
"sort"
"strconv"
"time"
)
@@ -69,20 +70,20 @@ func getBookings(w http.ResponseWriter, r *http.Request) {
}
tsTo = tsTo.AddDate(0, 0, 1) // so that today is inside
bookings, err := (*models.Booking).GetBookingsGrouped(nil, user.CardUID, tsFrom, tsTo)
if err != nil {
log.Println("Error getting bookings: ", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
workDays := (*models.WorkDay).GetWorkDays(nil, user.CardUID, tsFrom, tsTo)
sort.Slice(workDays, func(i, j int) bool {
return workDays[i].Day.After(workDays[j].Day)
})
if r.Header.Get("Accept") == "application/json" {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(bookings)
json.NewEncoder(w).Encode(workDays)
return
}
ctx := context.WithValue(r.Context(), "user", user)
templates.TimePage(bookings).Render(ctx, w)
templates.TimePage(workDays).Render(ctx, w)
}
func updateBooking(w http.ResponseWriter, r *http.Request) {