Templates verbessert
This commit is contained in:
parent
56b4a3ab34
commit
e9e0cbf382
11 changed files with 53 additions and 42 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue