2022-09-05 18:10:35 +00:00
|
|
|
// deleteOfficeHourHandler
|
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2022-09-20 10:21:01 +00:00
|
|
|
"officeHours/models"
|
2022-09-05 18:10:35 +00:00
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (b *BaseHandler) DeleteOfficeHourHandler(w http.ResponseWriter, req *http.Request) {
|
|
|
|
if req.FormValue("id") != "" {
|
|
|
|
id, err := strconv.Atoi(req.FormValue("id"))
|
|
|
|
if err != nil {
|
|
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
|
|
}
|
|
|
|
officeHour, err := b.officeHourRepo.FindById(id)
|
|
|
|
if err != nil {
|
|
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
|
|
}
|
|
|
|
_, err = b.requestRepo.Add(officeHour, models.RequestDelete)
|
2022-09-13 05:28:13 +00:00
|
|
|
Templates.ExecuteTemplate(w, "deleteSuccess.html", struct{}{})
|
2022-09-05 18:10:35 +00:00
|
|
|
} else {
|
|
|
|
officeHours, _ := b.officeHourRepo.GetAll(true)
|
2022-09-19 12:46:16 +00:00
|
|
|
timetable, slots := b.GetTimetable(officeHours)
|
|
|
|
b.writeTimetablePage(w, req, b.printTimetable(timetable, slots, true))
|
2022-09-05 18:10:35 +00:00
|
|
|
}
|
|
|
|
}
|