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 39 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
39 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
400039d
fix: standardize parameter naming in model questionnaires
Eraxyso Jan 18, 2025
f7e2f7f
fix: add error check for calcHMACSHA1
Eraxyso Jan 20, 2025
7db77ba
fix: delete unused variables, parameters and schemas
Eraxyso Jan 20, 2025
de91f69
fix: add missing parameters to BeforeCreate and BeforeUpdate methods
Eraxyso Jan 20, 2025
81fe2bd
feat: update database schema and openapi for targets and admins
Eraxyso Jan 23, 2025
5a052c5
fix: fix some problems in openapi model
Eraxyso Jan 23, 2025
917692a
fix: change Groups type to use UUID format in openapi
Eraxyso Jan 23, 2025
6c52083
feat: change the type of groupid to uuid, and implement users and gro…
Eraxyso Jan 24, 2025
d525495
fix: add model.IRespondent for controller.Questionnaire
Eraxyso Jan 24, 2025
6f34a96
fix: prevent update of targets(admins) when target(admin) users and g…
Eraxyso Jan 24, 2025
dd2a645
feat: update db setting and migration
Eraxyso Jan 27, 2025
b94fa2d
feat: add tests for model administrator users&groups and target users…
Eraxyso Jan 30, 2025
f273cff
fix: format model targetUsers
Eraxyso Jan 30, 2025
8844000
fix: correct some testcase description in model quesitonnaires test
Eraxyso Jan 30, 2025
9fa0f25
Merge pull request #1290 from traPtitech/fix/openapi-target_group
Eraxyso Feb 3, 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"]
111 changes: 72 additions & 39 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 @@ -68,7 +68,7 @@ func convertResSharedTo(resSharedTo string) openapi.ResShareType {
func createUsersAndGroups(users []string, groups uuid.UUIDs) openapi.UsersAndGroups {
res := openapi.UsersAndGroups{
Users: users,
Groups: groups.Strings(),
Groups: groups,
}
return res
}
Expand All @@ -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,37 +149,38 @@ 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)
func questionnaire2QuestionnaireDetail(questionnaires model.Questionnaires, admins []string, adminUsers []string, adminGroups []uuid.UUID, targets []string, targetUsers []string, targetGroups []uuid.UUID, respondents []string) (openapi.QuestionnaireDetail, error) {
questions, err := convertQuestions(questionnaires.Questions)
if err != nil {
return openapi.QuestionnaireDetail{}, err
}
return res
}

func questionnaire2QuestionnaireDetail(questionnaires model.Questionnaires, adminUsers []string, adminGroups []uuid.UUID, targetUsers []string, targetGroups []uuid.UUID, respondents []string) openapi.QuestionnaireDetail {
res := openapi.QuestionnaireDetail{
Admins: createUsersAndGroups(adminUsers, adminGroups),
Admin: createUsersAndGroups(adminUsers, adminGroups),
Admins: admins,
CreatedAt: questionnaires.CreatedAt,
Description: questionnaires.Description,
IsDuplicateAnswerAllowed: questionnaires.IsDuplicateAnswerAllowed,
IsAnonymous: questionnaires.IsAnonymous,
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),
Target: createUsersAndGroups(targetUsers, targetGroups),
Targets: targets,
Title: questionnaires.Title,
}
return res
return res, nil
}

func respondentDetail2Response(ctx echo.Context, respondentDetail model.RespondentDetail) (openapi.Response, error) {
Expand All @@ -175,21 +190,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,17 +219,20 @@ 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 {
answer := []int{}
questionnaire, _, _, _, _, _, err := model.NewQuestionnaire().GetQuestionnaireInfo(ctx.Request().Context(), r.QuestionID)
questionnaire, _, _, _, _, _, _, _, err := model.NewQuestionnaire().GetQuestionnaireInfo(ctx.Request().Context(), r.QuestionID)
if err != nil {
ctx.Logger().Errorf("failed to get questionnaire info: %+v", err)
return openapi.Response{}, err
Expand All @@ -220,29 +244,35 @@ 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 {
questionnaire, _, _, _, _, _, err := model.NewQuestionnaire().GetQuestionnaireInfo(ctx.Request().Context(), r.QuestionID)
questionnaire, _, _, _, _, _, _, _, err := model.NewQuestionnaire().GetQuestionnaireInfo(ctx.Request().Context(), r.QuestionID)
if err != nil {
ctx.Logger().Errorf("failed to get questionnaire info: %+v", err)
return openapi.Response{}, err
}
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 +284,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