From cc255b96900ef7ddbfbb084fdafef31b0a453776 Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Sat, 29 Oct 2022 19:26:11 -0800 Subject: [PATCH] cleanup more duplicate service code --- backend/app/api/handlers/v1/v1_ctrl_group.go | 6 ++---- backend/internal/repo/repo_group.go | 5 +++-- backend/internal/services/service_group.go | 7 ------- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/backend/app/api/handlers/v1/v1_ctrl_group.go b/backend/app/api/handlers/v1/v1_ctrl_group.go index a403877..35c31e9 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_group.go +++ b/backend/app/api/handlers/v1/v1_ctrl_group.go @@ -2,7 +2,6 @@ package v1 import ( "net/http" - "strings" "time" "github.com/hay-kot/homebox/backend/internal/repo" @@ -54,13 +53,12 @@ func (ctrl *V1Controller) handleGroupGeneral() server.HandlerFunc { switch r.Method { case http.MethodGet: - group, err := ctrl.svc.Group.Get(ctx) + group, err := ctrl.repo.Groups.GroupByID(ctx, ctx.GID) if err != nil { log.Err(err).Msg("failed to get group") return validate.NewRequestError(err, http.StatusInternalServerError) } - group.Currency = strings.ToUpper(group.Currency) // TODO: Hack to fix the currency enums being lower caseƍ return server.Respond(w, http.StatusOK, group) case http.MethodPut: @@ -74,7 +72,7 @@ func (ctrl *V1Controller) handleGroupGeneral() server.HandlerFunc { log.Err(err).Msg("failed to update group") return validate.NewRequestError(err, http.StatusInternalServerError) } - group.Currency = strings.ToUpper(group.Currency) // TODO: Hack to fix the currency enums being lower case + return server.Respond(w, http.StatusOK, group) } diff --git a/backend/internal/repo/repo_group.go b/backend/internal/repo/repo_group.go index ac0e071..473ecc7 100644 --- a/backend/internal/repo/repo_group.go +++ b/backend/internal/repo/repo_group.go @@ -2,6 +2,7 @@ package repo import ( "context" + "strings" "time" "github.com/google/uuid" @@ -52,7 +53,7 @@ func mapToGroup(g *ent.Group) Group { Name: g.Name, CreatedAt: g.CreatedAt, UpdatedAt: g.UpdatedAt, - Currency: g.Currency.String(), + Currency: strings.ToUpper(g.Currency.String()), } } @@ -76,7 +77,7 @@ func (r *GroupRepository) GroupCreate(ctx context.Context, name string) (Group, } func (r *GroupRepository) GroupUpdate(ctx context.Context, ID uuid.UUID, data GroupUpdate) (Group, error) { - currency := group.Currency(data.Currency) + currency := group.Currency(strings.ToLower(data.Currency)) entity, err := r.db.Group.UpdateOneID(ID). SetName(data.Name). diff --git a/backend/internal/services/service_group.go b/backend/internal/services/service_group.go index 4859f85..cec613d 100644 --- a/backend/internal/services/service_group.go +++ b/backend/internal/services/service_group.go @@ -2,7 +2,6 @@ package services import ( "errors" - "strings" "time" "github.com/hay-kot/homebox/backend/internal/repo" @@ -13,10 +12,6 @@ type GroupService struct { repos *repo.AllRepos } -func (svc *GroupService) Get(ctx Context) (repo.Group, error) { - return svc.repos.Groups.GroupByID(ctx.Context, ctx.GID) -} - func (svc *GroupService) UpdateGroup(ctx Context, data repo.GroupUpdate) (repo.Group, error) { if data.Name == "" { data.Name = ctx.User.GroupName @@ -26,8 +21,6 @@ func (svc *GroupService) UpdateGroup(ctx Context, data repo.GroupUpdate) (repo.G return repo.Group{}, errors.New("currency cannot be empty") } - data.Currency = strings.ToLower(data.Currency) - return svc.repos.Groups.GroupUpdate(ctx.Context, ctx.GID, data) }