Question: fix answers
This commit is contained in:
parent
01ab1aa509
commit
5303afc6e8
2
go.mod
2
go.mod
|
@ -19,7 +19,7 @@ require (
|
|||
github.com/sirupsen/logrus v1.8.0
|
||||
github.com/vektah/gqlparser/v2 v2.1.0
|
||||
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83
|
||||
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2 // indirect
|
||||
golang.org/x/sys v0.0.0-20210313110737-8e9fff1a3a18 // indirect
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
)
|
||||
|
|
4
go.sum
4
go.sum
|
@ -223,8 +223,8 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210218155724-8ebf48af031b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2 h1:46ULzRKLh1CwgRq2dC5SlBzEqqNCi8rreOZnNrbqcIY=
|
||||
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210313110737-8e9fff1a3a18 h1:jxr7/dEo+rR29uEBoLSWJ1tRHCFAMwFbGUU9nRqzpds=
|
||||
golang.org/x/sys v0.0.0-20210313110737-8e9fff1a3a18/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
|
|
|
@ -1020,13 +1020,13 @@ type Question {
|
|||
explanation: String
|
||||
correctAnswer: Answer!
|
||||
image: String
|
||||
answerA: Answer
|
||||
answerA: String
|
||||
answerAImage: String
|
||||
answerB: Answer
|
||||
answerB: String
|
||||
answerBImage: String
|
||||
answerC: Answer
|
||||
answerC: String
|
||||
answerCImage: String
|
||||
answerD: Answer
|
||||
answerD: String
|
||||
answerDImage: String
|
||||
qualification: Qualification @goField(forceResolver: true)
|
||||
createdAt: Time!
|
||||
|
@ -1046,16 +1046,16 @@ input QuestionInput {
|
|||
qualificationID: Int
|
||||
image: Upload
|
||||
deleteImage: Boolean
|
||||
answerA: Answer
|
||||
answerA: String
|
||||
answerAImage: Upload
|
||||
deleteAnswerAImage: Boolean
|
||||
answerB: Answer
|
||||
answerB: String
|
||||
answerBImage: Upload
|
||||
deleteAnswerBImage: Boolean
|
||||
answerC: Answer
|
||||
answerC: String
|
||||
answerCImage: Upload
|
||||
deleteAnswerCImage: Boolean
|
||||
answerD: Answer
|
||||
answerD: String
|
||||
answerDImage: Upload
|
||||
deleteAnswerDImage: Boolean
|
||||
}
|
||||
|
@ -4141,9 +4141,9 @@ func (ec *executionContext) _Question_answerA(ctx context.Context, field graphql
|
|||
if resTmp == nil {
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(models.Answer)
|
||||
res := resTmp.(string)
|
||||
fc.Result = res
|
||||
return ec.marshalOAnswer2githubᚗcomᚋzdamᚑegzaminᚑzawodowyᚋbackendᚋinternalᚋmodelsᚐAnswer(ctx, field.Selections, res)
|
||||
return ec.marshalOString2string(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Question_answerAImage(ctx context.Context, field graphql.CollectedField, obj *models.Question) (ret graphql.Marshaler) {
|
||||
|
@ -4205,9 +4205,9 @@ func (ec *executionContext) _Question_answerB(ctx context.Context, field graphql
|
|||
if resTmp == nil {
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(models.Answer)
|
||||
res := resTmp.(string)
|
||||
fc.Result = res
|
||||
return ec.marshalOAnswer2githubᚗcomᚋzdamᚑegzaminᚑzawodowyᚋbackendᚋinternalᚋmodelsᚐAnswer(ctx, field.Selections, res)
|
||||
return ec.marshalOString2string(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Question_answerBImage(ctx context.Context, field graphql.CollectedField, obj *models.Question) (ret graphql.Marshaler) {
|
||||
|
@ -4269,9 +4269,9 @@ func (ec *executionContext) _Question_answerC(ctx context.Context, field graphql
|
|||
if resTmp == nil {
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(models.Answer)
|
||||
res := resTmp.(string)
|
||||
fc.Result = res
|
||||
return ec.marshalOAnswer2githubᚗcomᚋzdamᚑegzaminᚑzawodowyᚋbackendᚋinternalᚋmodelsᚐAnswer(ctx, field.Selections, res)
|
||||
return ec.marshalOString2string(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Question_answerCImage(ctx context.Context, field graphql.CollectedField, obj *models.Question) (ret graphql.Marshaler) {
|
||||
|
@ -4333,9 +4333,9 @@ func (ec *executionContext) _Question_answerD(ctx context.Context, field graphql
|
|||
if resTmp == nil {
|
||||
return graphql.Null
|
||||
}
|
||||
res := resTmp.(models.Answer)
|
||||
res := resTmp.(string)
|
||||
fc.Result = res
|
||||
return ec.marshalOAnswer2githubᚗcomᚋzdamᚑegzaminᚑzawodowyᚋbackendᚋinternalᚋmodelsᚐAnswer(ctx, field.Selections, res)
|
||||
return ec.marshalOString2string(ctx, field.Selections, res)
|
||||
}
|
||||
|
||||
func (ec *executionContext) _Question_answerDImage(ctx context.Context, field graphql.CollectedField, obj *models.Question) (ret graphql.Marshaler) {
|
||||
|
@ -6623,7 +6623,7 @@ func (ec *executionContext) unmarshalInputQuestionInput(ctx context.Context, obj
|
|||
var err error
|
||||
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("answerA"))
|
||||
it.AnswerA, err = ec.unmarshalOAnswer2ᚖgithubᚗcomᚋzdamᚑegzaminᚑzawodowyᚋbackendᚋinternalᚋmodelsᚐAnswer(ctx, v)
|
||||
it.AnswerA, err = ec.unmarshalOString2ᚖstring(ctx, v)
|
||||
if err != nil {
|
||||
return it, err
|
||||
}
|
||||
|
@ -6647,7 +6647,7 @@ func (ec *executionContext) unmarshalInputQuestionInput(ctx context.Context, obj
|
|||
var err error
|
||||
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("answerB"))
|
||||
it.AnswerB, err = ec.unmarshalOAnswer2ᚖgithubᚗcomᚋzdamᚑegzaminᚑzawodowyᚋbackendᚋinternalᚋmodelsᚐAnswer(ctx, v)
|
||||
it.AnswerB, err = ec.unmarshalOString2ᚖstring(ctx, v)
|
||||
if err != nil {
|
||||
return it, err
|
||||
}
|
||||
|
@ -6671,7 +6671,7 @@ func (ec *executionContext) unmarshalInputQuestionInput(ctx context.Context, obj
|
|||
var err error
|
||||
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("answerC"))
|
||||
it.AnswerC, err = ec.unmarshalOAnswer2ᚖgithubᚗcomᚋzdamᚑegzaminᚑzawodowyᚋbackendᚋinternalᚋmodelsᚐAnswer(ctx, v)
|
||||
it.AnswerC, err = ec.unmarshalOString2ᚖstring(ctx, v)
|
||||
if err != nil {
|
||||
return it, err
|
||||
}
|
||||
|
@ -6695,7 +6695,7 @@ func (ec *executionContext) unmarshalInputQuestionInput(ctx context.Context, obj
|
|||
var err error
|
||||
|
||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("answerD"))
|
||||
it.AnswerD, err = ec.unmarshalOAnswer2ᚖgithubᚗcomᚋzdamᚑegzaminᚑzawodowyᚋbackendᚋinternalᚋmodelsᚐAnswer(ctx, v)
|
||||
it.AnswerD, err = ec.unmarshalOString2ᚖstring(ctx, v)
|
||||
if err != nil {
|
||||
return it, err
|
||||
}
|
||||
|
@ -8328,16 +8328,6 @@ func (ec *executionContext) marshalN__TypeKind2string(ctx context.Context, sel a
|
|||
return res
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalOAnswer2githubᚗcomᚋzdamᚑegzaminᚑzawodowyᚋbackendᚋinternalᚋmodelsᚐAnswer(ctx context.Context, v interface{}) (models.Answer, error) {
|
||||
var res models.Answer
|
||||
err := res.UnmarshalGQL(v)
|
||||
return res, graphql.ErrorOnPath(ctx, err)
|
||||
}
|
||||
|
||||
func (ec *executionContext) marshalOAnswer2githubᚗcomᚋzdamᚑegzaminᚑzawodowyᚋbackendᚋinternalᚋmodelsᚐAnswer(ctx context.Context, sel ast.SelectionSet, v models.Answer) graphql.Marshaler {
|
||||
return v
|
||||
}
|
||||
|
||||
func (ec *executionContext) unmarshalOAnswer2ᚖgithubᚗcomᚋzdamᚑegzaminᚑzawodowyᚋbackendᚋinternalᚋmodelsᚐAnswer(ctx context.Context, v interface{}) (*models.Answer, error) {
|
||||
if v == nil {
|
||||
return nil, nil
|
||||
|
|
|
@ -12,13 +12,13 @@ type Question {
|
|||
explanation: String
|
||||
correctAnswer: Answer!
|
||||
image: String
|
||||
answerA: Answer
|
||||
answerA: String
|
||||
answerAImage: String
|
||||
answerB: Answer
|
||||
answerB: String
|
||||
answerBImage: String
|
||||
answerC: Answer
|
||||
answerC: String
|
||||
answerCImage: String
|
||||
answerD: Answer
|
||||
answerD: String
|
||||
answerDImage: String
|
||||
qualification: Qualification @goField(forceResolver: true)
|
||||
createdAt: Time!
|
||||
|
@ -38,16 +38,16 @@ input QuestionInput {
|
|||
qualificationID: Int
|
||||
image: Upload
|
||||
deleteImage: Boolean
|
||||
answerA: Answer
|
||||
answerA: String
|
||||
answerAImage: Upload
|
||||
deleteAnswerAImage: Boolean
|
||||
answerB: Answer
|
||||
answerB: String
|
||||
answerBImage: Upload
|
||||
deleteAnswerBImage: Boolean
|
||||
answerC: Answer
|
||||
answerC: String
|
||||
answerCImage: Upload
|
||||
deleteAnswerCImage: Boolean
|
||||
answerD: Answer
|
||||
answerD: String
|
||||
answerDImage: Upload
|
||||
deleteAnswerDImage: Boolean
|
||||
}
|
||||
|
|
|
@ -20,13 +20,13 @@ type Question struct {
|
|||
Explanation string `json:"explanation" xml:"explanation" gqlgen:"explanation"`
|
||||
CorrectAnswer Answer `pg:",unique:group_1,notnull" json:"correctAnswer" xml:"correctAnswer" gqlgen:"correctAnswer"`
|
||||
Image string `json:"image" xml:"image" gqlgen:"image"`
|
||||
AnswerA Answer `pg:"answer_a" json:"answerA" xml:"answerA" gqlgen:"answerA"`
|
||||
AnswerA string `pg:"answer_a" json:"answerA" xml:"answerA" gqlgen:"answerA"`
|
||||
AnswerAImage string `pg:"answer_a_image" json:"answerAImage" xml:"answerAImage" gqlgen:"answerAImage"`
|
||||
AnswerB Answer `pg:"answer_b" json:"answerB" xml:"answerB" gqlgen:"answerB"`
|
||||
AnswerB string `pg:"answer_b" json:"answerB" xml:"answerB" gqlgen:"answerB"`
|
||||
AnswerBImage string `pg:"answer_b_image" json:"answerBImage" xml:"answerBImage" gqlgen:"answerBImage"`
|
||||
AnswerC Answer `pg:"answer_c" json:"answerC" xml:"answerC" gqlgen:"answerC"`
|
||||
AnswerC string `pg:"answer_c" json:"answerC" xml:"answerC" gqlgen:"answerC"`
|
||||
AnswerCImage string `pg:"answer_c_image" json:"answerCImage" xml:"answerCImage" gqlgen:"answerCImage"`
|
||||
AnswerD Answer `pg:"answer_d" json:"answerD" xml:"answerD" gqlgen:"answerD"`
|
||||
AnswerD string `pg:"answer_d" json:"answerD" xml:"answerD" gqlgen:"answerD"`
|
||||
AnswerDImage string `pg:"answer_d_image" json:"answerDImage" xml:"answerDImage" gqlgen:"answerDImage"`
|
||||
QualificationID int `pg:",unique:group_1,on_delete:CASCADE" json:"qualificationID" xml:"qualificationID" gqlgen:"qualificationID"`
|
||||
Qualification *Qualification `pg:"rel:has-one" json:"qualification" xml:"qualification" gqlgen:"qualification"`
|
||||
|
@ -46,10 +46,10 @@ type QuestionInput struct {
|
|||
From *string `json:"from" xml:"from" gqlgen:"from"`
|
||||
Explanation *string `json:"explanation" xml:"explanation" gqlgen:"explanation"`
|
||||
CorrectAnswer *Answer `json:"correctAnswer" xml:"correctAnswer" gqlgen:"correctAnswer"`
|
||||
AnswerA *Answer `gqlgen:"answerA" json:"answerA" xml:"answerA"`
|
||||
AnswerB *Answer `gqlgen:"answerB" json:"answerB" xml:"answerB"`
|
||||
AnswerC *Answer `gqlgen:"answerC" json:"answerC" xml:"answerC"`
|
||||
AnswerD *Answer `gqlgen:"answerD" json:"answerD" xml:"answerD"`
|
||||
AnswerA *string `gqlgen:"answerA" json:"answerA" xml:"answerA"`
|
||||
AnswerB *string `gqlgen:"answerB" json:"answerB" xml:"answerB"`
|
||||
AnswerC *string `gqlgen:"answerC" json:"answerC" xml:"answerC"`
|
||||
AnswerD *string `gqlgen:"answerD" json:"answerD" xml:"answerD"`
|
||||
QualificationID *int `gqlgen:"qualificationID" json:"qualificationID" xml:"qualificationID"`
|
||||
Image *graphql.Upload `json:"image" xml:"image" gqlgen:"image"`
|
||||
DeleteImage *bool `json:"deleteImage" xml:"deleteImage" gqlgen:"deleteImage"`
|
||||
|
@ -103,6 +103,18 @@ func (input *QuestionInput) Sanitize() *QuestionInput {
|
|||
if input.Explanation != nil {
|
||||
*input.Explanation = strings.TrimSpace(*input.Explanation)
|
||||
}
|
||||
if input.AnswerA != nil {
|
||||
*input.AnswerA = strings.TrimSpace(*input.AnswerA)
|
||||
}
|
||||
if input.AnswerB != nil {
|
||||
*input.AnswerB = strings.TrimSpace(*input.AnswerB)
|
||||
}
|
||||
if input.AnswerC != nil {
|
||||
*input.AnswerC = strings.TrimSpace(*input.AnswerC)
|
||||
}
|
||||
if input.AnswerD != nil {
|
||||
*input.AnswerD = strings.TrimSpace(*input.AnswerD)
|
||||
}
|
||||
|
||||
return input
|
||||
}
|
||||
|
|
|
@ -141,26 +141,26 @@ func validateInput(input *models.QuestionInput, opts validateOptions) error {
|
|||
}
|
||||
|
||||
if input.AnswerA != nil {
|
||||
if !input.AnswerA.IsValid() {
|
||||
return fmt.Errorf(messageAnswerIsInvalid, "A")
|
||||
if *input.AnswerA == "" {
|
||||
return fmt.Errorf(messageAnswerIsRequired, "A")
|
||||
}
|
||||
}
|
||||
|
||||
if input.AnswerB != nil {
|
||||
if !input.AnswerB.IsValid() {
|
||||
return fmt.Errorf(messageAnswerIsInvalid, "B")
|
||||
if *input.AnswerA == "" {
|
||||
return fmt.Errorf(messageAnswerIsRequired, "B")
|
||||
}
|
||||
}
|
||||
|
||||
if input.AnswerC != nil {
|
||||
if !input.AnswerC.IsValid() {
|
||||
return fmt.Errorf(messageAnswerIsInvalid, "C")
|
||||
if *input.AnswerC == "" {
|
||||
return fmt.Errorf(messageAnswerIsRequired, "C")
|
||||
}
|
||||
}
|
||||
|
||||
if input.AnswerD != nil {
|
||||
if !input.AnswerD.IsValid() {
|
||||
return fmt.Errorf(messageAnswerIsInvalid, "D")
|
||||
if *input.AnswerD == "" {
|
||||
return fmt.Errorf(messageAnswerIsRequired, "D")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,25 +172,25 @@ func validateInput(input *models.QuestionInput, opts validateOptions) error {
|
|||
|
||||
if input.AnswerAImage != nil {
|
||||
if !validateMimeType(input.AnswerAImage.ContentType) {
|
||||
return fmt.Errorf(messageAnswerIsInvalid, "Obrazek odpowiedź A")
|
||||
return fmt.Errorf(messageImageNotAcceptableMIMEType, "Obrazek odpowiedź A")
|
||||
}
|
||||
}
|
||||
|
||||
if input.AnswerBImage != nil {
|
||||
if !validateMimeType(input.AnswerBImage.ContentType) {
|
||||
return fmt.Errorf(messageAnswerIsInvalid, "Obrazek odpowiedź B")
|
||||
return fmt.Errorf(messageImageNotAcceptableMIMEType, "Obrazek odpowiedź B")
|
||||
}
|
||||
}
|
||||
|
||||
if input.AnswerCImage != nil {
|
||||
if !validateMimeType(input.AnswerCImage.ContentType) {
|
||||
return fmt.Errorf(messageAnswerIsInvalid, "Obrazek odpowiedź C")
|
||||
return fmt.Errorf(messageImageNotAcceptableMIMEType, "Obrazek odpowiedź C")
|
||||
}
|
||||
}
|
||||
|
||||
if input.AnswerDImage != nil {
|
||||
if !validateMimeType(input.AnswerDImage.ContentType) {
|
||||
return fmt.Errorf(messageAnswerIsInvalid, "Obrazek odpowiedź D")
|
||||
return fmt.Errorf(messageImageNotAcceptableMIMEType, "Obrazek odpowiedź D")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in New Issue