Skip to content

Commit

Permalink
fix: add is_anonymous to responsebody
Browse files Browse the repository at this point in the history
  • Loading branch information
kavos113 committed Nov 9, 2024
1 parent 44bda24 commit 4c36179
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
9 changes: 8 additions & 1 deletion controller/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func questionnaire2QuestionnaireDetail(questionnaires model.Questionnaires, admi
Admins: createUsersAndGroups(adminUsers, adminGroups),
CreatedAt: questionnaires.CreatedAt,
Description: questionnaires.Description,
IsAllowingMultipleResponses: questionnaires.IsAllowingMultipleResponses,
// IsAllowingMultipleResponses: questionnaires.IsAllowingMultipleResponses,
IsAnonymous: questionnaires.IsAnonymous,
IsPublished: questionnaires.IsPublished,
ModifiedAt: questionnaires.ModifiedAt,
Expand Down Expand Up @@ -264,6 +264,12 @@ func respondentDetail2Response(ctx echo.Context, respondentDetail model.Responde
oResponseBodies = append(oResponseBodies, oResponseBody)
}

isAnonymous, err := model.NewQuestionnaire().GetResponseIsAnonymousByQuestionnaireID(ctx.Request().Context(), respondentDetail.QuestionnaireID)
if err != nil {
ctx.Logger().Errorf("failed to get response is anonymous: %+v", err)
return openapi.Response{}, err
}

res := openapi.Response{
Body: oResponseBodies,
IsDraft: respondentDetail.SubmittedAt.Valid,
Expand All @@ -272,6 +278,7 @@ func respondentDetail2Response(ctx echo.Context, respondentDetail model.Responde
Respondent: &(respondentDetail.TraqID),
ResponseId: respondentDetail.ResponseID,
SubmittedAt: respondentDetail.SubmittedAt.Time,
IsAnonymous: &isAnonymous,
}

return res, nil
Expand Down
3 changes: 3 additions & 0 deletions controller/questionnaire.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,13 +656,16 @@ func (q Questionnaire) PostQuestionnaireResponse(c echo.Context, questionnaireID
}
}

isAnonymous, err := q.GetResponseIsAnonymousByQuestionnaireID(c.Request().Context(), questionnaireID)

res = openapi.Response{
QuestionnaireId: questionnaireID,
ResponseId: resopnseID,
Respondent: &userID,
SubmittedAt: submittedAt,
ModifiedAt: modifiedAt,
IsDraft: params.IsDraft,
IsAnonymous: &isAnonymous,
Body: params.Body,
}

Expand Down
5 changes: 3 additions & 2 deletions controller/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func (r Response) GetMyResponses(ctx echo.Context, params openapi.GetMyResponses
Respondent: &userID,
ResponseId: response.ResponseId,
SubmittedAt: response.SubmittedAt,
IsAnonymous: response.IsAnonymous,
}
res = append(res, tmp)
}
Expand Down Expand Up @@ -244,6 +245,6 @@ func (r Response) EditResponse(ctx echo.Context, responseID openapi.ResponseIDIn
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Errorf("failed to insert responses: %w", err))
}
}

return nil
}
}

0 comments on commit 4c36179

Please sign in to comment.