diff --git a/Makefile b/Makefile index 0d5d9783..5df5221b 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,6 @@ dev: docker-compose -f compose/docker-compose_outside_docker.yml down docker-compose -f compose/docker-compose_outside_docker.yml up -d db docker-compose -f compose/docker-compose_outside_docker.yml up -d smtp - go run main.go --config=config/config_outside_docker.yaml & + go run -race main.go --config=config/config_outside_docker.yaml & all: dockerized diff --git a/orm/contest.go b/orm/contest.go index 366da332..aa2c7e4e 100644 --- a/orm/contest.go +++ b/orm/contest.go @@ -2,6 +2,7 @@ package orm import ( "fmt" + "log" "net/http" "time" @@ -21,6 +22,9 @@ type Contest struct { StartTime time.Time EndTime time.Time + NumQuestions int + NumAnswersPerQuestion int + Questions []*Question Participants []*Participant `gorm:"many2many:subscriptions"` } @@ -45,10 +49,16 @@ func (c *Contest) Create(args map[string]string, w http.ResponseWriter, r *http. date := r.FormValue("Date") startTime := r.FormValue("StartTime") endTime := r.FormValue("EndTime") - - r.PostForm.Set("Date", fmt.Sprintf("%sT%s:00+00:00", date, startTime)) - r.PostForm.Set("StartTime", fmt.Sprintf("%sT%s:00+00:00", date, startTime)) - r.PostForm.Set("EndTime", fmt.Sprintf("%sT%s:00+00:00", date, endTime)) + log.Println("Zero time", date) + if date == "" { + r.PostForm.Set("Date", time.Time{}.String()) + r.PostForm.Set("StartTime", time.Time{}.String()) + r.PostForm.Set("EndTime", time.Time{}.String()) + } else { + r.PostForm.Set("Date", fmt.Sprintf("%sT%s:00+00:00", date, startTime)) + r.PostForm.Set("StartTime", fmt.Sprintf("%sT%s:00+00:00", date, startTime)) + r.PostForm.Set("EndTime", fmt.Sprintf("%sT%s:00+00:00", date, endTime)) + } err = renderer.Decode(contest, r) if err != nil { @@ -120,17 +130,16 @@ func (c *Contest) Update(args map[string]string, w http.ResponseWriter, r *http. startTime := r.FormValue("StartTime") endTime := r.FormValue("EndTime") - r.PostForm.Set("Date", fmt.Sprintf("%sT%s:00+00:00", date, startTime)) - r.PostForm.Set("StartTime", fmt.Sprintf("%sT%s:00+00:00", date, startTime)) - r.PostForm.Set("EndTime", fmt.Sprintf("%sT%s:00+00:00", date, endTime)) - - err = r.ParseForm() - if err != nil { - return nil, err + if date == "" { + r.PostForm.Set("Date", time.Time{}.Format(time.RFC3339)) + r.PostForm.Set("StartTime", time.Time{}.Format(time.RFC3339)) + r.PostForm.Set("EndTime", time.Time{}.Format(time.RFC3339)) + } else { + r.PostForm.Set("Date", fmt.Sprintf("%sT%s:00+00:00", date, startTime)) + r.PostForm.Set("StartTime", fmt.Sprintf("%sT%s:00+00:00", date, startTime)) + r.PostForm.Set("EndTime", fmt.Sprintf("%sT%s:00+00:00", date, endTime)) } - r.Form["Date"][0] = fmt.Sprintf("%sT%s+00:00", date, startTime) - err = renderer.Decode(contest, r) if err != nil { return nil, err diff --git a/orm/participant.go b/orm/participant.go index 43174553..c59da3b4 100644 --- a/orm/participant.go +++ b/orm/participant.go @@ -2,9 +2,8 @@ package orm import ( "fmt" - "strconv" - "net/http" + "strconv" "strings" "git.andreafazzi.eu/andrea/oef/config" @@ -108,7 +107,7 @@ func (model *Participant) AfterSave(tx *gorm.DB) error { &Response{ Name: fmt.Sprintf("%s (%s)", contest.Name, model.String()), ContestID: contest.ID, - ParticipantID: model.UserID, + ParticipantID: model.ID, }).Error; err != nil { return err } diff --git a/orm/school.go b/orm/school.go index 496c283e..a97cb777 100644 --- a/orm/school.go +++ b/orm/school.go @@ -24,6 +24,12 @@ type School struct { Code string EmailSentDate time.Time + SchoolResponsibleLastname string + SchoolResponsibleFirstname string + + ContestResponsibleLastname string + ContestResponsibleFirstname string + UserID uint RegionID uint `schema:"region_id"` diff --git a/orm/useraction.go b/orm/useraction.go index 4d1e3faa..c0fb0ad6 100644 --- a/orm/useraction.go +++ b/orm/useraction.go @@ -1,7 +1,6 @@ package orm import ( - "log" "net/http" "github.com/dgrijalva/jwt-go" @@ -74,7 +73,6 @@ func NewUserModifierUpdate(r *http.Request) *UserModifierUpdate { if r.Context().Value("user") != nil { claims = r.Context().Value("user").(*jwt.Token).Claims.(jwt.MapClaims) } - log.Println("UPDATE Inside useraction", claims["user_id"]) return &UserModifierUpdate{ UpdaterID: claims["user_id"].(string), UpdaterRole: claims["role"].(string), diff --git a/renderer/funcmap.go b/renderer/funcmap.go index 99876f6f..fd7e22c6 100644 --- a/renderer/funcmap.go +++ b/renderer/funcmap.go @@ -28,6 +28,7 @@ var ( "prettyDate": prettyDate, "prettyTime": prettyTime, "prettyDateTime": prettyDateTime, + "zeroTime": zeroTime, "modelPath": modelPath, "dict": dict, "yaml": yaml, @@ -270,6 +271,10 @@ func prettyTime(value interface{}) string { return convertTime(value) } +func zeroTime(t *time.Time) bool { + return *t == time.Time{} +} + func modelPath(model string, action string, id uint) string { var q template.URL diff --git a/renderer/renderer.go b/renderer/renderer.go index 105f970d..24398b3c 100644 --- a/renderer/renderer.go +++ b/renderer/renderer.go @@ -323,6 +323,7 @@ func Decode(dst interface{}, r *http.Request) error { case "html": var timeConverter = func(value string) reflect.Value { + log.Println(value) if value == "" { return reflect.ValueOf(time.Time{}) } diff --git a/templates/contests_add_update.html.tpl b/templates/contests_add_update.html.tpl index 9edbba04..3539a708 100644 --- a/templates/contests_add_update.html.tpl +++ b/templates/contests_add_update.html.tpl @@ -5,12 +5,12 @@ {{if $update}} -{{template "breadcrumb" toSlice "Contests" (all "Contest") (.Data|string) (.Data.ID|show "Contest") "Aggiorna" "current"}} +{{template "breadcrumb" toSlice "Gare" (all "Contest") (.Data|string) (.Data.ID|show "Contest") "Aggiorna" "current"}} {{else}} -{{template "breadcrumb" toSlice "Contests" (all "Contest") "Aggiungi" "current"}} +{{template "breadcrumb" toSlice "Gare" (all "Contest") "Aggiungi" "current"}} {{end}} -{{template "add_update_header" dict "update" $update "addTitle" "Crea nuovo ELEMENTO" "updateTitle" (printf "Aggiorna gara %s" (.Data|string))}} +{{template "add_update_header" dict "update" $update "addTitle" "Crea nuova gara" "updateTitle" (printf "Aggiorna gara %s" (.Data|string))}} {{$form := "form_add_update"}}