Skip to content

Commit

Permalink
refactor: TeamsList dto
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandrMatsko committed Nov 20, 2024
1 parent a82ef93 commit 418e731
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 45 deletions.
12 changes: 6 additions & 6 deletions api/controller/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ func SearchTeams(dataBase moira.Database, page, size int64, textRegexp *regexp.R
if page < 0 || (page > 0 && size < 0) {
return dto.TeamsList{
List: []dto.TeamModel{},
Page: &page,
Size: &size,
Total: &total,
Page: page,
Size: size,
Total: total,
}, nil
}

Expand All @@ -135,9 +135,9 @@ func SearchTeams(dataBase moira.Database, page, size int64, textRegexp *regexp.R
}

model := dto.NewTeamsList(teams)
model.Page = &page
model.Size = &size
model.Total = &total
model.Page = page
model.Size = size
model.Total = total

return model, nil
}
Expand Down
66 changes: 33 additions & 33 deletions api/controller/team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ func TestSearchTeams(t *testing.T) {
So(err, ShouldBeNil)
So(response, ShouldResemble, dto.TeamsList{
List: []dto.TeamModel{},
Page: &page,
Size: &allTeamsSize,
Total: &total,
Page: page,
Size: allTeamsSize,
Total: total,
})
})

Expand All @@ -270,9 +270,9 @@ func TestSearchTeams(t *testing.T) {
So(err, ShouldBeNil)
So(response, ShouldResemble, dto.TeamsList{
List: []dto.TeamModel{},
Page: &page,
Size: &allTeamsSize,
Total: &total,
Page: page,
Size: allTeamsSize,
Total: total,
})
})

Expand All @@ -296,9 +296,9 @@ func TestSearchTeams(t *testing.T) {
So(err, ShouldBeNil)
So(response, ShouldResemble, dto.TeamsList{
List: teamModels,
Page: &firstPage,
Size: &allTeamsSize,
Total: &total,
Page: firstPage,
Size: allTeamsSize,
Total: total,
})
})

Expand All @@ -317,9 +317,9 @@ func TestSearchTeams(t *testing.T) {
So(err, ShouldBeNil)
So(response, ShouldResemble, dto.TeamsList{
List: teamModels[:size],
Page: &page0,
Size: &size,
Total: &total,
Page: page0,
Size: size,
Total: total,
})

dataBase.EXPECT().GetAllTeams().Return(teams, nil)
Expand All @@ -328,9 +328,9 @@ func TestSearchTeams(t *testing.T) {
So(err, ShouldBeNil)
So(response, ShouldResemble, dto.TeamsList{
List: teamModels[page1*size : page1*size+size],
Page: &page1,
Size: &size,
Total: &total,
Page: page1,
Size: size,
Total: total,
})
})

Expand All @@ -347,9 +347,9 @@ func TestSearchTeams(t *testing.T) {
So(err, ShouldBeNil)
So(response, ShouldResemble, dto.TeamsList{
List: teamModels[page*size:],
Page: &page,
Size: &size,
Total: &total,
Page: page,
Size: size,
Total: total,
})
})

Expand All @@ -366,9 +366,9 @@ func TestSearchTeams(t *testing.T) {
So(err, ShouldBeNil)
So(response, ShouldResemble, dto.TeamsList{
List: []dto.TeamModel{},
Page: &page,
Size: &size,
Total: &total,
Page: page,
Size: size,
Total: total,
})
})
})
Expand All @@ -382,9 +382,9 @@ func TestSearchTeams(t *testing.T) {
So(err, ShouldBeNil)
So(response, ShouldResemble, dto.TeamsList{
List: teamModels[3:],
Page: &firstPage,
Size: &allTeamsSize,
Total: &total,
Page: firstPage,
Size: allTeamsSize,
Total: total,
})
})

Expand All @@ -405,9 +405,9 @@ func TestSearchTeams(t *testing.T) {
teamModels[5],
teamModels[2],
},
Page: &firstPage,
Size: &allTeamsSize,
Total: &total,
Page: firstPage,
Size: allTeamsSize,
Total: total,
})
})

Expand All @@ -427,9 +427,9 @@ func TestSearchTeams(t *testing.T) {
teamModels[0],
teamModels[4],
},
Page: &firstPage,
Size: &allTeamsSize,
Total: &total,
Page: firstPage,
Size: allTeamsSize,
Total: total,
})
})
})
Expand All @@ -450,9 +450,9 @@ func TestSearchTeams(t *testing.T) {
teamModels[3],
teamModels[4],
},
Page: &page,
Size: &size,
Total: &total,
Page: page,
Size: size,
Total: total,
})
})
})
Expand Down
6 changes: 3 additions & 3 deletions api/dto/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ func (TeamSettings) Render(w http.ResponseWriter, r *http.Request) error {
// TeamsList is a structure that represents a list of existing teams in db.
type TeamsList struct {
List []TeamModel `json:"list"`
Page *int64 `json:"page,omitempty" format:"int64" extensions:"x-nullable"`
Size *int64 `json:"size,omitempty" format:"int64" extensions:"x-nullable"`
Total *int64 `json:"total,omitempty" format:"int64" extensions:"x-nullable"`
Page int64 `json:"page" example:"0" format:"int64"`
Size int64 `json:"size" example:"100" format:"int64"`
Total int64 `json:"total" example:"10" format:"int64"`
}

// Render is a function that implements chi Renderer interface for TeamsList.
Expand Down
6 changes: 3 additions & 3 deletions api/handler/team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ func Test_searchTeams(t *testing.T) {
total := int64(len(testTeams))

expectedDTO := dto.NewTeamsList(testTeams)
expectedDTO.Page = &defaultTestPage
expectedDTO.Size = &defaultTestSize
expectedDTO.Total = &total
expectedDTO.Page = defaultTestPage
expectedDTO.Size = defaultTestSize
expectedDTO.Total = total

searchTeams(responseWriter, testRequest)

Expand Down

0 comments on commit 418e731

Please sign in to comment.