Fix user modifier for response

This commit is contained in:
Andrea Fazzi 2019-12-16 07:50:18 +01:00
parent 24ad134e66
commit 973ff5a1af
3 changed files with 28 additions and 6 deletions

View file

@ -87,10 +87,6 @@ func (model *Participant) exists() (*User, error) {
return &user, nil
}
func (model *Participant) AfterCreate(tx *gorm.DB) error {
response.UserModifierCreate = NewUserModifierCreate(r)
}
func (model *Participant) BeforeSave(tx *gorm.DB) error {
var user User
@ -200,6 +196,19 @@ func (model *Participant) Create(args map[string]string, w http.ResponseWriter,
if err != nil {
return nil, err
}
var response Response
if err := DB().Debug().First(&response, &Response{ParticipantID: participant.ID}).Error; err != nil {
return nil, err
}
response.UserModifierCreate = NewUserModifierCreate(r)
if err := DB().Save(&response).Error; err != nil {
return nil, err
}
return participant, nil
}
}
@ -348,6 +357,19 @@ func (model *Participant) Update(args map[string]string, w http.ResponseWriter,
if err != nil {
return nil, err
}
var response Response
if err := DB().Debug().First(&response, &Response{ParticipantID: participant.(*Participant).ID}).Error; err != nil {
return nil, err
}
response.UserModifierUpdate = NewUserModifierUpdate(r)
if err := DB().Save(&response).Error; err != nil {
return nil, err
}
return participant.(*Participant), nil
}
}

View file

@ -81,7 +81,7 @@ func (model *Response) Read(args map[string]string, w http.ResponseWriter, r *ht
func (model *Response) ReadAll(args map[string]string, w http.ResponseWriter, r *http.Request) (interface{}, error) {
var responses []*Response
if err := DB().Preload("Contest", "Participant").Order("created_at").Find(&responses).Error; err != nil {
if err := DB().Preload("Contest").Preload("Participant").Order("created_at").Find(&responses).Error; err != nil {
return nil, err
}
return responses, nil

View file

@ -4,7 +4,7 @@
<div class="container">
{{$options := `
title: "Responses"
buttonTitle: "Crea nuovo Response"
buttonTitle: "Crea nuova prova partecipante"
`}}
{{template "read_all_header" dict "options" ($options | yaml) "lengthData" (len .Data) "modelPath" (create "Response")}}