From 1d4c81c42565bde4c27b25e52397f444f3acd14f 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: Thu, 3 Apr 2025 12:48:01 +0300 Subject: [PATCH] MSP-5186 Make application id required --- domain/application.go | 2 +- service/application.go | 10 +--------- tests/application_test.go | 34 ---------------------------------- 3 files changed, 2 insertions(+), 44 deletions(-) diff --git a/domain/application.go b/domain/application.go index b66e3af..482ac07 100644 --- a/domain/application.go +++ b/domain/application.go @@ -41,7 +41,7 @@ type ApplicationSimple struct { } type CreateApplicationRequest struct { - Id int + Id int `validate:"required"` Name string `validate:"required"` Description string ApplicationGroupId int `validate:"required"` diff --git a/service/application.go b/service/application.go index deab679..5c17144 100644 --- a/service/application.go +++ b/service/application.go @@ -249,15 +249,7 @@ func (s Application) GetAll(ctx context.Context) ([]domain.Application, error) { } func (s Application) Create(ctx context.Context, req domain.CreateApplicationRequest) (*domain.ApplicationWithTokens, error) { - appId := req.Id - var err error - if appId == 0 { - appId, err = s.appRepo.NextApplicationId(ctx) - if err != nil { - return nil, errors.WithMessage(err, "next application id") - } - } - app, err := s.appRepo.CreateApplication(ctx, appId, req.Name, req.Description, req.ApplicationGroupId, req.Type) + app, err := s.appRepo.CreateApplication(ctx, req.Id, req.Name, req.Description, req.ApplicationGroupId, req.Type) if err != nil { return nil, errors.WithMessage(err, "create application") } diff --git a/tests/application_test.go b/tests/application_test.go index 8292a1a..4e8532d 100644 --- a/tests/application_test.go +++ b/tests/application_test.go @@ -97,40 +97,6 @@ func (s *ApplicationSuite) TestCreate_HappyPath() { s.Require().Empty(result.Tokens) } -func (s *ApplicationSuite) TestCreate_WithEmptyAppId_HappyPath() { - nextAppId, err := s.appRepo.NextApplicationId(s.T().Context()) - s.Require().NoError(err) - - result := domain.ApplicationWithTokens{} - apiReq := fake.It[domain.CreateApplicationRequest]() - apiReq.Type = domain.ApplicationMobileType - appGroup := s.createAppGroup() - apiReq.ApplicationGroupId = appGroup.Id - apiReq.Id = 0 - - err = s.api.Invoke("system/application/create_application"). - JsonRequestBody(apiReq). - JsonResponseBody(&result). - Do(s.T().Context()) - s.Require().NoError(err) - - s.Require().NotEmpty(result.App.CreatedAt) - result.App.CreatedAt = time.Time{} - - s.Require().NotEmpty(result.App.UpdatedAt) - result.App.UpdatedAt = time.Time{} - - expectedApp := domain.Application{ - Id: nextAppId, - Name: apiReq.Name, - Description: apiReq.Description, - Type: apiReq.Type, - ServiceId: apiReq.ApplicationGroupId, - } - s.Require().Equal(expectedApp, result.App) - s.Require().Empty(result.Tokens) -} - func (s *ApplicationSuite) TestCreate_AppGroupNotFound() { apiReq := fake.It[domain.CreateApplicationRequest]() apiReq.Type = domain.ApplicationSystemType