Erstelle Maske, um Sprechstunden hinzuzufügen

This commit is contained in:
Gonne 2022-08-31 22:49:14 +02:00
parent c7a9522c2c
commit 369f4ebcec
15 changed files with 357 additions and 50 deletions

View file

@ -43,6 +43,15 @@ func (r *TutorRepo) FindById(id int) (models.Tutor, error) {
return tutor, nil
}
func (r *TutorRepo) FindByNameAndEmail(name string, email string) (models.Tutor, error) {
row := r.db.QueryRow("SELECT * FROM tutor WHERE email=? AND name=?", email, name)
var tutor models.Tutor
if err := row.Scan(&tutor.Id, &tutor.Name, &tutor.Email); err != nil {
return models.Tutor{}, err
}
return tutor, nil
}
func (r *TutorRepo) GetAll() ([]models.Tutor, error) {
rows, err := r.db.Query("SELECT * FROM tutor")
if err != nil {
@ -64,5 +73,12 @@ func (r *TutorRepo) Save(tutor models.Tutor) error {
return nil
}
func (r *TutorRepo) Add(tutor models.Tutor) error {
return nil
//Don't add identical tutors
_, err := r.FindByNameAndEmail(tutor.Name, tutor.Email)
if err == sql.ErrNoRows {
_, err = r.db.Exec("INSERT INTO `tutor` (name, email) VALUES (?,?);", tutor.Name, tutor.Email)
return err
}
return err
}