diff --git a/controller/download.go b/controller/download.go index b2a3929..ce6d601 100644 --- a/controller/download.go +++ b/controller/download.go @@ -13,7 +13,7 @@ type DownloadService interface { DownloadUsers(ctx context.Context, req domain.UsersPageRequest, w http.ResponseWriter) error DownloadSessions(ctx context.Context, req domain.SessionPageRequest, w http.ResponseWriter) error DownloadAudit(ctx context.Context, req domain.AuditPageRequest, w http.ResponseWriter) error - DownloadRoles(ctx context.Context, w http.ResponseWriter) error + DownloadRoles(ctx context.Context, req domain.RoleAllRequest, w http.ResponseWriter) error } type Download struct { @@ -92,8 +92,8 @@ func (c Download) Audit(ctx context.Context, req domain.AuditPageRequest, w http // @Success 200 // @Failure 500 {object} apierrors.Error "Внутренняя ошибка сервиса ```{errorCode: -1}```" // @Router /role/download [POST] -func (c Download) Roles(ctx context.Context, w http.ResponseWriter) error { - err := c.service.DownloadRoles(ctx, w) +func (c Download) Roles(ctx context.Context, req domain.RoleAllRequest, w http.ResponseWriter) error { + err := c.service.DownloadRoles(ctx, req, w) if err != nil { return errors.WithMessage(err, "download roles") } diff --git a/docs/swagger.json b/docs/swagger.json index 06357ff..8594252 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -2353,6 +2353,11 @@ "limit" ], "properties": { + "applicationGroup": { + "description": "Фильтр по группе приложений", + "type": "string", + "minLength": 1 + }, "limit": { "description": "Максимальное количество записей", "type": "integer" diff --git a/domain/user.go b/domain/user.go index d9a402e..bbaa2d6 100644 --- a/domain/user.go +++ b/domain/user.go @@ -33,6 +33,7 @@ type UserQuery struct { type UsersPageRequest struct { LimitOffsetParams + RoleAllRequest Order *OrderParams // Параметры сортировки Query *UserQuery // Параметры выборки diff --git a/service/download.go b/service/download.go index 5273650..6dbdd3d 100644 --- a/service/download.go +++ b/service/download.go @@ -178,7 +178,7 @@ func (s Download) DownloadUsers(ctx context.Context, req domain.UsersPageRequest return errors.WithMessage(err, "get users") } - roles, err := s.roleService.All(ctx, domain.RoleAllRequest{}) + roles, err := s.roleService.All(ctx, req.RoleAllRequest) if err != nil { return errors.WithMessage(err, "get roles") } @@ -216,8 +216,8 @@ func (s Download) DownloadUsers(ctx context.Context, req domain.UsersPageRequest return nil } -func (s Download) DownloadRoles(ctx context.Context, w http.ResponseWriter) error { - roles, err := s.roleService.All(ctx, domain.RoleAllRequest{}) +func (s Download) DownloadRoles(ctx context.Context, req domain.RoleAllRequest, w http.ResponseWriter) error { + roles, err := s.roleService.All(ctx, req) if err != nil { return errors.WithMessage(err, "get roles") } diff --git a/tests/download_test.go b/tests/download_test.go index 29ea6e9..0510d0e 100644 --- a/tests/download_test.go +++ b/tests/download_test.go @@ -232,7 +232,22 @@ func (s *DownloadSuite) TestAuditHappyPath() { } func (s *DownloadSuite) TestRolesHappyPath() { + InsertRole(s.db, entity.Role{ + Name: "admin_1", + ApplicationGroup: "123", + Permissions: s.permissions, + }) + InsertRole(s.db, entity.Role{ + Name: "admin_2", + ApplicationGroup: "456", + Permissions: s.permissions, + }) + + applicationGroup := "123" resp, err := s.httpCli.Post("role/download"). + JsonRequestBody(domain.RoleAllRequest{ + ApplicationGroup: &applicationGroup, + }). StatusCodeToError(). Do(s.T().Context()) s.Require().NoError(err) @@ -240,4 +255,23 @@ func (s *DownloadSuite) TestRolesHappyPath() { records, err := csv.NewReader(resp.Raw.Body).ReadAll() s.Require().NoError(err) s.Require().NotEmpty(records) + + header := records[0] + col := make(map[string]int, len(header)) + for i, name := range header { + col[name] = i + } + + moveIdx, ok := col["Действие"] + s.Require().True(ok) + keyIdx, ok := col["Ключ в системе"] + s.Require().True(ok) + nameIdx, ok := col["admin_1"] + s.Require().True(ok) + + s.Require().Len(records, 2) + row := records[1] + s.Require().EqualValues("123", row[moveIdx]) + s.Require().EqualValues("data_download", row[keyIdx]) + s.Require().EqualValues("+", row[nameIdx]) }