MSP-3428 CRUD application_group, service -> application_group
This commit is contained in:
1 parent
7108122102
commit
bef400d0d9
26 files changed
+559
-395
No files matched your search
+15
-15
@@ -12,8 +12,8 @@ import (
|
||||
type ApplicationService interface {
|
||||
GetById(ctx context.Context, appId int) (*domain.ApplicationWithTokens, error)
|
||||
GetByIdList(ctx context.Context, idList []int) ([]*domain.ApplicationWithTokens, error)
|
||||
GetByServiceId(ctx context.Context, id int) ([]*domain.ApplicationWithTokens, error)
|
||||
SystemTree(ctx context.Context, systemId int) ([]*domain.DomainWithService, error)
|
||||
GetByApplicationGroupId(ctx context.Context, id int) ([]*domain.ApplicationWithTokens, error)
|
||||
SystemTree(ctx context.Context, systemId int) ([]*domain.DomainWithApplicationGroup, error)
|
||||
CreateUpdate(ctx context.Context, req domain.ApplicationCreateUpdateRequest) (*domain.ApplicationWithTokens, error)
|
||||
Delete(ctx context.Context, idList []int) (int, error)
|
||||
}
|
||||
@@ -66,30 +66,30 @@ func (c Application) GetByIdList(ctx context.Context, req []int) ([]*domain.Appl
|
||||
return c.service.GetByIdList(ctx, req)
|
||||
}
|
||||
|
||||
// GetByServiceId godoc
|
||||
// GetByApplicationGroupId godoc
|
||||
// @Tags application
|
||||
// @Summary Получить список приложений по идентификатору сервиса
|
||||
// @Description Возвращает список приложений по запрошенному идентификатору сервиса
|
||||
// @Summary Получить список приложений по идентификатору группы приложений
|
||||
// @Description Возвращает список приложений по запрошенному идентификатору группы приложений
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор сервиса"
|
||||
// @Param body body domain.Identity true "Идентификатор группы приложений"
|
||||
// @Success 200 {array} domain.ApplicationWithTokens
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /application/get_applications_by_service_id [POST]
|
||||
func (c Application) GetByServiceId(ctx context.Context, req domain.Identity) ([]*domain.ApplicationWithTokens, error) {
|
||||
return c.service.GetByServiceId(ctx, req.Id)
|
||||
// @Router /application/get_applications_by_application_group_id [POST]
|
||||
func (c Application) GetByApplicationGroupId(ctx context.Context, req domain.Identity) ([]*domain.ApplicationWithTokens, error) {
|
||||
return c.service.GetByApplicationGroupId(ctx, req.Id)
|
||||
}
|
||||
|
||||
// GetSystemTree godoc
|
||||
// @Tags application
|
||||
// @Summary Метод получения системного дерева
|
||||
// @Description Возвращает описание взаимосвязей сервисов и приложений
|
||||
// @Description Возвращает описание взаимосвязей группы приложений и приложений
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {array} domain.DomainWithService
|
||||
// @Success 200 {array} domain.DomainWithApplicationGroup
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /application/get_system_tree [POST]
|
||||
func (c Application) GetSystemTree(ctx context.Context) ([]*domain.DomainWithService, error) {
|
||||
func (c Application) GetSystemTree(ctx context.Context) ([]*domain.DomainWithApplicationGroup, error) {
|
||||
return c.service.SystemTree(ctx, domain.DefaultSystemId)
|
||||
}
|
||||
|
||||
@@ -109,12 +109,12 @@ func (c Application) GetSystemTree(ctx context.Context) ([]*domain.DomainWithSer
|
||||
func (c Application) CreateUpdate(ctx context.Context, req domain.ApplicationCreateUpdateRequest) (*domain.ApplicationWithTokens, error) {
|
||||
result, err := c.service.CreateUpdate(ctx, req)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrServiceNotFound):
|
||||
return nil, status.Errorf(codes.InvalidArgument, "service with id %d not found", req.ServiceId)
|
||||
case errors.Is(err, domain.ErrApplicationGroupNotFound):
|
||||
return nil, status.Errorf(codes.InvalidArgument, "application group with id %d not found", req.ApplicationGroupId)
|
||||
case errors.Is(err, domain.ErrApplicationDuplicateName):
|
||||
return nil, status.Errorf(codes.AlreadyExists, "application with name %s already exists", req.Name)
|
||||
case errors.Is(err, domain.ErrApplicationNotFound):
|
||||
return nil, status.Errorf(codes.NotFound, "Application with id %d not found", req.Id)
|
||||
return nil, status.Errorf(codes.NotFound, "application with id %d not found", req.Id)
|
||||
case err != nil:
|
||||
return nil, err
|
||||
default:
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"isp-system-service/domain"
|
||||
)
|
||||
|
||||
type ApplicationGroupService interface {
|
||||
GetById(ctx context.Context, id int) (*domain.ApplicationGroup, error)
|
||||
GetByIdList(ctx context.Context, idList []int) ([]domain.ApplicationGroup, error)
|
||||
GetByDomainId(ctx context.Context, domainId int) ([]domain.ApplicationGroup, error)
|
||||
CreateUpdate(ctx context.Context, req domain.ApplicationGroupCreateUpdateRequest) (*domain.ApplicationGroup, error)
|
||||
Delete(ctx context.Context, idList []int) (int, error)
|
||||
}
|
||||
|
||||
type ApplicationGroup struct {
|
||||
service ApplicationGroupService
|
||||
}
|
||||
|
||||
func NewApplicationGroup(service ApplicationGroupService) ApplicationGroup {
|
||||
return ApplicationGroup{
|
||||
service: service,
|
||||
}
|
||||
}
|
||||
|
||||
// GetById godoc
|
||||
// @Tags application_group
|
||||
// @Summary Получить группу приложений по идентификатору
|
||||
// @Description Возвращает описание группы приложений по ее идентификатору
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.Identity true "Идентификатор группы приложений"
|
||||
// @Success 200 {object} domain.ApplicationGroup
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /application_group/get_group_by_id [POST]
|
||||
func (c ApplicationGroup) GetById(ctx context.Context, req domain.Identity) (*domain.ApplicationGroup, error) {
|
||||
result, err := c.service.GetById(ctx, req.Id)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrApplicationGroupNotFound):
|
||||
return nil, status.Errorf(codes.NotFound, "application group with id %d not found", req.Id)
|
||||
case err != nil:
|
||||
return nil, err
|
||||
default:
|
||||
return result, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Get godoc
|
||||
// @Tags application_group
|
||||
// @Summary Получить список группы приложений
|
||||
// @Description Возвращает список групп приложений по их идентификаторам
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов групп приложений"
|
||||
// @Success 200 {array} domain.ApplicationGroup
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /application_group/get_group [POST]
|
||||
func (c ApplicationGroup) Get(ctx context.Context, req []int) ([]domain.ApplicationGroup, error) {
|
||||
return c.service.GetByIdList(ctx, req)
|
||||
}
|
||||
|
||||
// CreateUpdate godoc
|
||||
// @Tags application_group
|
||||
// @Summary Создать/обновить группу приложений
|
||||
// @Description Если группы приложений с такими идентификатором существует, то обновляет данные, если нет, то добавляет данные в базу
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body domain.ApplicationGroupCreateUpdateRequest true "Объект группы приложений"
|
||||
// @Success 200 {object} domain.ApplicationGroup
|
||||
// @Failure 400 {object} domain.GrpcError
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 409 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /application_group/create_update_group [POST]
|
||||
func (c ApplicationGroup) CreateUpdate(ctx context.Context, req domain.ApplicationGroupCreateUpdateRequest) (*domain.ApplicationGroup, error) {
|
||||
req.DomainId = 1 // Хардкодом проставляем domainId = 1
|
||||
|
||||
result, err := c.service.CreateUpdate(ctx, req)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrDomainNotFound):
|
||||
return nil, status.Errorf(codes.InvalidArgument, "domain with id %d not found", req.DomainId)
|
||||
case errors.Is(err, domain.ErrApplicationGroupNotFound):
|
||||
return nil, status.Errorf(codes.NotFound, "application group with id %d not found", req.Id)
|
||||
case errors.Is(err, domain.ErrApplicationGroupDuplicateName):
|
||||
return nil, status.Errorf(codes.AlreadyExists, "application group with name %s already exists", req.Name)
|
||||
case err != nil:
|
||||
return nil, err
|
||||
default:
|
||||
return result, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Delete godoc
|
||||
// @Tags application_group
|
||||
// @Summary Удалить группы приложений
|
||||
// @Description Удаляет группы приложений по списку их идентификаторов, возвращает количество удаленных групп
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []integer true "Массив идентификаторов групп приложений"
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 400 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /application_group/delete_group [POST]
|
||||
func (c ApplicationGroup) Delete(ctx context.Context, req []int) (*domain.DeleteResponse, error) {
|
||||
if len(req) == 0 {
|
||||
return nil, status.Error(codes.InvalidArgument, "at least one id are required")
|
||||
}
|
||||
|
||||
result, err := c.service.Delete(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &domain.DeleteResponse{
|
||||
Deleted: result,
|
||||
}, nil
|
||||
}
|
||||
+11
-11
@@ -10,10 +10,10 @@ import (
|
||||
)
|
||||
|
||||
type ServiceService interface {
|
||||
GetById(ctx context.Context, id int) (*domain.Service, error)
|
||||
GetByIdList(ctx context.Context, idList []int) ([]domain.Service, error)
|
||||
GetByDomainId(ctx context.Context, domainId int) ([]domain.Service, error)
|
||||
CreateUpdate(ctx context.Context, req domain.ServiceCreateUpdateRequest) (*domain.Service, error)
|
||||
GetById(ctx context.Context, id int) (*domain.ApplicationGroup, error)
|
||||
GetByIdList(ctx context.Context, idList []int) ([]domain.ApplicationGroup, error)
|
||||
GetByDomainId(ctx context.Context, domainId int) ([]domain.ApplicationGroup, error)
|
||||
CreateUpdate(ctx context.Context, req domain.ApplicationGroupCreateUpdateRequest) (*domain.ApplicationGroup, error)
|
||||
Delete(ctx context.Context, idList []int) (int, error)
|
||||
}
|
||||
|
||||
@@ -38,10 +38,10 @@ func NewService(service ServiceService) Service {
|
||||
// @Failure 404 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /service/get_service_by_id [POST]
|
||||
func (c Service) GetById(ctx context.Context, req domain.Identity) (*domain.Service, error) {
|
||||
func (c Service) GetById(ctx context.Context, req domain.Identity) (*domain.ApplicationGroup, error) {
|
||||
result, err := c.service.GetById(ctx, req.Id)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrServiceNotFound):
|
||||
case errors.Is(err, domain.ErrApplicationGroupNotFound):
|
||||
return nil, status.Errorf(codes.NotFound, "service with id %d not found", req.Id)
|
||||
case err != nil:
|
||||
return nil, err
|
||||
@@ -60,7 +60,7 @@ func (c Service) GetById(ctx context.Context, req domain.Identity) (*domain.Serv
|
||||
// @Success 200 {array} domain.Service
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /service/get_service [POST]
|
||||
func (c Service) Get(ctx context.Context, req []int) ([]domain.Service, error) {
|
||||
func (c Service) Get(ctx context.Context, req []int) ([]domain.ApplicationGroup, error) {
|
||||
return c.service.GetByIdList(ctx, req)
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ func (c Service) Get(ctx context.Context, req []int) ([]domain.Service, error) {
|
||||
// @Success 200 {array} domain.Service
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /service/get_services_by_domain_id [POST]
|
||||
func (c Service) GetByDomainId(ctx context.Context, req domain.Identity) ([]domain.Service, error) {
|
||||
func (c Service) GetByDomainId(ctx context.Context, req domain.Identity) ([]domain.ApplicationGroup, error) {
|
||||
return c.service.GetByDomainId(ctx, req.Id)
|
||||
}
|
||||
|
||||
@@ -91,14 +91,14 @@ func (c Service) GetByDomainId(ctx context.Context, req domain.Identity) ([]doma
|
||||
// @Failure 409 {object} domain.GrpcError
|
||||
// @Failure 500 {object} domain.GrpcError
|
||||
// @Router /service/create_update_service [POST]
|
||||
func (c Service) CreateUpdate(ctx context.Context, req domain.ServiceCreateUpdateRequest) (*domain.Service, error) {
|
||||
func (c Service) CreateUpdate(ctx context.Context, req domain.ApplicationGroupCreateUpdateRequest) (*domain.ApplicationGroup, error) {
|
||||
result, err := c.service.CreateUpdate(ctx, req)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrDomainNotFound):
|
||||
return nil, status.Errorf(codes.InvalidArgument, "domain with id %d not found", req.DomainId)
|
||||
case errors.Is(err, domain.ErrServiceNotFound):
|
||||
case errors.Is(err, domain.ErrApplicationGroupNotFound):
|
||||
return nil, status.Errorf(codes.NotFound, "service with id %d not found", req.Id)
|
||||
case errors.Is(err, domain.ErrServiceDuplicateName):
|
||||
case errors.Is(err, domain.ErrApplicationGroupDuplicateName):
|
||||
return nil, status.Errorf(codes.AlreadyExists, "service with name %s already exists", req.Name)
|
||||
case err != nil:
|
||||
return nil, err
|
||||
|
||||
+2
-2
@@ -55,8 +55,8 @@ func (c Token) Create(ctx context.Context, req domain.TokenCreateRequest) (*doma
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrApplicationNotFound):
|
||||
return nil, status.Errorf(codes.NotFound, "application with id %d not found", req.AppId)
|
||||
case errors.Is(err, domain.ErrServiceNotFound):
|
||||
return nil, status.Errorf(codes.NotFound, "service for app_id id %d not found", req.AppId)
|
||||
case errors.Is(err, domain.ErrApplicationGroupNotFound):
|
||||
return nil, status.Errorf(codes.NotFound, "application group for app_id id %d not found", req.AppId)
|
||||
case errors.Is(err, domain.ErrDomainNotFound):
|
||||
return nil, status.Errorf(codes.NotFound, "domain for app_id %d not found", req.AppId)
|
||||
case err != nil:
|
||||
|
||||
Reference in new issue
Block a user