diff --git a/controllers/addOfficeHourHandlers.go b/controllers/addOfficeHourHandler.go
similarity index 97%
rename from controllers/addOfficeHourHandlers.go
rename to controllers/addOfficeHourHandler.go
index 7c5b89e..e935368 100644
--- a/controllers/addOfficeHourHandlers.go
+++ b/controllers/addOfficeHourHandler.go
@@ -16,10 +16,7 @@ type maskData struct {
MinuteGranularity int
SelectedCourse int
SelectedRoom int
- Week int
- Day int
- Hour int
- Minute int
+ Date models.Date
Duration int
Roomname string
Name string
@@ -115,7 +112,6 @@ func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Requ
info := req.FormValue("info")
allowed, err := b.officeHourRepo.AllowedAt(date, duration, room, true)
- fmt.Println(allowed)
if err != nil {
errors = append(errors, fmt.Sprintf("Fehler beim Abfragen der Raumkapazität: %s", err.Error()))
} else if !allowed {
@@ -128,10 +124,7 @@ func (b *BaseHandler) AddOfficeHourHandler(w http.ResponseWriter, req *http.Requ
models.MinuteGranularity,
courseid,
roomid,
- week,
- day,
- hour,
- minute,
+ date,
duration,
roomname,
name,
diff --git a/controllers/confirmRequestHandler.go b/controllers/confirmRequestHandler.go
index d5ea2e6..dccd1e0 100644
--- a/controllers/confirmRequestHandler.go
+++ b/controllers/confirmRequestHandler.go
@@ -18,7 +18,14 @@ func (b *BaseHandler) ConfirmRequestHandler(w http.ResponseWriter, req *http.Req
err = b.requestRepo.Execute(request)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
- tmpl, err := template.ParseFiles("templates/executeFailure.html")
- tmpl.Execute(w, err)
+ tmpl, _ := template.ParseFiles("templates/executeFailure.html")
+ tmpl.Execute(w, err.Error())
+ return
}
+ tmpl, err := template.ParseFiles("templates/executeSuccess.html")
+ if err != nil {
+ w.WriteHeader(http.StatusInternalServerError)
+ }
+ tmpl.Execute(w, struct{}{})
+
}
diff --git a/controllers/timetable.go b/controllers/timetable.go
index 4fbef49..2574a2b 100644
--- a/controllers/timetable.go
+++ b/controllers/timetable.go
@@ -50,10 +50,7 @@ func GetTimetable(officeHours []models.OfficeHour) (timetable map[models.Date]ma
func printTimetable(timetable map[models.Date]map[int]models.OfficeHour, slots []int, deleteIcons bool) template.HTML {
var tableBody string
- tableCell, _ := template.New("td.html").
- Funcs(template.FuncMap{"mod": func(i int, j int) int { return i % j },
- "add": func(i int, j int) int { return i + j },
- "divide": func(i int, j int) int { return i / j }}).ParseFiles("templates/td.html")
+ tableCell, _ := template.New("td.html").Funcs(template.FuncMap{"divide": func(i int, j int) int { return i / j }}).ParseFiles("templates/td.html")
for hour := 8; hour < 19; hour += 1 {
for minute := 0; minute < 60; minute += models.MinuteGranularity {
tableBody += "
"
diff --git a/main.go b/main.go
index 89fb5cf..eb2f7b8 100644
--- a/main.go
+++ b/main.go
@@ -26,5 +26,4 @@ func main() {
http.HandleFunc("/", h.RootHandler)
http.ListenAndServe(":8080", nil)
-
}
diff --git a/models/officeHour.go b/models/officeHour.go
index 3527513..89f0b98 100644
--- a/models/officeHour.go
+++ b/models/officeHour.go
@@ -21,3 +21,7 @@ type OfficeHourRepository interface {
Add(officeHour OfficeHour) (int, error)
AllowedAt(date Date, duration int, room Room, activeOnly bool) (bool, error)
}
+
+func (officeHour OfficeHour) EndDate() Date {
+ return GetEndDate(officeHour.Date, officeHour.Duration, false)
+}
diff --git a/repositories/officeHour.go b/repositories/officeHour.go
index 1439f24..e4880e6 100644
--- a/repositories/officeHour.go
+++ b/repositories/officeHour.go
@@ -3,6 +3,7 @@ package repositories
import (
"database/sql"
+ "fmt"
"sprechstundentool/models"
)
@@ -31,7 +32,7 @@ func (r *OfficeHourRepo) GetAll(activeOnly bool) ([]models.OfficeHour, error) {
rows, err = r.db.Query("SELECT * FROM officeHour")
}
if err != nil {
- return nil, err
+ return nil, fmt.Errorf("Error getting all officeHours from database: %s", err.Error())
}
defer rows.Close()
return r.getFromRows(rows)
@@ -46,7 +47,7 @@ func (r *OfficeHourRepo) FindByCourse(course models.Course, activeOnly bool) ([]
rows, err = r.db.Query("SELECT * FROM officeHour WHERE course=?", course.Id)
}
if err != nil {
- return nil, err
+ return nil, fmt.Errorf("Error getting officeHours by course from database: %s", err.Error())
}
defer rows.Close()
return r.getFromRows(rows)
@@ -61,7 +62,7 @@ func (r *OfficeHourRepo) FindByRoom(room models.Room, activeOnly bool) ([]models
rows, err = r.db.Query("SELECT * FROM officeHour WHERE room=?", room.Id)
}
if err != nil {
- return nil, err
+ return nil, fmt.Errorf("Error getting officeHours by room from database: %s", err.Error())
}
defer rows.Close()
return r.getFromRows(rows)
@@ -92,7 +93,7 @@ func (r *OfficeHourRepo) Add(officeHour models.OfficeHour) (id int, err error) {
officeHour.Info == oldOfficeHour.Info &&
officeHour.Active == oldOfficeHour.Active &&
officeHour.Duration == oldOfficeHour.Duration {
- return officeHour.Id, nil
+ return oldOfficeHour.Id, nil
}
}
@@ -113,7 +114,7 @@ func (r *OfficeHourRepo) Add(officeHour models.OfficeHour) (id int, err error) {
func (r *OfficeHourRepo) Delete(officeHour models.OfficeHour) error {
_, err := r.db.Exec("DELETE FROM officeHour WHERE id=?", officeHour.Id)
- return err
+ return fmt.Errorf("Error deleting officeHour from database: %s", err.Error())
}
func (r *OfficeHourRepo) getFromRow(row *sql.Row) (models.OfficeHour, error) {
@@ -122,7 +123,7 @@ func (r *OfficeHourRepo) getFromRow(row *sql.Row) (models.OfficeHour, error) {
var roomName, courseName string
err := row.Scan(&officeHour.Id, &tutorid, &day, &hour, &minute, &roomName, &courseName, &week, &officeHour.Info, &officeHour.Active, &officeHour.Duration)
if err != nil {
- return models.OfficeHour{}, err
+ return models.OfficeHour{}, fmt.Errorf("Error getting single officeHours row from database: %s", err.Error())
}
officeHour.Date = models.Date{week, day, hour, minute}
officeHour.Room, _ = r.roomRepo.FindByName(roomName)
@@ -137,7 +138,7 @@ func (r *OfficeHourRepo) getFromRows(rows *sql.Rows) ([]models.OfficeHour, error
var officeHour models.OfficeHour
var week, day, hour, minute, tutorId, roomId, courseId int
if err := rows.Scan(&officeHour.Id, &tutorId, &day, &hour, &minute, &roomId, &courseId, &week, &officeHour.Info, &officeHour.Active, &officeHour.Duration); err != nil {
- return officeHours, err
+ return officeHours, fmt.Errorf("Error getting multiple officeHour rows from database: %s", err.Error())
}
officeHour.Date = models.Date{week, day, hour, minute}
officeHour.Room, _ = r.roomRepo.FindById(roomId)
@@ -157,7 +158,7 @@ func (r *OfficeHourRepo) NumberByTimeSpanAndRoom(date models.Date, duration int,
rows, err = r.db.Query("SELECT * FROM officeHour WHERE room=?", room.Id)
}
if err != nil {
- return 0, err
+ return 0, fmt.Errorf("Error getting officeHours by timespan and room from database: %s", err.Error())
}
defer rows.Close()
officeHours, err := r.getFromRows(rows)
@@ -182,5 +183,5 @@ func (r *OfficeHourRepo) AllowedAt(date models.Date, duration int, room models.R
if err != nil {
return false, err
}
- return numberOfOfficeHours >= room.MaxOccupy, nil
+ return numberOfOfficeHours < room.MaxOccupy, nil
}
diff --git a/repositories/request.go b/repositories/request.go
index 9f9cd5d..0dca65f 100644
--- a/repositories/request.go
+++ b/repositories/request.go
@@ -81,7 +81,6 @@ func (r *RequestRepo) Add(officeHour models.OfficeHour, action int) (int, error)
if err != nil {
return 0, err
}
-
request, err = r.FindBySecret(secret)
if err != nil {
return request.Id, err
diff --git a/templates/addMask.html b/templates/addMask.html
index bfa3e9a..700899d 100644
--- a/templates/addMask.html
+++ b/templates/addMask.html
@@ -14,27 +14,27 @@
:
:
- :
- :
+ :
+ :
:
:
- :
+ :
:
-
+
:
diff --git a/templates/confirmationMail b/templates/confirmationMail
index 660d629..7344b5a 100644
--- a/templates/confirmationMail
+++ b/templates/confirmationMail
@@ -7,11 +7,10 @@ mit deiner Emailadresse soll eine Sprechstunde mit folgenden Daten {{if eq .Acti
{{.OfficeHour.Course.Name}}
{{DayName .OfficeHour.Date.Day}}
-ab {{.OfficeHour.Date.Hour}}:{{printf "%02d" .OfficeHour.Date.Minute}} Uhr
-{{.OfficeHour.Duration}} Minuten
+{{printf "%02d".OfficeHour.Date.Hour}}:{{printf "%02d" .OfficeHour.Date.Minute}} Uhr bis {{printf "%02d" .OfficeHour.EndDate.Hour}}:{{printf "%02d" .OfficeHour.EndDate.Minute}} Uhr
{{.OfficeHour.Tutor.Name}}
-Wenn dies richtig ist, so bestätige die Sprechstunde durch Abrufen der folgenden URL:
+Falls dies richtig ist, so bestätige die Sprechstunde durch Abrufen der folgenden URL:
https://sprechstunden.mathebau.de/confirmRequest?code={{.Secret}}
Solltest du diese Email nicht erwartet haben, so kannst du sie einfach ignorieren.
diff --git a/templates/executeSuccess.html b/templates/executeSuccess.html
new file mode 100644
index 0000000..86b2f2f
--- /dev/null
+++ b/templates/executeSuccess.html
@@ -0,0 +1,12 @@
+
+
+ Anfrage ausgeführt
+
+
+ Deine Anfrage wurde ausgeführt.
+
+
+
\ No newline at end of file
diff --git a/templates/td.html b/templates/td.html
index ad24b5e..d4b17f4 100644
--- a/templates/td.html
+++ b/templates/td.html
@@ -1,6 +1,6 @@
{{if .DeleteIcons}}{{end}}
- {{printf "%02d" .OfficeHour.Date.Hour}}:{{printf "%02d" .OfficeHour.Date.Minute}} - {{printf "%02d" (add .OfficeHour.Date.Hour (divide .OfficeHour.Duration 60))}}:{{printf "%02d" (mod (add .OfficeHour.Date.Minute .OfficeHour.Duration) 60)}}
+ {{printf "%02d" .OfficeHour.Date.Hour}}:{{printf "%02d" .OfficeHour.Date.Minute}} - {{printf "%02d" .OfficeHour.EndDate.Hour}}:{{printf "%02d" .OfficeHour.EndDate.Minute}}
{{.OfficeHour.Course.Name}}
{{.OfficeHour.Tutor.Name}}
{{.OfficeHour.Room.Name}}
|