Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WEB-117: Readable team URLs #23

Merged
merged 2 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions controllers/v1/public/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion routes/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion services/public/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions services/public/teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down