MSP-5186 Add /application_group/get_all endpoint

This commit is contained in:
Синельник Тимур Романович committed 2025-04-03 14:01:28 +03:00
1 parent 199d576956
commit 4e85278a63
7 files changed
+100

No files matched your search

+15
View File
@@ -15,6 +15,7 @@ type AppGroupService interface {
Update(ctx context.Context, req domain.UpdateAppGroupRequest) (*domain.AppGroup, error)
DeleteList(ctx context.Context, req domain.IdListRequest) (*domain.DeleteResponse, error)
GetByIdList(ctx context.Context, idList []int) ([]domain.AppGroup, error)
GetAll(ctx context.Context) ([]domain.AppGroup, error)
}
type AppGroup struct {
@@ -122,3 +123,17 @@ func (c AppGroup) DeleteList(ctx context.Context, req domain.IdListRequest) (*do
func (c AppGroup) GetByIdList(ctx context.Context, req domain.IdListRequest) ([]domain.AppGroup, error) {
return c.service.GetByIdList(ctx, req.IdList)
}
// GetAll godoc
//
// @Tags application_group
// @Summary Получить группы приложений
// @Description Возвращает все группы приложений
// @Accept json
// @Produce json
// @Success 200 {array} domain.AppGroup
// @Failure 500 {object} apierrors.Error
// @Router /application_group/get_all [POST]
func (c AppGroup) GetAll(ctx context.Context) ([]domain.AppGroup, error) {
return c.service.GetAll(ctx)
}
+21
View File
@@ -830,6 +830,27 @@ paths:
summary: Удалить группы приложений
tags:
- application_group
/application_group/get_all:
post:
consumes:
- application/json
description: Возвращает все группы приложений
produces:
- application/json
responses:
"200":
description: OK
schema:
items:
$ref: '#/definitions/domain.AppGroup'
type: array
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/apierrors.Error'
summary: Получить группы приложений
tags:
- application_group
/application_group/get_by_id_list:
post:
consumes:
+19
View File
@@ -163,3 +163,22 @@ func (r AppGroup) DeleteAppGroup(ctx context.Context, idList []int) (int, error)
return int(rowsAffected), nil
}
func (r AppGroup) GetAllAppGroups(ctx context.Context) ([]entity.AppGroup, error) {
q, arg, err := query.New().
Select("id", "name", "description", "domain_id", "created_at", "updated_at").
From("application_group").
OrderBy("created_at DESC").
ToSql()
if err != nil {
return nil, errors.WithMessage(err, "build query")
}
result := make([]entity.AppGroup, 0)
err = r.db.Select(ctx, &result, q, arg...)
if err != nil {
return nil, errors.WithMessagef(err, "exec query %s", q)
}
return result, nil
}
+4
View File
@@ -229,6 +229,10 @@ func applicationGroupCluster(c Controllers) []cluster.EndpointDescriptor {
Path: "system/application_group/get_by_id_list",
Inner: true,
Handler: c.AppGroup.GetByIdList,
}, {
Path: "system/application_group/get_all",
Inner: true,
Handler: c.AppGroup.GetAll,
},
}
}
+12
View File
@@ -58,6 +58,18 @@ func (s AppGroup) GetByIdList(ctx context.Context, idList []int) ([]domain.AppGr
return result, nil
}
func (s AppGroup) GetAll(ctx context.Context) ([]domain.AppGroup, error) {
appGroups, err := s.repo.GetAllAppGroups(ctx)
if err != nil {
return nil, errors.WithMessage(err, "get all appGroups")
}
result := make([]domain.AppGroup, 0, len(appGroups))
for _, appGroup := range appGroups {
result = append(result, s.convertAppGroup(appGroup))
}
return result, nil
}
func (s AppGroup) convertAppGroup(appGroup entity.AppGroup) domain.AppGroup {
return domain.AppGroup{
Id: appGroup.Id,
+1
View File
@@ -34,6 +34,7 @@ type AppGroupRepo interface {
GetAppGroupById(ctx context.Context, id int) (*entity.AppGroup, error)
GetAppGroupByIdList(ctx context.Context, idList []int) ([]entity.AppGroup, error)
GetAppGroupByDomainId(ctx context.Context, domainIdList []int) ([]entity.AppGroup, error)
GetAllAppGroups(ctx context.Context) ([]entity.AppGroup, error)
GetAppGroupByNameAndDomainId(ctx context.Context, name string, domainId int) (*entity.AppGroup, error)
CreateAppGroup(ctx context.Context, name string, desc string, domainId int) (*entity.AppGroup, error)
UpdateAppGroup(ctx context.Context, id int, name string, description string) (*entity.AppGroup, error)
+28
View File
@@ -247,6 +247,34 @@ func (s *AppGroupSuite) TestDeleteList() {
s.Require().NoError(err)
}
func (s *AppGroupSuite) TestGetAll() {
toGenerate := 10
appGroups := make([]domain.AppGroup, 0, toGenerate)
for range 10 {
appGroup := s.createAppGroup()
appGroups = append(appGroups, domain.AppGroup{
Id: appGroup.Id,
Name: appGroup.Name,
Description: appGroup.Description.String,
CreatedAt: time.Time{},
UpdatedAt: time.Time{},
})
}
result := []domain.AppGroup{}
err := s.api.Invoke("system/application_group/get_all").
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) createAppGroup() *entity.AppGroup {
appGroup, err := s.appGroupRepo.CreateAppGroup(
s.T().Context(),