27 lines
743 B
Go
27 lines
743 B
Go
// deleteOfficeHourHandler
|
|
package controllers
|
|
|
|
import (
|
|
"net/http"
|
|
"officeHours/models"
|
|
"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)
|
|
b.serveTemplate(w, "deleteSuccess", nil)
|
|
} else {
|
|
officeHours, _ := b.officeHourRepo.GetAll(true)
|
|
timetable, slots := b.GetTimetable(officeHours)
|
|
b.writeTimetablePage(w, req, b.printTimetable(timetable, slots, true))
|
|
}
|
|
}
|