Sprechstunden hinzufügen und durch einen E-Mail-Link bestätigen lassen
This commit is contained in:
parent
369f4ebcec
commit
78af58a51d
18 changed files with 291 additions and 29 deletions
|
@ -72,19 +72,18 @@ func (r *OfficeHourRepo) FindById(id int) (models.OfficeHour, error) {
|
|||
|
||||
}
|
||||
|
||||
func (r *OfficeHourRepo) Add(officeHour models.OfficeHour) error {
|
||||
func (r *OfficeHourRepo) Add(officeHour models.OfficeHour) (id int, err error) {
|
||||
// Find correct tutor or add if not existent
|
||||
r.tutorRepo.Add(officeHour.Tutor)
|
||||
var err error
|
||||
officeHour.Tutor, err = r.tutorRepo.FindByNameAndEmail(officeHour.Tutor.Name, officeHour.Tutor.Email)
|
||||
if err != nil {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
|
||||
//Don't add identical officeHours
|
||||
officeHours, err := r.FindByCourse(officeHour.Course, false)
|
||||
if err != nil {
|
||||
return err
|
||||
return 0, err
|
||||
}
|
||||
for _, oldOfficeHour := range officeHours {
|
||||
if officeHour.Tutor == oldOfficeHour.Tutor &&
|
||||
|
@ -94,11 +93,11 @@ func (r *OfficeHourRepo) Add(officeHour models.OfficeHour) error {
|
|||
officeHour.Info == oldOfficeHour.Info &&
|
||||
officeHour.Active == oldOfficeHour.Active &&
|
||||
officeHour.Duration == oldOfficeHour.Duration {
|
||||
return nil
|
||||
return officeHour.Id, nil
|
||||
}
|
||||
}
|
||||
|
||||
_, err = r.db.Exec("INSERT INTO `officeHour` (tutor, day, hour, minute, room, course, week, info, active, duration) VALUES (?,?,?,?,?,?,?,?,?,?)",
|
||||
sqlResult, err := r.db.Exec("INSERT INTO `officeHour` (tutor, day, hour, minute, room, course, week, info, active, duration) VALUES (?,?,?,?,?,?,?,?,?,?)",
|
||||
officeHour.Tutor.Id,
|
||||
officeHour.Date.Day,
|
||||
officeHour.Date.Hour,
|
||||
|
@ -109,7 +108,8 @@ func (r *OfficeHourRepo) Add(officeHour models.OfficeHour) error {
|
|||
officeHour.Info,
|
||||
officeHour.Active,
|
||||
officeHour.Duration)
|
||||
return err
|
||||
id64, _ := sqlResult.LastInsertId()
|
||||
return int(id64), err
|
||||
}
|
||||
|
||||
func (r *OfficeHourRepo) Delete(officeHour models.OfficeHour) error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue