Skip to content

Commit

Permalink
feat: unify IsAllowingMultipleResponses to IsDuplicateAnswerAllowed a…
Browse files Browse the repository at this point in the history
…nd update controller with new parameter
  • Loading branch information
Eraxyso authored Nov 2, 2024
1 parent 9346574 commit 84a33d2
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 115 deletions.
24 changes: 12 additions & 12 deletions controller/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (

func questionnaireInfo2questionnaireSummary(questionnaireInfo model.QuestionnaireInfo, allResponded bool, hasMyDraft bool, hasMyResponse bool, respondedDateTimeByMe null.Time) *openapi.QuestionnaireSummary {
res := openapi.QuestionnaireSummary{
AllResponded: allResponded,
CreatedAt: questionnaireInfo.CreatedAt,
Description: questionnaireInfo.Description,
HasMyDraft: hasMyDraft,
HasMyResponse: hasMyResponse,
// IsAllowingMultipleResponses: questionnaireInfo.IsAllowingMultipleResponses,
AllResponded: allResponded,
CreatedAt: questionnaireInfo.CreatedAt,
Description: questionnaireInfo.Description,
HasMyDraft: hasMyDraft,
HasMyResponse: hasMyResponse,
IsDuplicateAnswerAllowed: questionnaireInfo.IsDuplicateAnswerAllowed,
// IsAnonymous: questionnaireInfo.IsAnonymous,
// IsPublished: questionnaireInfo.IsPublished,
IsPublished: questionnaireInfo.IsPublished,
IsTargetingMe: questionnaireInfo.IsTargeted,
ModifiedAt: questionnaireInfo.ModifiedAt,
QuestionnaireId: questionnaireInfo.ID,
Expand Down Expand Up @@ -149,12 +149,12 @@ func convertRespondents(respondents []model.Respondents) []string {

func questionnaire2QuestionnaireDetail(questionnaires model.Questionnaires, adminUsers []string, adminGroups []string, targetUsers []string, targetGroups []string, respondents []string) openapi.QuestionnaireDetail {
res := openapi.QuestionnaireDetail{
Admins: createUsersAndGroups(adminUsers, adminGroups),
CreatedAt: questionnaires.CreatedAt,
Description: questionnaires.Description,
// IsAllowingMultipleResponses: questionnaires.IsAllowingMultipleResponses,
Admins: createUsersAndGroups(adminUsers, adminGroups),
CreatedAt: questionnaires.CreatedAt,
Description: questionnaires.Description,
IsDuplicateAnswerAllowed: questionnaires.IsDuplicateAnswerAllowed,
// IsAnonymous: questionnaires.IsAnonymous,
// IsPublished: questionnaires.IsPublished,
IsPublished: questionnaires.IsPublished,
ModifiedAt: questionnaires.ModifiedAt,
QuestionnaireId: questionnaires.ID,
Questions: convertQuestions(questionnaires.Questions),
Expand Down
20 changes: 10 additions & 10 deletions controller/questionnaire.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (q Questionnaire) PostQuestionnaire(c echo.Context, userID string, params o
questionnaireID := 0

err := q.ITransaction.Do(c.Request().Context(), nil, func(ctx context.Context) error {
questionnaireID, err := q.InsertQuestionnaire(ctx, params.Title, params.Description, responseDueDateTime, convertResponseViewableBy(params.ResponseViewableBy), params.IsPublished)
questionnaireID, err := q.InsertQuestionnaire(ctx, params.Title, params.Description, responseDueDateTime, convertResponseViewableBy(params.ResponseViewableBy), params.IsPublished, params.IsDuplicateAnswerAllowed)
if err != nil {
c.Logger().Errorf("failed to insert questionnaire: %+v", err)
return err
Expand Down Expand Up @@ -214,12 +214,12 @@ func (q Questionnaire) PostQuestionnaire(c echo.Context, userID string, params o
c.Logger().Errorf("failed to get question settings: %+v", err)
return openapi.QuestionnaireDetail{}, echo.NewHTTPError(http.StatusInternalServerError, "failed to get question settings")
}
err = q.IScaleLabel.InsertScaleLabel(c.Request().Context(), question.ID,
err = q.IScaleLabel.InsertScaleLabel(c.Request().Context(), question.ID,
model.ScaleLabels{
ScaleLabelLeft: *b.MinLabel,
ScaleLabelLeft: *b.MinLabel,
ScaleLabelRight: *b.MaxLabel,
ScaleMax: b.MaxValue,
ScaleMin: b.MinValue,
ScaleMax: b.MaxValue,
ScaleMin: b.MinValue,
})
if err != nil {
c.Logger().Errorf("failed to insert scale label: %+v", err)
Expand Down Expand Up @@ -302,7 +302,7 @@ func (q Questionnaire) EditQuestionnaire(c echo.Context, questionnaireID int, pa
responseDueDateTime.Time = *params.ResponseDueDateTime
}
err := q.ITransaction.Do(c.Request().Context(), nil, func(ctx context.Context) error {
err := q.UpdateQuestionnaire(ctx, params.Title, params.Description, responseDueDateTime, string(params.ResponseViewableBy), questionnaireID, params.IsPublished)
err := q.UpdateQuestionnaire(ctx, params.Title, params.Description, responseDueDateTime, string(params.ResponseViewableBy), questionnaireID, params.IsPublished, params.IsDuplicateAnswerAllowed)
if err != nil && !errors.Is(err, model.ErrNoRecordUpdated) {
c.Logger().Errorf("failed to update questionnaire: %+v", err)
return err
Expand Down Expand Up @@ -397,12 +397,12 @@ func (q Questionnaire) EditQuestionnaire(c echo.Context, questionnaireID int, pa
c.Logger().Errorf("failed to get question settings: %+v", err)
return echo.NewHTTPError(http.StatusInternalServerError, "failed to get question settings")
}
err = q.IScaleLabel.UpdateScaleLabel(c.Request().Context(), question.ID,
err = q.IScaleLabel.UpdateScaleLabel(c.Request().Context(), question.ID,
model.ScaleLabels{
ScaleLabelLeft: *b.MinLabel,
ScaleLabelLeft: *b.MinLabel,
ScaleLabelRight: *b.MaxLabel,
ScaleMax: b.MaxValue,
ScaleMin: b.MinValue,
ScaleMax: b.MaxValue,
ScaleMin: b.MinValue,
})
if err != nil && !errors.Is(err, model.ErrNoRecordUpdated) {
c.Logger().Errorf("failed to insert scale label: %+v", err)
Expand Down
10 changes: 5 additions & 5 deletions docs/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ components:
- $ref: "#/components/schemas/QuestionnaireResponseDueDateTime"
- $ref: "#/components/schemas/QuestionnaireResponseViewableBy"
- $ref: "#/components/schemas/QuestionnaireIsAnonymous"
- $ref: "#/components/schemas/QuestionnaireIsAllowingMultipleResponses"
- $ref: "#/components/schemas/QuestionnaireIsDuplicateAnswerAllowed"
- $ref: "#/components/schemas/QuestionnaireIsPublished"
- $ref: "#/components/schemas/QuestionnaireTargetsAndAdmins"
NewQuestionnaire:
Expand Down Expand Up @@ -519,7 +519,7 @@ components:
- $ref: "#/components/schemas/QuestionnaireResponseDueDateTime"
- $ref: "#/components/schemas/QuestionnaireResponseViewableBy"
- $ref: "#/components/schemas/QuestionnaireIsAnonymous"
- $ref: "#/components/schemas/QuestionnaireIsAllowingMultipleResponses"
- $ref: "#/components/schemas/QuestionnaireIsDuplicateAnswerAllowed"
- $ref: "#/components/schemas/QuestionnaireIsPublished"
- $ref: "#/components/schemas/QuestionnaireIsTargetingMe"
- $ref: "#/components/schemas/QuestionnaireCreatedAt"
Expand Down Expand Up @@ -608,16 +608,16 @@ components:
匿名回答かどうか
required:
- is_anonymous
QuestionnaireIsAllowingMultipleResponses:
QuestionnaireIsDuplicateAnswerAllowed:
type: object
properties:
is_allowing_multiple_responses:
is_duplicate_answer_allowed:
type: boolean
example: true
description: |
一人が複数回回答できるかどうか
required:
- is_allowing_multiple_responses
- is_duplicate_answer_allowed
QuestionnaireIsPublished:
type: object
properties:
Expand Down
140 changes: 70 additions & 70 deletions openapi/spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 84a33d2

Please sign in to comment.