From 3b28cf7d088ef21615590f112b5872a4d0a87051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B8=D0=BD=D0=B5=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA=20?= =?UTF-8?q?=D0=A2=D0=B8=D0=BC=D1=83=D1=80=20=D0=A0=D0=BE=D0=BC=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=B8=D1=87?= Date: Wed, 2 Apr 2025 10:45:02 +0300 Subject: [PATCH] MSP-5186 Simplify CreateUpdate --- service/application.go | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/service/application.go b/service/application.go index 50561ea..590d694 100644 --- a/service/application.go +++ b/service/application.go @@ -149,24 +149,8 @@ func (s Application) SystemTree(ctx context.Context, systemId int) ([]*domain.Do } func (s Application) CreateUpdate(ctx context.Context, req domain.ApplicationCreateUpdateRequest) (*domain.ApplicationWithTokens, error) { - existed, err := s.appRepo.GetApplicationByNameAndAppGroupId(ctx, req.Name, req.ServiceId) - switch { - case errors.Is(err, domain.ErrApplicationNotFound): - case err != nil: - return nil, errors.WithMessage(err, "get application by name and service_id") - } - - _, err = s.serviceRepo.GetAppGroupById(ctx, req.ServiceId) - if err != nil { - return nil, errors.WithMessage(err, "get service by id") - } - - if existed != nil && (existed.Id != req.Id || req.Id == 0) { - return nil, domain.ErrApplicationDuplicateName - } - if req.Id == 0 { - _, err = s.appRepo.GetApplicationByNameAndAppGroupId(ctx, req.Name, req.ServiceId) + _, err := s.appRepo.GetApplicationByNameAndAppGroupId(ctx, req.Name, req.ServiceId) if err != nil { return nil, errors.WithMessage(err, "get application by name and service_id") } @@ -189,7 +173,7 @@ func (s Application) CreateUpdate(ctx context.Context, req domain.ApplicationCre return result[0], nil } - _, err = s.appRepo.GetApplicationById(ctx, req.Id) + _, err := s.appRepo.GetApplicationById(ctx, req.Id) if err != nil { return nil, errors.WithMessage(err, "get application by id") }