MSP-5186 Use sql.NullString for description
This commit is contained in:
1 parent
a047fb23dd
commit
9a1e8a7cd4
7 files changed
+52
-30
No files matched your search
+2
-1
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
+3
-16
@@ -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,
|
||||
|
||||
+1
-5
@@ -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,
|
||||
|
||||
+41
-3
@@ -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() {
|
||||
|
||||
@@ -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{},
|
||||
|
||||
Reference in new issue
Block a user