Skip to content

Commit

Permalink
style: rename "getAllTeams" handler and controller to "searchAllTeams"
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksandrMatsko committed Nov 20, 2024
1 parent 25d3f7b commit 6a4e448
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions api/controller/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ func GetTeam(dataBase moira.Database, teamID string) (dto.TeamModel, *api.ErrorR
return teamModel, nil
}

// GetAllTeams is a controller function that returns all teams.
func GetAllTeams(dataBase moira.Database, page, size int64, textRegexp *regexp.Regexp, sortOrder api.SortOrder) (dto.TeamsList, *api.ErrorResponse) {
// SearchAllTeams is a controller function that returns all teams.
func SearchAllTeams(dataBase moira.Database, page, size int64, textRegexp *regexp.Regexp, sortOrder api.SortOrder) (dto.TeamsList, *api.ErrorResponse) {
teams, err := dataBase.GetAllTeams()
if err != nil {
return dto.TeamsList{}, api.ErrorInternalServer(fmt.Errorf("cannot get teams from database: %w", err))
Expand Down
28 changes: 14 additions & 14 deletions api/controller/team_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ func TestGetTeam(t *testing.T) {
})
}

func TestGetAllTeams(t *testing.T) {
Convey("GetTeamAllTeams", t, func() {
func TestSearchAllTeams(t *testing.T) {
Convey("SearchAllTeams", t, func() {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
dataBase := mock_moira_alert.NewMockDatabase(mockCtrl)
Expand Down Expand Up @@ -247,7 +247,7 @@ func TestGetAllTeams(t *testing.T) {
total = int64(len(teamModels))
)

response, err := GetAllTeams(dataBase, page, allTeamsSize, anyText, api.NoSortOrder)
response, err := SearchAllTeams(dataBase, page, allTeamsSize, anyText, api.NoSortOrder)

So(err, ShouldBeNil)
So(response, ShouldResemble, dto.TeamsList{
Expand All @@ -265,7 +265,7 @@ func TestGetAllTeams(t *testing.T) {
total = int64(len(teamModels))
)

response, err := GetAllTeams(dataBase, page, allTeamsSize, anyText, api.NoSortOrder)
response, err := SearchAllTeams(dataBase, page, allTeamsSize, anyText, api.NoSortOrder)

So(err, ShouldBeNil)
So(response, ShouldResemble, dto.TeamsList{
Expand All @@ -281,7 +281,7 @@ func TestGetAllTeams(t *testing.T) {

dataBase.EXPECT().GetAllTeams().Return(nil, dbErr)

response, err := GetAllTeams(dataBase, firstPage, allTeamsSize, anyText, api.NoSortOrder)
response, err := SearchAllTeams(dataBase, firstPage, allTeamsSize, anyText, api.NoSortOrder)

So(err, ShouldResemble, api.ErrorInternalServer(fmt.Errorf("cannot get teams from database: %w", dbErr)))
So(response, ShouldResemble, dto.TeamsList{})
Expand All @@ -291,7 +291,7 @@ func TestGetAllTeams(t *testing.T) {
dataBase.EXPECT().GetAllTeams().Return(teams, nil)
total := int64(len(teamModels))

response, err := GetAllTeams(dataBase, firstPage, allTeamsSize, anyText, api.NoSortOrder)
response, err := SearchAllTeams(dataBase, firstPage, allTeamsSize, anyText, api.NoSortOrder)

So(err, ShouldBeNil)
So(response, ShouldResemble, dto.TeamsList{
Expand All @@ -313,7 +313,7 @@ func TestGetAllTeams(t *testing.T) {

dataBase.EXPECT().GetAllTeams().Return(teams, nil)

response, err := GetAllTeams(dataBase, page0, size, anyText, api.NoSortOrder)
response, err := SearchAllTeams(dataBase, page0, size, anyText, api.NoSortOrder)
So(err, ShouldBeNil)
So(response, ShouldResemble, dto.TeamsList{
List: teamModels[:size],
Expand All @@ -324,7 +324,7 @@ func TestGetAllTeams(t *testing.T) {

dataBase.EXPECT().GetAllTeams().Return(teams, nil)

response, err = GetAllTeams(dataBase, page1, size, anyText, api.NoSortOrder)
response, err = SearchAllTeams(dataBase, page1, size, anyText, api.NoSortOrder)
So(err, ShouldBeNil)
So(response, ShouldResemble, dto.TeamsList{
List: teamModels[page1*size : page1*size+size],
Expand All @@ -343,7 +343,7 @@ func TestGetAllTeams(t *testing.T) {

dataBase.EXPECT().GetAllTeams().Return(teams, nil)

response, err := GetAllTeams(dataBase, page, size, anyText, api.NoSortOrder)
response, err := SearchAllTeams(dataBase, page, size, anyText, api.NoSortOrder)
So(err, ShouldBeNil)
So(response, ShouldResemble, dto.TeamsList{
List: teamModels[page*size:],
Expand All @@ -362,7 +362,7 @@ func TestGetAllTeams(t *testing.T) {

dataBase.EXPECT().GetAllTeams().Return(teams, nil)

response, err := GetAllTeams(dataBase, page, size, anyText, api.NoSortOrder)
response, err := SearchAllTeams(dataBase, page, size, anyText, api.NoSortOrder)
So(err, ShouldBeNil)
So(response, ShouldResemble, dto.TeamsList{
List: []dto.TeamModel{},
Expand All @@ -378,7 +378,7 @@ func TestGetAllTeams(t *testing.T) {
textRegexp := regexp.MustCompile(".*th-team-id")
total := int64(len(teamModels)) - 3

response, err := GetAllTeams(dataBase, firstPage, allTeamsSize, textRegexp, api.NoSortOrder)
response, err := SearchAllTeams(dataBase, firstPage, allTeamsSize, textRegexp, api.NoSortOrder)
So(err, ShouldBeNil)
So(response, ShouldResemble, dto.TeamsList{
List: teamModels[3:],
Expand All @@ -393,7 +393,7 @@ func TestGetAllTeams(t *testing.T) {
dataBase.EXPECT().GetAllTeams().Return(teams, nil)
total := int64(len(teamModels))

response, err := GetAllTeams(dataBase, firstPage, allTeamsSize, anyText, api.AscSortOrder)
response, err := SearchAllTeams(dataBase, firstPage, allTeamsSize, anyText, api.AscSortOrder)
So(err, ShouldBeNil)
So(response, ShouldResemble, dto.TeamsList{
List: []dto.TeamModel{
Expand All @@ -415,7 +415,7 @@ func TestGetAllTeams(t *testing.T) {
dataBase.EXPECT().GetAllTeams().Return(teams, nil)
total := int64(len(teamModels))

response, err := GetAllTeams(dataBase, firstPage, allTeamsSize, anyText, api.DescSortOrder)
response, err := SearchAllTeams(dataBase, firstPage, allTeamsSize, anyText, api.DescSortOrder)
So(err, ShouldBeNil)
So(response, ShouldResemble, dto.TeamsList{
List: []dto.TeamModel{
Expand Down Expand Up @@ -443,7 +443,7 @@ func TestGetAllTeams(t *testing.T) {
size int64 = 2
)

response, err := GetAllTeams(dataBase, page, size, textRegexp, api.DescSortOrder)
response, err := SearchAllTeams(dataBase, page, size, textRegexp, api.DescSortOrder)
So(err, ShouldBeNil)
So(response, ShouldResemble, dto.TeamsList{
List: []dto.TeamModel{
Expand Down
6 changes: 3 additions & 3 deletions api/handler/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func teams(router chi.Router) {
middleware.Paginate(getAllTeamsDefaultPage, getAllTeamsDefaultSize),
middleware.SearchTextContext(regexp.MustCompile(getAllTeamsDefaultRegexTemplate)),
middleware.SortOrderContext(api.AscSortOrder),
).Get("/all", getAllTeams)
).Get("/all", searchAllTeams)
router.Get("/", getAllTeamsForUser)
router.Post("/", createTeam)
router.Route("/{teamId}", func(router chi.Router) {
Expand Down Expand Up @@ -154,13 +154,13 @@ func getTeam(writer http.ResponseWriter, request *http.Request) {
// @failure 422 {object} api.ErrorRenderExample "Render error"
// @failure 500 {object} api.ErrorInternalServerExample "Internal server error"
// @router /teams/all [get]
func getAllTeams(writer http.ResponseWriter, request *http.Request) {
func searchAllTeams(writer http.ResponseWriter, request *http.Request) {
page := middleware.GetPage(request)
size := middleware.GetSize(request)
textRegex := middleware.GetSearchText(request)
sort := middleware.GetSortOrder(request)

response, err := controller.GetAllTeams(database, page, size, textRegex, sort)
response, err := controller.SearchAllTeams(database, page, size, textRegex, sort)
if err != nil {
render.Render(writer, request, err) //nolint:errcheck
return
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 @@ -31,7 +31,7 @@ func fillContextForGetAllTeams(ctx context.Context, testPage, testSize int64, se
return ctx
}

func TestGetAllTeams(t *testing.T) {
func Test_searchAllTeams(t *testing.T) {
Convey("Test getting all teams", t, func() {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
Expand Down Expand Up @@ -78,7 +78,7 @@ func TestGetAllTeams(t *testing.T) {
expectedDTO.Size = &defaultTestSize
expectedDTO.Total = &total

getAllTeams(responseWriter, testRequest)
searchAllTeams(responseWriter, testRequest)

response := responseWriter.Result()
defer response.Body.Close()
Expand Down Expand Up @@ -121,7 +121,7 @@ func TestGetAllTeams(t *testing.T) {
ErrorText: expectedErrResponseFromController.ErrorText,
}

getAllTeams(responseWriter, testRequest)
searchAllTeams(responseWriter, testRequest)

response := responseWriter.Result()
defer response.Body.Close()
Expand Down

0 comments on commit 6a4e448

Please sign in to comment.