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 17 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
22 changes: 18 additions & 4 deletions docs/swagger/traPortfolio.v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1148,10 +1148,10 @@ components:
- link
- description
- teams
ContestTeam:
title: ContestTeam
ContestTeamWithoutMembers:
title: ContestTeamWithoutMembers
type: object
description: コンテストチーム情報
description: コンテストチーム情報(チームメンバーなし)
properties:
id:
type: string
Expand All @@ -1168,6 +1168,21 @@ components:
- id
- name
- result
ContestTeam:
title: ContestTeam
type: object
description: コンテストチーム情報
allOf:
- $ref: "#/components/schemas/ContestTeamWithoutMembers"
- type: object
properties:
members:
type: array
description: チームメンバーのユーザー情報
items:
$ref: '#/components/schemas/User'
required:
- members
ContestTeamDetail:
title: ContestTeamDetail
type: object
Expand All @@ -1191,7 +1206,6 @@ components:
required:
- link
- description
- members
PrPermitted:
title: PrPermitted
type: boolean
Expand Down
8 changes: 6 additions & 2 deletions domain/contest.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,20 @@ type ContestDetail struct {
ContestTeams []*ContestTeam
}

type ContestTeam struct {
type ContestTeamWithoutMembers struct {
ID uuid.UUID
ContestID uuid.UUID
Name string
Result string
}

type ContestTeam struct {
ContestTeamWithoutMembers
Members []*User
}

type ContestTeamDetail struct {
ContestTeam
Link string
Description string
Members []*User
}
2 changes: 1 addition & 1 deletion domain/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type UserContest struct {
Name string // コンテスト名
TimeStart time.Time
TimeEnd time.Time
Teams []*ContestTeam // ユーザーが所属するチームのリスト
Teams []*ContestTeamWithoutMembers // ユーザーが所属するチームのリスト
}

type UserGroup struct {
Expand Down
11 changes: 8 additions & 3 deletions integration_tests/repository/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,12 +543,17 @@ func TestUserRepository_GetContests(t *testing.T) {
mustAddContestTeamMembers(t, contestRepo, team1.ID, []uuid.UUID{user1.ID, user2.ID})
mustAddContestTeamMembers(t, contestRepo, team2.ID, []uuid.UUID{user1.ID})

expected1 := []*domain.UserContest{newUserContest(&contest1.Contest, []*domain.ContestTeam{&team1.ContestTeam}), newUserContest(&contest2.Contest, []*domain.ContestTeam{&team2.ContestTeam})}
expected1 := []*domain.UserContest{
newUserContest(&contest1.Contest, []*domain.ContestTeamWithoutMembers{&team1.ContestTeam.ContestTeamWithoutMembers}),
newUserContest(&contest2.Contest, []*domain.ContestTeamWithoutMembers{&team2.ContestTeam.ContestTeamWithoutMembers}),
}
contests1, err := userRepo.GetContests(context.Background(), user1.ID)
assert.NoError(t, err)
assert.ElementsMatch(t, expected1, contests1)

expected2 := []*domain.UserContest{newUserContest(&contest1.Contest, []*domain.ContestTeam{&team1.ContestTeam})}
expected2 := []*domain.UserContest{
newUserContest(&contest1.Contest, []*domain.ContestTeamWithoutMembers{&team1.ContestTeam.ContestTeamWithoutMembers}),
}
contests2, err := userRepo.GetContests(context.Background(), user2.ID)
assert.NoError(t, err)
assert.ElementsMatch(t, expected2, contests2)
Expand All @@ -575,7 +580,7 @@ func newUserProject(args *urepository.CreateProjectMemberArgs, project *domain.P
}
}

func newUserContest(contest *domain.Contest, teams []*domain.ContestTeam) *domain.UserContest {
func newUserContest(contest *domain.Contest, teams []*domain.ContestTeamWithoutMembers) *domain.UserContest {
return &domain.UserContest{
ID: contest.ID,
Name: contest.Name,
Expand Down
34 changes: 25 additions & 9 deletions interfaces/handler/contest.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ func (h *ContestHandler) GetContest(_c echo.Context) error {

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())
}
teams[i] = newContestTeam(v.ID, v.Name, v.Result, members)
}

res := newContestDetail(
Expand Down Expand Up @@ -96,7 +100,7 @@ func (h *ContestHandler) CreateContest(_c echo.Context) error {

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{}))
}
res := newContestDetail(newContest(contest.ID, contest.Name, contest.TimeStart, contest.TimeEnd), contest.Link, contest.Description, contestTeams)

Expand Down Expand Up @@ -170,7 +174,11 @@ func (h *ContestHandler) GetContestTeams(_c echo.Context) error {

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())
}
res[i] = newContestTeam(v.ID, v.Name, v.Result, members)
}

return c.JSON(http.StatusOK, res)
Expand Down Expand Up @@ -202,10 +210,9 @@ func (h *ContestHandler) GetContestTeam(_c echo.Context) error {
}

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 @@ func (h *ContestHandler) AddContestTeam(_c echo.Context) error {
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,29 @@ func newContestDetail(contest Contest, link string, description string, teams []
}
}

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,
Members: members,
}
}

func newContestTeamWithoutMembers(id uuid.UUID, name string, result string) ContestTeamWithoutMembers {
return ContestTeamWithoutMembers{
Id: id,
Name: name,
Result: result,
}
}

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
102 changes: 61 additions & 41 deletions interfaces/handler/contest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,26 +123,33 @@ func makeContest(t *testing.T) (*domain.ContestDetail, *ContestDetail) {
Description: random.AlphaNumeric(),
ContestTeams: []*domain.ContestTeam{
{
ID: getContestID[1],
ContestID: getContestID[0],
Name: random.AlphaNumeric(),
Result: random.AlphaNumeric(),
ContestTeamWithoutMembers: domain.ContestTeamWithoutMembers{
ID: getContestID[1],
ContestID: getContestID[0],
Name: random.AlphaNumeric(),
Result: random.AlphaNumeric(),
},
Members: make([]*domain.User, 0),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここメンバー1つでもいいので入れ他方がよさそう

},
{
ID: getContestID[2],
ContestID: getContestID[0],
Name: random.AlphaNumeric(),
Result: random.AlphaNumeric(),
ContestTeamWithoutMembers: domain.ContestTeamWithoutMembers{
ID: getContestID[2],
ContestID: getContestID[0],
Name: random.AlphaNumeric(),
Result: random.AlphaNumeric(),
},
Members: make([]*domain.User, 0),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここも

},
},
}

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 @@ -506,28 +513,36 @@ func TestContestHandler_GetContestTeams(t *testing.T) {
contestID := random.UUID()
repoContestTeams := []*domain.ContestTeam{
{
ID: random.UUID(),
ContestID: contestID,
Name: random.AlphaNumeric(),
Result: random.AlphaNumeric(),
ContestTeamWithoutMembers: domain.ContestTeamWithoutMembers{
ID: random.UUID(),
ContestID: contestID,
Name: random.AlphaNumeric(),
Result: random.AlphaNumeric(),
},
Members: make([]*domain.User, 0),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここらへんも

},
{
ID: random.UUID(),
ContestID: contestID,
Name: random.AlphaNumeric(),
Result: random.AlphaNumeric(),
ContestTeamWithoutMembers: domain.ContestTeamWithoutMembers{
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 @@ -575,17 +590,19 @@ func TestContestHandler_GetContestTeam(t *testing.T) {
contestID := random.UUID()
repoContestTeamDetail := domain.ContestTeamDetail{
ContestTeam: domain.ContestTeam{
ID: teamID,
ContestID: contestID,
Name: random.AlphaNumeric(),
Result: random.AlphaNumeric(),
ContestTeamWithoutMembers: domain.ContestTeamWithoutMembers{
ID: teamID,
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 @@ -679,19 +696,22 @@ func TestContestHandler_AddContestTeam(t *testing.T) {
}
want := domain.ContestTeamDetail{
ContestTeam: domain.ContestTeam{
ID: teamID,
ContestID: contestID,
Name: args.Name,
Result: args.Result.ValueOrZero(),
ContestTeamWithoutMembers: domain.ContestTeamWithoutMembers{
ID: teamID,
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
Loading