From 141650417a363748aebc76b3de3fe4604b2c9988 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: Tue, 1 Apr 2025 19:10:41 +0300 Subject: [PATCH] MSP-5186 Check app duplicate name before check req.Id --- service/application.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/service/application.go b/service/application.go index 9c5fa15..4e3abdb 100644 --- a/service/application.go +++ b/service/application.go @@ -161,11 +161,11 @@ func (s Application) CreateUpdate(ctx context.Context, req domain.ApplicationCre return nil, errors.WithMessage(err, "get service by id") } - if req.Id == 0 { - if existed != nil { - return nil, domain.ErrApplicationDuplicateName - } + 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) if err != nil { return nil, errors.WithMessage(err, "get application by name and service_id") @@ -189,10 +189,6 @@ func (s Application) CreateUpdate(ctx context.Context, req domain.ApplicationCre return result[0], nil } - if existed != nil && existed.Id != req.Id { - return nil, domain.ErrApplicationDuplicateName - } - _, err = s.appRepo.GetApplicationById(ctx, req.Id) if err != nil { return nil, errors.WithMessage(err, "get application by id")