diff --git a/entity/app_group.go b/entity/app_group.go index 82e7d92..9638e77 100644 --- a/entity/app_group.go +++ b/entity/app_group.go @@ -1,13 +1,14 @@ package entity import ( + "database/sql" "time" ) type AppGroup struct { Id int Name string - Description *string + Description sql.NullString DomainId int CreatedAt time.Time UpdatedAt time.Time diff --git a/entity/application.go b/entity/application.go index 1fcf51d..119ed67 100644 --- a/entity/application.go +++ b/entity/application.go @@ -1,13 +1,14 @@ package entity import ( + "database/sql" "time" ) type Application struct { Id int Name string - Description *string + Description sql.NullString ApplicationGroupId int Type string CreatedAt time.Time diff --git a/service/app_group.go b/service/app_group.go index 5538f70..03a8992 100644 --- a/service/app_group.go +++ b/service/app_group.go @@ -62,7 +62,7 @@ func (s AppGroup) convertAppGroup(appGroup entity.AppGroup) domain.AppGroup { return domain.AppGroup{ Id: appGroup.Id, Name: appGroup.Name, - Description: *appGroup.Description, + Description: appGroup.Description.String, CreatedAt: appGroup.CreatedAt, UpdatedAt: appGroup.UpdatedAt, } diff --git a/service/application.go b/service/application.go index ae4002c..deab679 100644 --- a/service/application.go +++ b/service/application.go @@ -110,14 +110,10 @@ func (s Application) SystemTree(ctx context.Context, systemId int) ([]*domain.Do resultServiceByServiceId := make(map[int]*domain.ServiceWithApps, len(serviceEntityList)) for i, serviceEntity := range serviceEntityList { serviceIdList[i] = serviceEntity.Id - description := "" - if serviceEntity.Description != nil { - description = *serviceEntity.Description - } resultService := &domain.ServiceWithApps{ Id: serviceEntity.Id, Name: serviceEntity.Name, - Description: description, + Description: serviceEntity.Description.String, Apps: make([]*domain.ApplicationSimple, 0), } r := resultByDomainId[serviceEntity.DomainId] @@ -132,15 +128,11 @@ func (s Application) SystemTree(ctx context.Context, systemId int) ([]*domain.Do for _, applicationEntity := range applicationEntityList { resultService := resultServiceByServiceId[applicationEntity.ApplicationGroupId] - description := "" - if applicationEntity.Description != nil { - description = *applicationEntity.Description - } resultService.Apps = append(resultService.Apps, &domain.ApplicationSimple{ Id: applicationEntity.Id, Name: applicationEntity.Name, Type: applicationEntity.Type, - Description: description, + Description: applicationEntity.Description.String, Tokens: make([]domain.Token, 0), }) } @@ -291,15 +283,10 @@ func (s Application) Update(ctx context.Context, req domain.UpdateApplicationReq } func (s Application) convertApplication(req entity.Application) domain.Application { - desc := "" - if req.Description != nil { - desc = *req.Description - } - return domain.Application{ Id: req.Id, Name: req.Name, - Description: desc, + Description: req.Description.String, ServiceId: req.ApplicationGroupId, Type: req.Type, CreatedAt: req.CreatedAt, diff --git a/service/service.go b/service/service.go index 659746e..a16c69c 100644 --- a/service/service.go +++ b/service/service.go @@ -102,14 +102,10 @@ func (s Service) Delete(ctx context.Context, idList []int) (int, error) { } func (s Service) convertService(req entity.AppGroup) domain.Service { - desc := "" - if req.Description != nil { - desc = *req.Description - } result := domain.Service{ Id: req.Id, Name: req.Name, - Description: desc, + Description: req.Description.String, DomainId: req.DomainId, CreatedAt: req.CreatedAt, UpdatedAt: req.UpdatedAt, diff --git a/tests/app_group_test.go b/tests/app_group_test.go index 2096d54..775f8e2 100644 --- a/tests/app_group_test.go +++ b/tests/app_group_test.go @@ -64,7 +64,45 @@ func (s *AppGroupSuite) TestGetByIdList() { appGroups = append(appGroups, domain.AppGroup{ Id: appGroup.Id, Name: appGroup.Name, - Description: *appGroup.Description, + Description: appGroup.Description.String, + CreatedAt: time.Time{}, + UpdatedAt: time.Time{}, + }) + ids = append(ids, appGroup.Id) + } + result := []domain.AppGroup{} + apiReq := domain.IdListRequest{IdList: ids} + err := s.api.Invoke("system/application_group/get_by_id_list"). + JsonRequestBody(apiReq). + JsonResponseBody(&result). + Do(s.T().Context()) + s.Require().NoError(err) + for i := range result { + s.Require().NotEmpty(result[i].CreatedAt) + result[i].CreatedAt = time.Time{} + + s.Require().NotEmpty(result[i].UpdatedAt) + result[i].UpdatedAt = time.Time{} + } + s.Require().ElementsMatch(appGroups, result) +} + +func (s *AppGroupSuite) TestGetByIdList_EmptyDescription() { + toGenerate := 10 + appGroups := make([]domain.AppGroup, 0, toGenerate) + ids := make([]int, 0, toGenerate) + for range 10 { + appGroup, err := s.appGroupRepo.CreateAppGroup( + s.T().Context(), + fake.It[string](), + "", + 1, + ) + s.Require().NoError(err) + appGroups = append(appGroups, domain.AppGroup{ + Id: appGroup.Id, + Name: appGroup.Name, + Description: "", CreatedAt: time.Time{}, UpdatedAt: time.Time{}, }) @@ -118,7 +156,7 @@ func (s *AppGroupSuite) TestCreate_HappyPath() { appGroup, err := s.appGroupRepo.GetAppGroupById(s.T().Context(), result.Id) s.Require().NoError(err) s.Require().Equal(apiReq.Name, appGroup.Name) - s.Require().Equal(apiReq.Description, *appGroup.Description) + s.Require().Equal(apiReq.Description, appGroup.Description.String) } func (s *AppGroupSuite) TestCreate_AppGroupNameNotUnique() { @@ -160,7 +198,7 @@ func (s *AppGroupSuite) TestUpdate_HappyPath() { appGroup, err := s.appGroupRepo.GetAppGroupById(s.T().Context(), apiReq.Id) s.Require().NoError(err) s.Require().Equal(apiReq.Name, appGroup.Name) - s.Require().Equal(apiReq.Description, *appGroup.Description) + s.Require().Equal(apiReq.Description, appGroup.Description.String) } func (s *AppGroupSuite) TestUpdate_AppGroupNameNotUnique() { diff --git a/tests/application_test.go b/tests/application_test.go index a2f1b81..8292a1a 100644 --- a/tests/application_test.go +++ b/tests/application_test.go @@ -217,11 +217,10 @@ func (s *ApplicationSuite) TestUpdate_HappyPath() { expectedDbApp := entity.Application{ Id: apiReq.Id, Name: apiReq.Name, + Description: app.Description, Type: inserted[0].Type, ApplicationGroupId: inserted[0].ServiceId, } - s.Require().Equal(apiReq.Description, *app.Description) - app.Description = nil s.Require().NotEmpty(app.CreatedAt) app.CreatedAt = time.Time{} @@ -302,7 +301,7 @@ func (s *ApplicationSuite) insertApps(toInsert []domain.Application) []domain.Ap toExpect = append(toExpect, domain.Application{ Id: createdApp.Id, Name: createdApp.Name, - Description: *createdApp.Description, + Description: createdApp.Description.String, ServiceId: createdApp.ApplicationGroupId, Type: createdApp.Type, CreatedAt: time.Time{},