Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

動けるようにする #1288

Open
wants to merge 24 commits into
base: fix/openapi
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d33f4f9
fix: update local server url in swagger configuration
Eraxyso Dec 19, 2024
362ed96
fix: update the wire configuration and move middleware from the handl…
Eraxyso Dec 19, 2024
c72dd83
fix: delete OapiRequestValidator
Eraxyso Dec 19, 2024
4838f4f
fix: resolve remaining error caused by previous schema change
Eraxyso Dec 19, 2024
78af188
fix: update CI workflow as the router no longer exists
Eraxyso Dec 19, 2024
120a0d9
Merge remote-tracking branch 'origin/fix/openapi' into fix/openapi-run
Eraxyso Jan 6, 2025
2439e59
fix: correct index of responseIDs in TestGetMyResponseIDs
Eraxyso Jan 6, 2025
2517d41
fix: fix function TestCancelTargets
Eraxyso Jan 9, 2025
c78d59e
fix: fix setupQuestionnairesTest and updateQuestionnaireTest
Eraxyso Jan 9, 2025
cf95822
fix: fix GetRespondentDetails ,TestGetRespondentDetails and TestGetMy…
Eraxyso Jan 9, 2025
65e13bb
fix: fix logic of checking questionnaireIDs in GetRespondentInfos
Eraxyso Jan 13, 2025
d168125
fix: improve the logic of TestGetMyResponseIDs
Eraxyso Jan 13, 2025
e0f9dbb
fix: fix getQuestionnairesTest and GetQuestionnaires
Eraxyso Jan 14, 2025
e1c8e7b
fix: add error checks in the controller adapter
Eraxyso Jan 14, 2025
916d8e4
fix: add error handling for some operation in controller
Eraxyso Jan 14, 2025
c92364b
fix: update the version of some ci workflow and add configuration for…
Eraxyso Jan 14, 2025
c2031d6
fix: fix some lint issues
Eraxyso Jan 14, 2025
28f85e7
fix: fix some lint issues
Eraxyso Jan 14, 2025
75ae3ba
fix: remove unused uuid import in utils
Eraxyso Jan 14, 2025
2e5510d
fix: fix lint issues
Eraxyso Jan 14, 2025
877cb2e
fix: update ci configuration
Eraxyso Jan 14, 2025
176a19d
fix: fix lint issues
Eraxyso Jan 14, 2025
56ba5a6
fix: configure spectral action
Eraxyso Jan 14, 2025
d635192
fix: fix lint of swagger.yaml
Eraxyso Jan 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- uses: actions/[email protected]
cache: false
- uses: actions/[email protected]
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-gomod-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-gomod-
- run: go mod download
build:
name: Build
Expand All @@ -35,21 +38,22 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- uses: actions/[email protected]
cache: false
- uses: actions/[email protected]
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-gomod-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-gomod-
- uses: actions/cache@v3.3.2
- uses: actions/cache@v4.2.0
with:
path: /tmp/go/cache
key: ${{ runner.os }}-go-build-${{ github.ref }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-go-build-${{ github.ref }}-
${{ runner.os }}-go-build-
- run: go build -o anke-to
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: anke-to
path: anke-to
Expand All @@ -70,26 +74,27 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- uses: actions/[email protected]
cache: false
- uses: actions/[email protected]
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-gomod-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-gomod-
- run: go install github.com/golang/mock/[email protected]
- run: go generate ./...
- run: go test ./model ./router -v -coverprofile=coverage.txt -race -vet=off
- run: go test ./model -v -coverprofile=coverage.txt -race -vet=off # for temporary use as controller test is not ready
# - run: go test ./controller ./model -v -coverprofile=coverage.txt -race -vet=off
env:
MARIADB_USERNAME: root
MARIADB_PASSWORD: password
MARIADB_HOSTNAME: 127.0.0.1
MARIADB_DATABASE: anke-to
- name: Upload coverage data
uses: codecov/codecov-action@v3.1.4
uses: codecov/codecov-action@v5.1.2
with:
file: ./coverage.txt
yml: ./codecov.yml
- uses: actions/upload-artifact@v3
files: ./coverage.txt
- uses: actions/upload-artifact@v4
with:
name: coverage.txt
path: coverage.txt
Expand Down
1 change: 1 addition & 0 deletions .spectral.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extends: ["spectral:oas"]
107 changes: 73 additions & 34 deletions controller/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ func questionnaireInfo2questionnaireSummary(questionnaireInfo model.Questionnair
HasMyDraft: hasMyDraft,
HasMyResponse: hasMyResponse,
IsDuplicateAnswerAllowed: questionnaireInfo.IsDuplicateAnswerAllowed,
// IsAnonymous: questionnaireInfo.IsAnonymous,
IsPublished: questionnaireInfo.IsPublished,
IsTargetingMe: questionnaireInfo.IsTargeted,
ModifiedAt: questionnaireInfo.ModifiedAt,
QuestionnaireId: questionnaireInfo.ID,
Title: questionnaireInfo.Title,
IsAnonymous: questionnaireInfo.IsAnonymous,
IsPublished: questionnaireInfo.IsPublished,
IsTargetingMe: questionnaireInfo.IsTargeted,
ModifiedAt: questionnaireInfo.ModifiedAt,
QuestionnaireId: questionnaireInfo.ID,
Title: questionnaireInfo.Title,
}
if respondedDateTimeByMe.Valid {
res.RespondedDateTimeByMe = &respondedDateTimeByMe.Time
Expand Down Expand Up @@ -81,52 +81,66 @@ func convertOptions(options []model.Options) openapi.QuestionSettingsSingleChoic
return res
}

func convertQuestions(questions []model.Questions) []openapi.Question {
func convertQuestions(questions []model.Questions) ([]openapi.Question, error) {
res := []openapi.Question{}
for _, question := range questions {
q := openapi.Question{
CreatedAt: question.CreatedAt,
// Description: question.Description,
CreatedAt: question.CreatedAt,
Body: question.Body,
IsRequired: question.IsRequired,
QuestionId: question.ID,
QuestionId: &question.ID,
QuestionnaireId: question.QuestionnaireID,
Title: question.Body,
}
switch question.Type {
case "Text":
q.FromQuestionSettingsText(
err := q.FromQuestionSettingsText(
openapi.QuestionSettingsText{
QuestionType: "Text",
},
)
if err != nil {
return nil, err
}
case "TextArea":
q.FromQuestionSettingsText(
err := q.FromQuestionSettingsText(
openapi.QuestionSettingsText{
QuestionType: "TextLong",
},
)
if err != nil {
return nil, err
}
case "Number":
q.FromQuestionSettingsNumber(
err := q.FromQuestionSettingsNumber(
openapi.QuestionSettingsNumber{
QuestionType: "Number",
},
)
if err != nil {
return nil, err
}
case "Radio":
q.FromQuestionSettingsSingleChoice(
err := q.FromQuestionSettingsSingleChoice(
openapi.QuestionSettingsSingleChoice{
QuestionType: "Radio",
Options: convertOptions(question.Options).Options,
},
)
if err != nil {
return nil, err
}
case "MultipleChoice":
q.FromQuestionSettingsMultipleChoice(
err := q.FromQuestionSettingsMultipleChoice(
openapi.QuestionSettingsMultipleChoice{
QuestionType: "MultipleChoice",
Options: convertOptions(question.Options).Options,
},
)
if err != nil {
return nil, err
}
case "LinearScale":
q.FromQuestionSettingsScale(
err := q.FromQuestionSettingsScale(
openapi.QuestionSettingsScale{
QuestionType: "LinearScale",
MinLabel: &question.ScaleLabels[0].ScaleLabelLeft,
Expand All @@ -135,20 +149,27 @@ func convertQuestions(questions []model.Questions) []openapi.Question {
MaxValue: question.ScaleLabels[0].ScaleMax,
},
)
if err != nil {
return nil, err
}
}
}
return res
return res, nil
}

func convertRespondents(respondents []model.Respondents) []string {
res := []string{}
for _, respondent := range respondents {
res = append(res, respondent.UserTraqid)
}
return res
}
// func convertRespondents(respondents []model.Respondents) []string {
// res := []string{}
// for _, respondent := range respondents {
// res = append(res, respondent.UserTraqid)
// }
// return res
// }

func questionnaire2QuestionnaireDetail(questionnaires model.Questionnaires, adminUsers []string, adminGroups []uuid.UUID, targetUsers []string, targetGroups []uuid.UUID, respondents []string) openapi.QuestionnaireDetail {
func questionnaire2QuestionnaireDetail(questionnaires model.Questionnaires, adminUsers []string, adminGroups []uuid.UUID, targetUsers []string, targetGroups []uuid.UUID, respondents []string) (openapi.QuestionnaireDetail, error) {
questions, err := convertQuestions(questionnaires.Questions)
if err != nil {
return openapi.QuestionnaireDetail{}, err
}
res := openapi.QuestionnaireDetail{
Admins: createUsersAndGroups(adminUsers, adminGroups),
CreatedAt: questionnaires.CreatedAt,
Expand All @@ -158,14 +179,14 @@ func questionnaire2QuestionnaireDetail(questionnaires model.Questionnaires, admi
IsPublished: questionnaires.IsPublished,
ModifiedAt: questionnaires.ModifiedAt,
QuestionnaireId: questionnaires.ID,
Questions: convertQuestions(questionnaires.Questions),
Questions: questions,
Respondents: respondents,
ResponseDueDateTime: &questionnaires.ResTimeLimit.Time,
ResponseViewableBy: convertResSharedTo(questionnaires.ResSharedTo),
Targets: createUsersAndGroups(targetUsers, targetGroups),
Title: questionnaires.Title,
}
return res
return res, nil
}

func respondentDetail2Response(ctx echo.Context, respondentDetail model.RespondentDetail) (openapi.Response, error) {
Expand All @@ -175,21 +196,27 @@ func respondentDetail2Response(ctx echo.Context, respondentDetail model.Responde
switch r.QuestionType {
case "Text":
if r.Body.Valid {
oResponseBody.FromResponseBodyText(
err := oResponseBody.FromResponseBodyText(
openapi.ResponseBodyText{
Answer: r.Body.String,
QuestionType: "Text",
},
)
if err != nil {
return openapi.Response{}, err
}
}
case "TextArea":
if r.Body.Valid {
oResponseBody.FromResponseBodyText(
err := oResponseBody.FromResponseBodyText(
openapi.ResponseBodyText{
Answer: r.Body.String,
QuestionType: "TextLong",
},
)
if err != nil {
return openapi.Response{}, err
}
}
case "Number":
if r.Body.Valid {
Expand All @@ -198,12 +225,15 @@ func respondentDetail2Response(ctx echo.Context, respondentDetail model.Responde
ctx.Logger().Errorf("failed to convert string to float: %+v", err)
return openapi.Response{}, err
}
oResponseBody.FromResponseBodyNumber(
err = oResponseBody.FromResponseBodyNumber(
openapi.ResponseBodyNumber{
Answer: float32(answer),
QuestionType: "Number",
},
)
if err != nil {
return openapi.Response{}, err
}
}
case "MultipleChoice":
if r.Body.Valid {
Expand All @@ -220,12 +250,15 @@ func respondentDetail2Response(ctx echo.Context, respondentDetail model.Responde
}
}
}
oResponseBody.FromResponseBodyMultipleChoice(
err = oResponseBody.FromResponseBodyMultipleChoice(
openapi.ResponseBodyMultipleChoice{
Answer: answer,
QuestionType: "MultipleChoice",
},
)
if err != nil {
return openapi.Response{}, err
}
}
case "Checkbox":
if r.Body.Valid {
Expand All @@ -237,12 +270,15 @@ func respondentDetail2Response(ctx echo.Context, respondentDetail model.Responde
for _, a := range r.OptionResponse {
for i, o := range questionnaire.Questions[j].Options {
if a == o.Body {
oResponseBody.FromResponseBodySingleChoice(
err := oResponseBody.FromResponseBodySingleChoice(
openapi.ResponseBodySingleChoice{
Answer: i,
QuestionType: "SingleChoice",
},
)
if err != nil {
return openapi.Response{}, err
}
}
}
}
Expand All @@ -254,12 +290,15 @@ func respondentDetail2Response(ctx echo.Context, respondentDetail model.Responde
ctx.Logger().Errorf("failed to convert string to int: %+v", err)
return openapi.Response{}, err
}
oResponseBody.FromResponseBodyScale(
err = oResponseBody.FromResponseBodyScale(
openapi.ResponseBodyScale{
Answer: answer,
QuestionType: "LinearScale",
},
)
if err != nil {
return openapi.Response{}, err
}
}
}
oResponseBodies = append(oResponseBodies, oResponseBody)
Expand Down
Loading
Loading