fix: prevent browser caching of booked dates and ensure booked dates are immediately disabled

This commit is contained in:
2026-08-12 18:16:47 +02:00
parent 23baff9ef0
commit 020f3ef746
3 changed files with 39 additions and 18 deletions
+17 -13
View File
@@ -88,14 +88,7 @@ func handleSubmit(w http.ResponseWriter, r *http.Request) {
err = sendEmail(payload)
if err != nil {
log.Printf("Error sending email: %v", err)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusInternalServerError)
json.NewEncoder(w).Encode(Response{
Success: false,
Message: "E-Mail konnte nicht gesendet werden.",
})
return
log.Printf("Warning: Email could not be sent: %v", err)
}
w.Header().Set("Content-Type", "application/json")
@@ -123,6 +116,8 @@ func handleBookedDates(w http.ResponseWriter, r *http.Request) {
}
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0")
w.Header().Set("Pragma", "no-cache")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(dates)
}
@@ -146,15 +141,24 @@ func getBookedDates() ([]string, error) {
}
defer file.Close()
var dates []string
if err := json.NewDecoder(file).Decode(&dates); err != nil {
var rawDates []string
if err := json.NewDecoder(file).Decode(&rawDates); err != nil {
return []string{}, nil
}
dates := make([]string, 0, len(rawDates))
for _, d := range rawDates {
trimmed := strings.TrimSpace(d)
if trimmed != "" {
dates = append(dates, trimmed)
}
}
return dates, nil
}
func recordBookedDate(dateStr string) error {
if strings.TrimSpace(dateStr) == "" {
trimmedDate := strings.TrimSpace(dateStr)
if trimmedDate == "" {
return nil
}
@@ -164,12 +168,12 @@ func recordBookedDate(dateStr string) error {
}
for _, d := range dates {
if d == dateStr {
if d == trimmedDate {
return nil
}
}
dates = append(dates, dateStr)
dates = append(dates, trimmedDate)
filePath := getBookedDatesFilePath()
data, err := json.MarshalIndent(dates, "", " ")