new folder strucure and file path

This commit is contained in:
Adrian Zürcher
2026-01-21 07:28:10 +01:00
parent 84abf6b820
commit 9150550609

View File

@@ -4,20 +4,36 @@ import (
"encoding/json"
"net/http"
"os"
"slideshowApp/utils"
)
type Schedule map[string]interface{}
var scheduleFile = "./data/schedule.json"
type Schedule map[string]any
func SaveSchedule(w http.ResponseWriter, r *http.Request) {
var s Schedule
json.NewDecoder(r.Body).Decode(&s)
data, _ := json.Marshal(s)
os.WriteFile("schedule.json", data, 0644)
if err := json.NewDecoder(r.Body).Decode(&s); err != nil {
utils.SendJSONError(w, "Invalid input", http.StatusBadRequest)
return
}
data, err := json.MarshalIndent(s, "", " ")
if err != nil {
utils.SendJSONError(w, "Encoding failed", http.StatusInternalServerError)
return
}
err = os.WriteFile(scheduleFile, data, 0644)
if err != nil {
utils.SendJSONError(w, "write file failed", http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
}
func GetSchedule(w http.ResponseWriter, r *http.Request) {
data, err := os.ReadFile("schedule.json")
data, err := os.ReadFile(scheduleFile)
if err != nil {
json.NewEncoder(w).Encode(Schedule{})
return