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

TeamDetail.MembersをTeamに移した #484

Merged
merged 31 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
876769e
TeamDetail.MembersをTeamに移した
0214sh7 Mar 7, 2023
171a9c0
Membersの箇所を修正
0214sh7 Mar 7, 2023
b637650
メンバーが空になるケースでの処理を変更
0214sh7 Mar 7, 2023
916b896
Merge branch 'main' of https://github.com/traPtitech/traPortfolio int…
0214sh7 Mar 21, 2023
8704e2e
単体/結合テストにおいてmembersがnilになっている箇所を修正
0214sh7 Mar 21, 2023
e86e891
rcontest.Teams[0].Membersが空であることを明示
0214sh7 Mar 21, 2023
484ed10
Merge branch 'main' of https://github.com/traPtitech/traPortfolio int…
0214sh7 Apr 4, 2023
26314d6
mockのユーザー情報をMembersに入れる
0214sh7 Apr 11, 2023
5d9eccd
HMockContestTeamMembersByIDを作成
0214sh7 Apr 11, 2023
6129f5d
HMockContestTeamMembersByIDを使ったID指定を残りの箇所にも反映
0214sh7 Apr 11, 2023
dfd2fdd
Merge branch 'main' of https://github.com/traPtitech/traPortfolio int…
0214sh7 Apr 25, 2023
4f6f677
mapがnilを返すときの場合分け
0214sh7 May 16, 2023
816841a
Merge branch 'main' of https://github.com/traPtitech/traPortfolio int…
0214sh7 Jun 27, 2023
8ee9ed2
ContestTeamWithoutMembersを追加しUserContestのメンバを変更
0214sh7 Jul 20, 2023
ecb1f28
軽微な修正
0214sh7 Jul 27, 2023
fa9bcf9
軽微な修正2
0214sh7 Jul 27, 2023
8c7785e
コンテストチームにチームメンバーを追加する処理(N+1)を追加
0214sh7 Aug 17, 2023
ff53b01
Merge branch 'main' of https://github.com/traPtitech/traPortfolio int…
0214sh7 Aug 20, 2023
686d30f
マージに伴う変更
0214sh7 Aug 20, 2023
1037bb7
domain.NewUserを使用/nilを空スライスに変更
0214sh7 Aug 20, 2023
2ab1502
N+1解消(テスト落ちる)
0214sh7 Sep 26, 2023
5e42353
go mod tidyした
0214sh7 Oct 5, 2023
e056822
handlerの一部を変更
0214sh7 Oct 5, 2023
28f5ada
fix unittest
0214sh7 Oct 26, 2023
b3440f6
pass all unittest
0214sh7 Oct 26, 2023
7b63f24
Merge branch 'main' of https://github.com/traPtitech/traPortfolio int…
0214sh7 Oct 26, 2023
9870eb6
commit with merge
0214sh7 Oct 26, 2023
849ccce
revert some change
0214sh7 Oct 26, 2023
746e6e3
add members to contestteam
0214sh7 Oct 26, 2023
bee01d2
add members to contestteam 2
0214sh7 Oct 26, 2023
498a2e7
remove contestteam from new contest
0214sh7 Oct 26, 2023
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
7 changes: 6 additions & 1 deletion docs/swagger/traPortfolio.v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1164,10 +1164,16 @@ components:
result:
type: string
description: 順位などの結果
members:
type: array
description: チームメンバーのUUID
0214sh7 marked this conversation as resolved.
Show resolved Hide resolved
items:
$ref: '#/components/schemas/User'
required:
- id
- name
- result
- members
ContestTeamDetail:
title: ContestTeamDetail
type: object
Expand All @@ -1191,7 +1197,6 @@ components:
required:
- link
- description
- members
PrPermitted:
title: PrPermitted
type: boolean
Expand Down
2 changes: 1 addition & 1 deletion domain/contest.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ type ContestTeam struct {
ContestID uuid.UUID
Name string
Result string
Members []*User
}

type ContestTeamDetail struct {
ContestTeam
Link string
Description string
Members []*User
}
32 changes: 20 additions & 12 deletions interfaces/handler/contest.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@

teams := make([]ContestTeam, len(contest.ContestTeams))
for i, v := range contest.ContestTeams {
teams[i] = newContestTeam(v.ID, v.Name, v.Result)
members := make([]User, len(v.Members))
for j, ct := range v.Members {
members[j] = newUser(ct.ID, ct.Name, ct.RealName())
}

Check warning on line 64 in interfaces/handler/contest.go

View check run for this annotation

Codecov / codecov/patch

interfaces/handler/contest.go#L63-L64

Added lines #L63 - L64 were not covered by tests
teams[i] = newContestTeam(v.ID, v.Name, v.Result, members)
}

res := newContestDetail(
Expand Down Expand Up @@ -96,7 +100,7 @@

contestTeams := make([]ContestTeam, 0, len(contest.ContestTeams))
for _, team := range contest.ContestTeams {
contestTeams = append(contestTeams, newContestTeam(team.ID, team.Name, team.Result))
contestTeams = append(contestTeams, newContestTeam(team.ID, team.Name, team.Result, []User{}))

Check warning on line 103 in interfaces/handler/contest.go

View check run for this annotation

Codecov / codecov/patch

interfaces/handler/contest.go#L103

Added line #L103 was not covered by tests
}
res := newContestDetail(newContest(contest.ID, contest.Name, contest.TimeStart, contest.TimeEnd), contest.Link, contest.Description, contestTeams)

Expand Down Expand Up @@ -170,7 +174,11 @@

res := make([]ContestTeam, len(contestTeams))
for i, v := range contestTeams {
res[i] = newContestTeam(v.ID, v.Name, v.Result)
members := make([]User, len(v.Members))
for j, ct := range v.Members {
members[j] = newUser(ct.ID, ct.Name, ct.RealName())
}

Check warning on line 180 in interfaces/handler/contest.go

View check run for this annotation

Codecov / codecov/patch

interfaces/handler/contest.go#L179-L180

Added lines #L179 - L180 were not covered by tests
res[i] = newContestTeam(v.ID, v.Name, v.Result, members)
}

return c.JSON(http.StatusOK, res)
Expand Down Expand Up @@ -202,10 +210,9 @@
}

res := newContestTeamDetail(
newContestTeam(contestTeam.ID, contestTeam.Name, contestTeam.Result),
newContestTeam(contestTeam.ID, contestTeam.Name, contestTeam.Result, members),
contestTeam.Link,
contestTeam.Description,
members,
)

return c.JSON(http.StatusOK, res)
Expand Down Expand Up @@ -238,7 +245,7 @@
return convertError(err)
}

res := newContestTeam(contestTeam.ID, contestTeam.Name, contestTeam.Result)
res := newContestTeam(contestTeam.ID, contestTeam.Name, contestTeam.Result, []User{})

return c.JSON(http.StatusCreated, res)
}
Expand Down Expand Up @@ -408,20 +415,21 @@
}
}

func newContestTeam(id uuid.UUID, name string, result string) ContestTeam {
func newContestTeam(id uuid.UUID, name string, result string, members []User) ContestTeam {
return ContestTeam{
Id: id,
Name: name,
Result: result,
Id: id,
Name: name,
Result: result,
Members: members,
}
}

func newContestTeamDetail(team ContestTeam, link string, description string, members []User) ContestTeamDetail {
func newContestTeamDetail(team ContestTeam, link string, description string) ContestTeamDetail {
return ContestTeamDetail{
Description: description,
Id: team.Id,
Link: link,
Members: members,
Members: team.Members,
Name: team.Name,
Result: team.Result,
}
Expand Down
42 changes: 25 additions & 17 deletions interfaces/handler/contest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,25 @@ func makeContest(t *testing.T) (*domain.ContestDetail, *ContestDetail) {
ContestID: getContestID[0],
Name: random.AlphaNumeric(),
Result: random.AlphaNumeric(),
Members: make([]*domain.User, 0),
},
{
ID: getContestID[2],
ContestID: getContestID[0],
Name: random.AlphaNumeric(),
Result: random.AlphaNumeric(),
Members: make([]*domain.User, 0),
},
},
}

teams := make([]ContestTeam, len(d.ContestTeams))
for i, v := range d.ContestTeams {
teams[i] = ContestTeam{
Id: v.ID,
Name: v.Name,
Result: v.Result,
Id: v.ID,
Members: make([]User, 0),
Name: v.Name,
Result: v.Result,
}
}

Expand Down Expand Up @@ -510,24 +513,28 @@ func TestContestHandler_GetContestTeams(t *testing.T) {
ContestID: contestID,
Name: random.AlphaNumeric(),
Result: random.AlphaNumeric(),
Members: make([]*domain.User, 0),
},
{
ID: random.UUID(),
ContestID: contestID,
Name: random.AlphaNumeric(),
Result: random.AlphaNumeric(),
Members: make([]*domain.User, 0),
},
}
hres = []*ContestTeam{
{
Id: repoContestTeams[0].ID,
Name: repoContestTeams[0].Name,
Result: repoContestTeams[0].Result,
Id: repoContestTeams[0].ID,
Members: make([]User, 0),
Name: repoContestTeams[0].Name,
Result: repoContestTeams[0].Result,
},
{
Id: repoContestTeams[1].ID,
Name: repoContestTeams[1].Name,
Result: repoContestTeams[1].Result,
Id: repoContestTeams[1].ID,
Members: make([]User, 0),
Name: repoContestTeams[1].Name,
Result: repoContestTeams[1].Result,
},
}
s.EXPECT().GetContestTeams(anyCtx{}, contestID).Return(repoContestTeams, nil)
Expand Down Expand Up @@ -579,13 +586,13 @@ func TestContestHandler_GetContestTeam(t *testing.T) {
ContestID: contestID,
Name: random.AlphaNumeric(),
Result: random.AlphaNumeric(),
Members: []*domain.User{
domain.NewUser(random.UUID(), random.AlphaNumeric(), random.AlphaNumeric(), random.Bool()),
domain.NewUser(random.UUID(), random.AlphaNumeric(), random.AlphaNumeric(), random.Bool()),
},
},
Link: random.AlphaNumeric(),
Description: random.AlphaNumeric(),
Members: []*domain.User{
domain.NewUser(random.UUID(), random.AlphaNumeric(), random.AlphaNumeric(), random.Bool()),
domain.NewUser(random.UUID(), random.AlphaNumeric(), random.AlphaNumeric(), random.Bool()),
},
}
members := make([]User, 0, len(repoContestTeamDetail.Members))
for _, member := range repoContestTeamDetail.Members {
Expand Down Expand Up @@ -683,15 +690,16 @@ func TestContestHandler_AddContestTeam(t *testing.T) {
ContestID: contestID,
Name: args.Name,
Result: args.Result.ValueOrZero(),
Members: make([]*domain.User, 0),
},
Link: args.Link.ValueOrZero(),
Description: args.Description,
Members: nil,
}
expectedResBody := ContestTeam{
Id: teamID,
Name: want.Name,
Result: want.Result,
Id: teamID,
Members: make([]User, 0),
Name: want.Name,
Result: want.Result,
}
s.EXPECT().CreateContestTeam(anyCtx{}, contestID, &args).Return(&want, nil)
return reqBody, expectedResBody, fmt.Sprintf("/api/v1/contests/%s/teams", contestID)
Expand Down
3 changes: 3 additions & 0 deletions interfaces/handler/oapi_types_gen.go

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

6 changes: 5 additions & 1 deletion interfaces/handler/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,11 @@
for i, c := range contests {
teams := make([]ContestTeam, len(c.Teams))
for j, ct := range c.Teams {
teams[j] = newContestTeam(ct.ID, ct.Name, ct.Result)
members := make([]User, len(ct.Members))
for k, ctt := range ct.Members {
members[k] = newUser(ctt.ID, ctt.Name, ctt.RealName())
}

Check warning on line 288 in interfaces/handler/user.go

View check run for this annotation

Codecov / codecov/patch

interfaces/handler/user.go#L287-L288

Added lines #L287 - L288 were not covered by tests
teams[j] = newContestTeam(ct.ID, ct.Name, ct.Result, members)
}
res[i] = newUserContest(
newContest(c.ID, c.Name, c.TimeStart, c.TimeEnd),
Expand Down
3 changes: 2 additions & 1 deletion interfaces/handler/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1184,14 +1184,15 @@ func TestUserHandler_GetUserContests(t *testing.T) {
ContestID: random.UUID(),
Name: random.AlphaNumeric(),
Result: random.AlphaNumeric(),
Members: make([]*domain.User, 0),
},
},
}

hcontest := newUserContest(
newContest(rcontest.ID, rcontest.Name, rcontest.TimeStart, rcontest.TimeEnd),
[]ContestTeam{
newContestTeam(rcontest.Teams[0].ID, rcontest.Teams[0].Name, rcontest.Teams[0].Result),
newContestTeam(rcontest.Teams[0].ID, rcontest.Teams[0].Name, rcontest.Teams[0].Result, make([]User, 0)),
},
)

Expand Down
2 changes: 1 addition & 1 deletion interfaces/repository/contest_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,10 @@ func (r *ContestRepository) CreateContestTeam(ctx context.Context, contestID uui
ContestID: contestTeam.ContestID,
Name: contestTeam.Name,
Result: contestTeam.Result,
Members: nil,
},
Link: contestTeam.Link,
Description: contestTeam.Description,
Members: nil,
}
return result, nil
}
Expand Down
2 changes: 1 addition & 1 deletion interfaces/repository/contest_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,10 +722,10 @@ func TestContestRepository_CreateContestTeam(t *testing.T) {
ContestID: cid,
Name: successArgs.Name,
Result: successArgs.Result.ValueOrZero(),
Members: nil,
},
Link: successArgs.Link.ValueOrZero(),
Description: successArgs.Description,
Members: nil,
},
setup: func(f mockContestRepositoryFields, args args, want *domain.ContestTeamDetail) {
f.h.Mock.
Expand Down
10 changes: 5 additions & 5 deletions usecases/service/contest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,12 +527,12 @@ func Test_contestService_GetContestTeam(t *testing.T) {
ContestID: cid,
Name: random.AlphaNumeric(),
Result: random.AlphaNumeric(),
Members: []*domain.User{
domain.NewUser(random.UUID(), random.AlphaNumeric(), random.AlphaNumeric(), random.Bool()),
},
},
Link: random.RandURLString(),
Description: random.AlphaNumeric(),
Members: []*domain.User{
domain.NewUser(random.UUID(), random.AlphaNumeric(), random.AlphaNumeric(), random.Bool()),
},
},
setup: func(f fields, args args, want *domain.ContestTeamDetail) {
repo := f.repo.(*mock_repository.MockContestRepository)
Expand Down Expand Up @@ -653,10 +653,10 @@ func TestContestService_CreateContestTeam(t *testing.T) {
ContestID: cid,
Name: name,
Result: result,
Members: nil,
},
Link: link,
Description: description,
Members: nil,
},
setup: func(f fields, args args, want *domain.ContestTeamDetail) {
repo := f.repo.(*mock_repository.MockContestRepository)
Expand All @@ -666,10 +666,10 @@ func TestContestService_CreateContestTeam(t *testing.T) {
ContestID: args.contestID,
Name: args.args.Name,
Result: args.args.Result.ValueOrZero(),
Members: nil,
},
Link: args.args.Link.ValueOrZero(),
Description: args.args.Description,
Members: nil,
}, nil)
},
assertion: assert.NoError,
Expand Down
21 changes: 12 additions & 9 deletions util/mockdata/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ func CloneHandlerMockContestDetails() []handler.ContestDetail {

for i, c := range hContestTeams {
mContestTeams[i] = handler.ContestTeam{
Id: c.ID,
Name: c.Name,
Result: c.Result,
Id: c.ID,
Members: make([]handler.User, 0),
ras0q marked this conversation as resolved.
Show resolved Hide resolved
Name: c.Name,
Result: c.Result,
}
}

Expand Down Expand Up @@ -85,9 +86,10 @@ func CloneHandlerMockContestTeamsByID() map[uuid.UUID][]handler.ContestTeam {

for _, ct := range mContestTeams {
hContestTeamsByID[ct.ContestID] = append(hContestTeamsByID[ct.ContestID], handler.ContestTeam{
Id: ct.ID,
Name: ct.Name,
Result: ct.Result,
Id: ct.ID,
Members: make([]handler.User, 0),
ras0q marked this conversation as resolved.
Show resolved Hide resolved
Name: ct.Name,
Result: ct.Result,
})
}
return hContestTeamsByID
Expand Down Expand Up @@ -418,9 +420,10 @@ func CloneHandlerMockUserContestsByID() map[uuid.UUID][]handler.UserContest {
}

userContestTeams[u.ID][c.Id] = append(userContestTeams[u.ID][c.Id], handler.ContestTeam{
Id: ct.ID,
Name: ct.Name,
Result: ct.Result,
Id: ct.ID,
Members: make([]handler.User, 0),
ras0q marked this conversation as resolved.
Show resolved Hide resolved
Name: ct.Name,
Result: ct.Result,
})
}
}
Expand Down