Skip to content

Commit

Permalink
fix: add question operations in questionnaire handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Eraxyso authored Nov 14, 2024
1 parent 4ae8961 commit 47fe43d
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions controller/questionnaire.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controller

import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
Expand Down Expand Up @@ -156,6 +157,25 @@ func (q Questionnaire) PostQuestionnaire(c echo.Context, userID string, params o
c.Logger().Errorf("failed to insert administrator groups: %+v", err)
return err
}
for questoinNum, question := range params.Questions {
b, err := question.MarshalJSON()
if err != nil {
c.Logger().Errorf("failed to marshal new question: %+v", err)
return err
}
var questionParsed map[string]interface{}
err = json.Unmarshal([]byte(b), &questionParsed)
if err != nil {
c.Logger().Errorf("failed to unmarshal new question: %+v", err)
return err
}
questionType := questionParsed["question_type"].(string)
_, err = q.InsertQuestion(ctx, questionnaireID, 1, questoinNum+1, questionType, question.Body, question.IsRequired)

Check failure on line 173 in controller/questionnaire.go

View workflow job for this annotation

GitHub Actions / Lint

question.Body undefined (type openapi.NewQuestion has no field or method Body)

Check failure on line 173 in controller/questionnaire.go

View workflow job for this annotation

GitHub Actions / Lint

question.Body undefined (type openapi.NewQuestion has no field or method Body)

Check failure on line 173 in controller/questionnaire.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] controller/questionnaire.go#L173

question.Body undefined (type openapi.NewQuestion has no field or method Body)
Raw output
controller/questionnaire.go:173:93: question.Body undefined (type openapi.NewQuestion has no field or method Body)

Check failure on line 173 in controller/questionnaire.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] controller/questionnaire.go#L173

question.Body undefined (type openapi.NewQuestion has no field or method Body)
Raw output
controller/questionnaire.go:173:93: question.Body undefined (type openapi.NewQuestion has no field or method Body)
if err != nil {
c.Logger().Errorf("failed to insert question: %+v", err)
return err
}
}

message := createQuestionnaireMessage(
questionnaireID,
Expand Down Expand Up @@ -357,6 +377,33 @@ func (q Questionnaire) EditQuestionnaire(c echo.Context, questionnaireID int, pa
c.Logger().Errorf("failed to insert administrator groups: %+v", err)
return err
}
for questoinNum, question := range params.Questions {
b, err := question.MarshalJSON()
if err != nil {
c.Logger().Errorf("failed to marshal new question: %+v", err)
return err
}
var questionParsed map[string]interface{}
err = json.Unmarshal([]byte(b), &questionParsed)
if err != nil {
c.Logger().Errorf("failed to unmarshal new question: %+v", err)
return err
}
questionType := questionParsed["question_type"].(string)
if question.QuestionId == nil {

Check failure on line 393 in controller/questionnaire.go

View workflow job for this annotation

GitHub Actions / Lint

invalid operation: question.QuestionId == nil (mismatched types int and untyped nil)

Check failure on line 393 in controller/questionnaire.go

View workflow job for this annotation

GitHub Actions / Lint

invalid operation: question.QuestionId == nil (mismatched types int and untyped nil)

Check failure on line 393 in controller/questionnaire.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] controller/questionnaire.go#L393

invalid operation: question.QuestionId == nil (mismatched types int and untyped nil)
Raw output
controller/questionnaire.go:393:30: invalid operation: question.QuestionId == nil (mismatched types int and untyped nil)

Check failure on line 393 in controller/questionnaire.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] controller/questionnaire.go#L393

invalid operation: question.QuestionId == nil (mismatched types int and untyped nil)
Raw output
controller/questionnaire.go:393:30: invalid operation: question.QuestionId == nil (mismatched types int and untyped nil)
_, err = q.InsertQuestion(ctx, questionnaireID, 1, questoinNum+1, questionType, question.Body, question.IsRequired)

Check failure on line 394 in controller/questionnaire.go

View workflow job for this annotation

GitHub Actions / Lint

question.Body undefined (type openapi.Question has no field or method Body)

Check failure on line 394 in controller/questionnaire.go

View workflow job for this annotation

GitHub Actions / Lint

question.Body undefined (type openapi.Question has no field or method Body)

Check failure on line 394 in controller/questionnaire.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] controller/questionnaire.go#L394

question.Body undefined (type openapi.Question has no field or method Body)
Raw output
controller/questionnaire.go:394:94: question.Body undefined (type openapi.Question has no field or method Body)

Check failure on line 394 in controller/questionnaire.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] controller/questionnaire.go#L394

question.Body undefined (type openapi.Question has no field or method Body)
Raw output
controller/questionnaire.go:394:94: question.Body undefined (type openapi.Question has no field or method Body)
if err != nil {
c.Logger().Errorf("failed to insert question: %+v", err)
return err
}
} else {
err = q.UpdateQuestion(ctx, questionnaireID, 1, questoinNum+1, questionType, question.Body, question.IsRequired, *question.QuestionId)

Check failure on line 400 in controller/questionnaire.go

View workflow job for this annotation

GitHub Actions / Lint

question.Body undefined (type openapi.Question has no field or method Body)

Check failure on line 400 in controller/questionnaire.go

View workflow job for this annotation

GitHub Actions / Lint

invalid operation: cannot indirect question.QuestionId (variable of type int) (typecheck)

Check failure on line 400 in controller/questionnaire.go

View workflow job for this annotation

GitHub Actions / Lint

question.Body undefined (type openapi.Question has no field or method Body)

Check failure on line 400 in controller/questionnaire.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] controller/questionnaire.go#L400

question.Body undefined (type openapi.Question has no field or method Body)
Raw output
controller/questionnaire.go:400:91: question.Body undefined (type openapi.Question has no field or method Body)

Check failure on line 400 in controller/questionnaire.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] controller/questionnaire.go#L400

invalid operation: cannot indirect question.QuestionId (variable of type int) (typecheck)
Raw output
controller/questionnaire.go:400:119: invalid operation: cannot indirect question.QuestionId (variable of type int) (typecheck)
package controller

Check failure on line 400 in controller/questionnaire.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] controller/questionnaire.go#L400

question.Body undefined (type openapi.Question has no field or method Body)
Raw output
controller/questionnaire.go:400:91: question.Body undefined (type openapi.Question has no field or method Body)

Check failure on line 400 in controller/questionnaire.go

View workflow job for this annotation

GitHub Actions / golangci

[golangci] controller/questionnaire.go#L400

invalid operation: cannot indirect question.QuestionId (variable of type int)) (typecheck)
Raw output
controller/questionnaire.go:400:119: invalid operation: cannot indirect question.QuestionId (variable of type int)) (typecheck)
	"github.com/traPtitech/anke-to/controller"
	^
if err != nil {
c.Logger().Errorf("failed to update question: %+v", err)
return err
}
}
}

return nil
})
Expand Down Expand Up @@ -483,6 +530,19 @@ func (q Questionnaire) DeleteQuestionnaire(c echo.Context, questionnaireID int)
return err
}

questions, err := q.GetQuestions(c.Request().Context(), questionnaireID)
if err != nil {
c.Logger().Errorf("failed to get questions: %+v", err)
return err
}
for _, question := range questions {
err = q.DeleteQuestion(c.Request().Context(), question.ID)
if err != nil {
c.Logger().Errorf("failed to delete administrators: %+v", err)
return err
}
}

return nil
})
if err != nil {
Expand Down

0 comments on commit 47fe43d

Please sign in to comment.