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

fix: fix the mismatch of parameters between the interface and implementation of GetMyResponseIDs #1287

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 10 additions & 5 deletions model/respondents_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,18 +396,23 @@ func (*Respondent) GetRespondentsUserIDs(ctx context.Context, questionnaireIDs [
}

// GetMyResponses 自分のすべての回答を取得
func (*Respondent) GetMyResponseIDs(ctx context.Context, userID string) ([]int, error) {
func (*Respondent) GetMyResponseIDs(ctx context.Context, sort string, userID string) ([]int, error) {
db, err := getTx(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get transaction: %w", err)
}

responsesID := []int{}
err = db.
Model(&Respondents{}).
query := db.Model(&Respondents{}).
Where("user_traqid = ?", userID).
Select("response_id").
Find(&responsesID).Error
Select("response_id")

query, _, err = setRespondentsOrder(query, sort)
if err != nil {
return nil, fmt.Errorf("failed to set respondents order: %w", err)
}

err = query.Find(&responsesID).Error
if err != nil {
return nil, fmt.Errorf("failed to get responsesID: %w", err)
}
Expand Down
6 changes: 5 additions & 1 deletion model/respondents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,7 @@ func TestGetMyResponseIDs(t *testing.T) {
}

type args struct {
sort string
userID string
}
type expect struct {
Expand All @@ -1042,6 +1043,7 @@ func TestGetMyResponseIDs(t *testing.T) {
{
description: "valid user with one resonse",
args: args{
sort: "submitted_at",
userID: userOne,
},
expect: expect{
Expand All @@ -1051,6 +1053,7 @@ func TestGetMyResponseIDs(t *testing.T) {
{
description: "valid user with multiple responses",
args: args{
sort: "submitted_at",
userID: userTwo,
},
expect: expect{
Expand All @@ -1060,6 +1063,7 @@ func TestGetMyResponseIDs(t *testing.T) {
{
description: "valid user with no response",
args: args{
sort: "submitted_at",
userID: userThree,
},
expect: expect{
Expand All @@ -1069,7 +1073,7 @@ func TestGetMyResponseIDs(t *testing.T) {
}

for _, testCase := range testCases {
MyResponseIDs, err := respondentImpl.GetMyResponseIDs(ctx, testCase.args.userID)
MyResponseIDs, err := respondentImpl.GetMyResponseIDs(ctx, testCase.args.sort, testCase.args.userID)

if !testCase.expect.isErr {
assertion.NoError(err, testCase.description, "no error")
Expand Down
Loading