diff --git a/cmd/teams-api-server/main.go b/cmd/teams-api-server/main.go index e8d70ea..4709bd4 100644 --- a/cmd/teams-api-server/main.go +++ b/cmd/teams-api-server/main.go @@ -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) diff --git a/pkg/handler/handler.go b/pkg/handler/handler.go index 0992347..965a8e0 100644 --- a/pkg/handler/handler.go +++ b/pkg/handler/handler.go @@ -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) +} diff --git a/pkg/service/service.go b/pkg/service/service.go index 4d99b61..f6e29f9 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -7,6 +7,7 @@ import ( ) type TeamService interface { + GetTeam(teamID string) (domain.Team, error) GetTeams() ([]domain.Team, error) AddTeam(team domain.Team) error } @@ -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 +}