Add some log messaging for participant creation process

This commit is contained in:
Andrea Fazzi 2020-12-29 18:53:13 +01:00
parent 5b25b76840
commit a3a7c43bc6

View file

@ -2,6 +2,7 @@ package orm
import ( import (
"fmt" "fmt"
"log"
"net/http" "net/http"
"strconv" "strconv"
@ -186,6 +187,7 @@ func (model *Participant) Create(db *Database, args map[string]string, w http.Re
} }
// Check if participant exists // Check if participant exists
log.Printf("Check if participant %s already exists", participant)
if user, err := participant.exists(db); err == nil && user != nil { if user, err := participant.exists(db); err == nil && user != nil {
if err := db._db.Where("user_id = ?", user.ID).Find(&participant).Error; err != nil { if err := db._db.Where("user_id = ?", user.ID).Find(&participant).Error; err != nil {
return nil, err return nil, err
@ -210,6 +212,7 @@ func (model *Participant) Create(db *Database, args map[string]string, w http.Re
if err := db._db.First(&school, participant.SchoolID).Error; err != nil { if err := db._db.First(&school, participant.SchoolID).Error; err != nil {
return nil, err return nil, err
} }
log.Printf("Check if a participant of the same category exists for school %s", school)
hasCategory, err := school.HasCategory(db, participant) hasCategory, err := school.HasCategory(db, participant)
if err != nil { if err != nil {
return nil, err return nil, err
@ -221,6 +224,8 @@ func (model *Participant) Create(db *Database, args map[string]string, w http.Re
WriteCreator(r, participant) WriteCreator(r, participant)
log.Printf("Create participant %s", participant)
participant, err = CreateParticipant(db, participant) participant, err = CreateParticipant(db, participant)
if err != nil { if err != nil {
return nil, err return nil, err