Skip to content

Commit

Permalink
[Oliver] feat: basic get team endpoint
Browse files Browse the repository at this point in the history
ThoughtWorks-DPS/lab-api-teams/#2
  • Loading branch information
olivercodes committed Jun 25, 2023
1 parent d1dc27e commit f196ca2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/teams-api-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func main() {
teamService := service.NewTeamService(teamRepo)
teamHandler := handler.NewTeamHandler(teamService)

router.GET("/teams/:teamID", teamHandler.GetTeam)
router.GET("/teams", teamHandler.GetTeams)
router.POST("/teams", teamHandler.AddTeam)

Expand Down
12 changes: 12 additions & 0 deletions pkg/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,15 @@ func (handler *TeamHandler) AddTeam(c *gin.Context) {

c.IndentedJSON(http.StatusCreated, newTeam)
}

func (handler *TeamHandler) GetTeam(c *gin.Context) {
teamID := c.Param("teamID")

team, err := handler.teamService.GetTeam(teamID)
if err != nil { // TODO transient/status errors
log.Printf("error %v", err)
return
}

c.IndentedJSON(http.StatusOK, team)
}
10 changes: 10 additions & 0 deletions pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
)

type TeamService interface {
GetTeam(teamID string) (domain.Team, error)
GetTeams() ([]domain.Team, error)
AddTeam(team domain.Team) error
}
Expand Down Expand Up @@ -35,3 +36,12 @@ func (s *teamServiceImpl) AddTeam(newTeam domain.Team) error {
}
return nil
}

func (s *teamServiceImpl) GetTeam(teamID string) (domain.Team, error) {
team, err := s.repo.GetTeam(teamID)
if err != nil {
return domain.Team{}, err // TODO transient/status errors
}

return team, nil
}

0 comments on commit f196ca2

Please sign in to comment.