From 8984eb48977bc75fdf24b22aedb982c9f3bf8f9c Mon Sep 17 00:00:00 2001 From: Steven Weathers Date: Tue, 17 Sep 2024 15:52:44 -0400 Subject: [PATCH] Add team and org specific estimation scale update methods --- internal/db/poker/estimationscale.go | 54 ++++++++++++++++++++++++++++ internal/http/estimationscale.go | 4 +-- thunderdome/poker.go | 4 +++ 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/internal/db/poker/estimationscale.go b/internal/db/poker/estimationscale.go index 87a9964a..01d4e3f4 100644 --- a/internal/db/poker/estimationscale.go +++ b/internal/db/poker/estimationscale.go @@ -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;` diff --git a/internal/http/estimationscale.go b/internal/http/estimationscale.go index ed9ea22a..10e4daac 100644 --- a/internal/http/estimationscale.go +++ b/internal/http/estimationscale.go @@ -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), @@ -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), diff --git a/thunderdome/poker.go b/thunderdome/poker.go index 90ce23a6..5290aecc 100644 --- a/thunderdome/poker.go +++ b/thunderdome/poker.go @@ -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) }