Sprechstunden löschen und Raumbeschränkungen beachten
This commit is contained in:
parent
2ce7a1fae1
commit
56b4a3ab34
7 changed files with 88 additions and 10 deletions
|
@ -69,7 +69,6 @@ func (r *OfficeHourRepo) FindByRoom(room models.Room, activeOnly bool) ([]models
|
|||
|
||||
func (r *OfficeHourRepo) FindById(id int) (models.OfficeHour, error) {
|
||||
return r.getFromRow(r.db.QueryRow("SELECT * FROM officeHour WHERE id=?", id))
|
||||
|
||||
}
|
||||
|
||||
func (r *OfficeHourRepo) Add(officeHour models.OfficeHour) (id int, err error) {
|
||||
|
@ -113,7 +112,8 @@ func (r *OfficeHourRepo) Add(officeHour models.OfficeHour) (id int, err error) {
|
|||
}
|
||||
|
||||
func (r *OfficeHourRepo) Delete(officeHour models.OfficeHour) error {
|
||||
return nil
|
||||
_, err := r.db.Exec("DELETE FROM officeHour WHERE id=?", officeHour.Id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *OfficeHourRepo) getFromRow(row *sql.Row) (models.OfficeHour, error) {
|
||||
|
@ -147,3 +147,40 @@ func (r *OfficeHourRepo) getFromRows(rows *sql.Rows) ([]models.OfficeHour, error
|
|||
}
|
||||
return officeHours, nil
|
||||
}
|
||||
|
||||
func (r *OfficeHourRepo) NumberByTimeSpanAndRoom(date models.Date, duration int, room models.Room, activeOnly bool) (int, error) {
|
||||
var rows *sql.Rows
|
||||
var err error
|
||||
if activeOnly {
|
||||
rows, err = r.db.Query("SELECT * FROM officeHour WHERE room=? AND day =? AND active", room.Id, date.Day)
|
||||
} else {
|
||||
rows, err = r.db.Query("SELECT * FROM officeHour WHERE room=?", room.Id)
|
||||
}
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer rows.Close()
|
||||
officeHours, err := r.getFromRows(rows)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
var count int
|
||||
for _, officeHour := range officeHours {
|
||||
if models.DateLess(models.GetEndDate(officeHour.Date, officeHour.Duration, false), date) || models.GetEndDate(officeHour.Date, officeHour.Duration, false) == date {
|
||||
continue
|
||||
}
|
||||
if models.DateLess(models.GetEndDate(date, duration, false), officeHour.Date) || models.GetEndDate(date, duration, false) == officeHour.Date {
|
||||
continue
|
||||
}
|
||||
count += 1
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (r *OfficeHourRepo) AllowedAt(date models.Date, duration int, room models.Room, activeOnly bool) (bool, error) {
|
||||
numberOfOfficeHours, err := r.NumberByTimeSpanAndRoom(date, duration, room, activeOnly)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return numberOfOfficeHours >= room.MaxOccupy, nil
|
||||
}
|
||||
|
|
|
@ -94,10 +94,10 @@ func (r *RequestRepo) Execute(request models.Request) error {
|
|||
switch request.Action {
|
||||
case models.RequestActivate:
|
||||
_, err = r.db.Exec("UPDATE officeHour SET active=true WHERE id=?", request.OfficeHour.Id)
|
||||
r.db.Exec("DELETE FROM request WHERE id=?", request.Id)
|
||||
r.db.Exec("DELETE FROM request WHERE officeHour=?", request.OfficeHour.Id)
|
||||
case models.RequestDelete:
|
||||
_, err = r.db.Exec("DELETE FROM officeHour WHERE id=?", request.OfficeHour.Id)
|
||||
r.db.Exec("DELETE FROM request WHERE id=?", request.Id)
|
||||
r.officeHourRepo.Delete(request.OfficeHour)
|
||||
r.db.Exec("DELETE FROM request WHERE officeHour=?", request.OfficeHour.Id)
|
||||
default:
|
||||
r.db.Exec("DELETE FROM request WHERE id=?", request.Id)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue