From c02bc1b8b8dc3326f327fa6c0e8b85de193b1ca2 Mon Sep 17 00:00:00 2001 From: rmil Date: Wed, 28 Sep 2022 15:03:56 +0100 Subject: [PATCH 1/2] Switch GetTeam to use emailAlias ticket-id: WEB-117 --- controllers/v1/public/team.go | 12 ++++-------- routes/router.go | 2 +- services/public/teams.go | 6 +++--- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/controllers/v1/public/team.go b/controllers/v1/public/team.go index 90f32ad..a2e63d9 100644 --- a/controllers/v1/public/team.go +++ b/controllers/v1/public/team.go @@ -32,18 +32,14 @@ func (r *Repos) ListTeams(c echo.Context) error { // @Description Contains members and a range of descriptions // @ID get-public-team // @Tags public-teams -// @Param teamid path int true "teamid" +// @Param emailAlias path string true "emailAlias" // @Produce json // @Success 200 {object} public.Team -// @Router /v1/public/teams/{teamid} [get] +// @Router /v1/public/teams/{emailAlias} [get] func (r *Repos) GetTeam(c echo.Context) error { - teamID, err := strconv.Atoi(c.Param("teamid")) - if err != nil { - return echo.NewHTTPError(http.StatusBadRequest, "Bad teamid") - } - t, err := r.public.GetTeam(c.Request().Context(), teamID) + t, err := r.public.GetTeam(c.Request().Context(), c.Param("emailAlias")) if err != nil { - err = fmt.Errorf("Public GetTeamByYear failed: %w", err) + err = fmt.Errorf("Public GetTeam failed: %w", err) return echo.NewHTTPError(http.StatusInternalServerError, err) } return c.JSON(http.StatusOK, t) diff --git a/routes/router.go b/routes/router.go index 9e20a9c..cd37ba7 100644 --- a/routes/router.go +++ b/routes/router.go @@ -308,7 +308,7 @@ func (r *Router) loadRoutes() { { teams.GET("", r.public.ListTeams) teams.GET("/officers", r.public.ListOfficers) - teams.GET("/:teamid", r.public.GetTeam) + teams.GET("/:emailAlias", r.public.GetTeam) teams.GET("/:teamid/:year", r.public.GetTeamByYear) } stream := public.Group("/playout/channel") diff --git a/services/public/teams.go b/services/public/teams.go index a219916..ccb8839 100644 --- a/services/public/teams.go +++ b/services/public/teams.go @@ -44,16 +44,16 @@ func (s *Store) ListTeams(ctx context.Context) ([]Team, error) { } // GetTeam returns a single team including it's members -func (s *Store) GetTeam(ctx context.Context, teamID int) (Team, error) { +func (s *Store) GetTeam(ctx context.Context, emailAlias string) (Team, error) { t := Team{} err := s.db.GetContext(ctx, &t, ` SELECT team_id, name, email_alias, short_description, full_description FROM people.officership_teams - WHERE team_id = $1;`, teamID) + WHERE email_alias = $1;`, emailAlias) if err != nil { return t, fmt.Errorf("failed to get team: %w", err) } - t.Members, err = s.ListTeamMembers(ctx, teamID) + t.Members, err = s.ListTeamMembers(ctx, t.TeamID) if err != nil { return t, fmt.Errorf("failed to get team members: %w", err) } From 837e5fffd0c8491e2975d80090953b5bbcb873ed Mon Sep 17 00:00:00 2001 From: rmil Date: Wed, 28 Sep 2022 15:08:51 +0100 Subject: [PATCH 2/2] Update public package interface ticket-id: WEB-117 --- services/public/public.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/public/public.go b/services/public/public.go index e90924e..05ccd5a 100644 --- a/services/public/public.go +++ b/services/public/public.go @@ -22,6 +22,7 @@ type ( GetSeriesFromPath(ctx context.Context, path string) (Series, error) Search(ctx context.Context, query string) (Series, error) } + // PlaylistRepo represents all playlist interactions PlaylistRepo interface { GetPlaylist(ctx context.Context, playlistID int) (Playlist, error) GetPlaylistPopular(ctx context.Context, fromPeriod time.Time) (Playlist, error) @@ -39,7 +40,7 @@ type ( // TeamRepo represents all team interactions TeamRepo interface { ListTeams(ctx context.Context) ([]Team, error) - GetTeam(ctx context.Context, teamID int) (Team, error) + GetTeam(ctx context.Context, emailAlias string) (Team, error) GetTeamByYear(ctx context.Context, teamID, year int) (Team, error) ListTeamMembers(ctx context.Context, teamID int) ([]TeamMember, error) ListOfficers(ctx context.Context) ([]TeamMember, error)