Skip to content

Commit

Permalink
Add team and org specific estimation scale update methods
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenWeathers committed Sep 17, 2024
1 parent 373774c commit 8984eb4
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
54 changes: 54 additions & 0 deletions internal/db/poker/estimationscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,60 @@ func (d *Service) UpdateEstimationScale(ctx context.Context, scale *thunderdome.
return scale, nil
}

// UpdateTeamEstimationScale updates an existing team estimation scale
func (d *Service) UpdateTeamEstimationScale(ctx context.Context, scale *thunderdome.EstimationScale) (*thunderdome.EstimationScale, error) {
query := `
UPDATE thunderdome.estimation_scale
SET name = $2, description = $3, scale_type = $4, values = $5, is_public = $6,
default_scale = $8, updated_at = CURRENT_TIMESTAMP
WHERE id = $1 AND team_id = $7
RETURNING updated_at;
`
err := d.DB.QueryRowContext(ctx, query,
scale.ID,
scale.Name,
scale.Description,
scale.ScaleType,
scale.Values,
scale.IsPublic,
scale.TeamID,
scale.DefaultScale,
).Scan(&scale.UpdatedAt)

if err != nil {
return nil, fmt.Errorf("error updating estimation scale: %v", err)
}

return scale, nil
}

// UpdateOrganizationEstimationScale updates an existing organization estimation scale
func (d *Service) UpdateOrganizationEstimationScale(ctx context.Context, scale *thunderdome.EstimationScale) (*thunderdome.EstimationScale, error) {
query := `
UPDATE thunderdome.estimation_scale
SET name = $2, description = $3, scale_type = $4, values = $5, is_public = $6,
default_scale = $8, updated_at = CURRENT_TIMESTAMP
WHERE id = $1 AND organization_id = $7
RETURNING updated_at;
`
err := d.DB.QueryRowContext(ctx, query,
scale.ID,
scale.Name,
scale.Description,
scale.ScaleType,
scale.Values,
scale.IsPublic,
scale.OrganizationID,
scale.DefaultScale,
).Scan(&scale.UpdatedAt)

if err != nil {
return nil, fmt.Errorf("error updating estimation scale: %v", err)
}

return scale, nil
}

// DeleteEstimationScale deletes an estimation scale
func (d *Service) DeleteEstimationScale(ctx context.Context, scaleID string) error {
query := `DELETE FROM thunderdome.estimation_scale WHERE id = $1;`
Expand Down
4 changes: 2 additions & 2 deletions internal/http/estimationscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ func (s *Service) handleTeamEstimationScaleUpdate() http.HandlerFunc {
IsPublic: false,
}

updatedScale, err := s.PokerDataSvc.UpdateEstimationScale(ctx, &es)
updatedScale, err := s.PokerDataSvc.UpdateTeamEstimationScale(ctx, &es)
if err != nil {
s.Logger.Ctx(ctx).Error("handleEstimationScaleUpdate error", zap.Error(err),
zap.String("scale_id", ID),
Expand Down Expand Up @@ -669,7 +669,7 @@ func (s *Service) handleOrganizationEstimationScaleUpdate() http.HandlerFunc {
IsPublic: false,
}

updatedScale, err := s.PokerDataSvc.UpdateEstimationScale(ctx, &es)
updatedScale, err := s.PokerDataSvc.UpdateOrganizationEstimationScale(ctx, &es)
if err != nil {
s.Logger.Ctx(ctx).Error("handleEstimationScaleUpdate error", zap.Error(err),
zap.String("scale_id", ID),
Expand Down
4 changes: 4 additions & 0 deletions thunderdome/poker.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,8 @@ type PokerDataSvc interface {
DeleteOrganizationEstimationScale(ctx context.Context, orgID string, scaleID string) error
// DeleteTeamEstimationScale deletes a team's estimation scale by its ID
DeleteTeamEstimationScale(ctx context.Context, teamID string, scaleID string) error
// UpdateOrganizationEstimationScale updates an existing organization estimation scale
UpdateOrganizationEstimationScale(ctx context.Context, scale *EstimationScale) (*EstimationScale, error)
// UpdateTeamEstimationScale updates an existing team estimation scale
UpdateTeamEstimationScale(ctx context.Context, scale *EstimationScale) (*EstimationScale, error)
}

0 comments on commit 8984eb4

Please sign in to comment.