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")