MSP-623 reimplement routes

This commit is contained in:
DeniskaRediska committed 2022-06-06 15:44:28 +03:00
1 parent 9db858b0e2
commit 7b5ca9d12c
2 files changed
+182 -120

No files matched your search

-120
View File
@@ -1,120 +0,0 @@
package helper
import (
"isp-system-service/controller"
"isp-system-service/domain"
"isp-system-service/entity"
"google.golang.org/grpc/metadata"
)
type SystemHandler struct {
GetSystems func([]int32) ([]entity.System, error) `method:"get_systems" group:"system" inner:"true"`
CreateUpdateSystem func(entity.System) (*entity.System, error) `method:"create_update_system" group:"system" inner:"true"`
GetSystemById func(domain.Identity) (*entity.System, error) `method:"get_system_by_id" group:"system" inner:"true"`
DeleteSystems func([]int32) (domain.DeleteResponse, error) `method:"delete_systems" group:"system" inner:"true"`
}
type DomainHandler struct {
GetDomainsBySystemId func(metadata.MD) ([]entity.Domain, error) `method:"get_domains_by_system_id" group:"domain" inner:"true"`
CreateUpdateDomain func(entity.Domain, metadata.MD) (*entity.Domain, error) `method:"create_update_domain" group:"domain" inner:"true"`
GetDomainById func(domain.Identity) (*entity.Domain, error) `method:"get_domain_by_id" group:"domain" inner:"true"`
DeleteDomains func([]int32) (domain.DeleteResponse, error) `method:"delete_domains" group:"domain" inner:"true"`
}
type ServiceHandler struct {
GetService func([]int32) ([]entity.Service, error) `method:"get_service" group:"service" inner:"true"`
GetServicesByDomainId func(domain.Identity) ([]entity.Service, error) `method:"get_services_by_domain_id" group:"service" inner:"true"`
CreateUpdateService func(entity.Service) (*entity.Service, error) `method:"create_update_service" group:"service" inner:"true"`
GetServiceById func(domain.Identity) (*entity.Service, error) `method:"get_service_by_id" group:"service" inner:"true"`
DeleteService func([]int32) (domain.DeleteResponse, error) `method:"delete_service" group:"service" inner:"true"`
}
type ApplicationHandler struct {
GetApplications func([]int32) ([]*domain.AppWithToken, error) `method:"get_applications" group:"application" inner:"true"`
GetApplicationsByServiceId func(domain.Identity) ([]*domain.AppWithToken, error) `method:"get_applications_by_service_id" group:"application" inner:"true"`
CreateUpdateApplication func(entity.Application) (*domain.AppWithToken, error) `method:"create_update_application" group:"application" inner:"true"`
GetApplicationById func(domain.Identity) (*domain.AppWithToken, error) `method:"get_application_by_id" group:"application" inner:"true"`
DeleteApplications func([]int32) (domain.DeleteResponse, error) `method:"delete_applications" group:"application" inner:"true"`
GetSystemTree func(metadata.MD) ([]*domain.DomainWithServices, error) `method:"get_system_tree" group:"application" inner:"true"`
}
type TokenHandler struct {
CreateToken func(domain.CreateTokenRequest) (*domain.AppWithToken, error) `method:"create_token" group:"token" inner:"true"`
RevokeTokens func(domain.RevokeTokensRequest) (*domain.AppWithToken, error) `method:"revoke_tokens" group:"token" inner:"true"`
RevokeTokensForApp func(domain.Identity) (*domain.DeleteResponse, error) `method:"revoke_tokens_for_app" group:"token" inner:"true"`
GetTokensByAppId func(domain.Identity) ([]entity.Token, error) `method:"get_tokens_by_app_id" group:"token" inner:"true"`
}
type AccessListHandler struct {
GetById func(domain.Identity) ([]domain.MethodInfo, error) `method:"get_by_id" group:"access_list" inner:"true"`
SetOne func(entity.AccessList) (*domain.CountResponse, error) `method:"set_one" group:"access_list" inner:"true"`
SetList func(domain.SetListRequest) ([]domain.MethodInfo, error) `method:"set_list" group:"access_list" inner:"true"`
}
func GetSystemHandler() *SystemHandler {
return &SystemHandler{
GetSystems: controller.System.GetSystems,
CreateUpdateSystem: controller.System.CreateUpdateSystem,
GetSystemById: controller.System.GetSystemById,
DeleteSystems: controller.System.DeleteSystems,
}
}
func GetDomainHandler() *DomainHandler {
return &DomainHandler{
GetDomainsBySystemId: controller.Domain.GetDomainsBySystemId,
CreateUpdateDomain: controller.Domain.CreateUpdateDomain,
GetDomainById: controller.Domain.GetDomainById,
DeleteDomains: controller.Domain.DeleteDomains,
}
}
func GetServiceHandler() *ServiceHandler {
return &ServiceHandler{
GetService: controller.Service.GetService,
GetServicesByDomainId: controller.Service.GetServicesByDomainId,
CreateUpdateService: controller.Service.CreateUpdateService,
GetServiceById: controller.Service.GetServiceById,
DeleteService: controller.Service.DeleteService,
}
}
func GetApplicationHandler() *ApplicationHandler {
return &ApplicationHandler{
GetApplications: controller.Application.GetApplications,
GetApplicationsByServiceId: controller.Application.GetApplicationsByServiceId,
CreateUpdateApplication: controller.Application.CreateUpdateApplication,
GetApplicationById: controller.Application.GetApplicationById,
DeleteApplications: controller.Application.DeleteApplications,
GetSystemTree: controller.Application.GetSystemTree,
}
}
func GetTokenHandler() *TokenHandler {
return &TokenHandler{
CreateToken: controller.Token.CreateToken,
GetTokensByAppId: controller.Token.GetTokensByAppId,
RevokeTokens: controller.Token.RevokeTokens,
RevokeTokensForApp: controller.Token.RevokeTokensForApp,
}
}
func GetAccessListHandler() *AccessListHandler {
return &AccessListHandler{
GetById: controller.AccessList.GetById,
SetOne: controller.AccessList.SetOne,
SetList: controller.AccessList.SetList,
}
}
func GetAllHandlers() []interface{} {
return []interface{}{
GetSystemHandler(),
GetDomainHandler(),
GetServiceHandler(),
GetApplicationHandler(),
GetTokenHandler(),
GetAccessListHandler(),
}
}
+182
View File
@@ -0,0 +1,182 @@
package routes
import (
"github.com/integration-system/isp-kit/cluster"
"github.com/integration-system/isp-kit/grpc"
"github.com/integration-system/isp-kit/grpc/endpoint"
"github.com/integration-system/isp-kit/grpc/isp"
"isp-system-service/controller"
)
type Controllers struct {
AccessList controller.AccessList
Domain controller.Domain
Service controller.Service
Application controller.Application
Token controller.Token
}
func EndpointDescriptors() []cluster.EndpointDescriptor {
return endpointDescriptors(Controllers{})
}
func Handler(wrapper endpoint.Wrapper, c Controllers) isp.BackendServiceServer {
muxer := grpc.NewMux()
for _, descriptor := range endpointDescriptors(c) {
muxer.Handle(descriptor.Path, wrapper.Endpoint(descriptor.Handler))
}
return muxer
}
func endpointDescriptors(c Controllers) []cluster.EndpointDescriptor {
return concatCluster([][]cluster.EndpointDescriptor{
accessListCluster(c),
domainCluster(c),
serviceCluster(c),
applicationCluster(c),
tokenCluster(c),
})
}
func accessListCluster(c Controllers) []cluster.EndpointDescriptor {
return []cluster.EndpointDescriptor{
{
Path: "system/access_list/get_by_id",
Inner: true,
Handler: c.AccessList.GetById,
},
{
Path: "system/access_list/set_one",
Inner: true,
Handler: c.AccessList.SetOne,
},
{
Path: "system/access_list/set_list",
Inner: true,
Handler: c.AccessList.SetList,
},
}
}
func domainCluster(c Controllers) []cluster.EndpointDescriptor {
return []cluster.EndpointDescriptor{
{
Path: "system/domain/get_domains_by_system_id",
Inner: true,
Handler: c.Domain.GetBySystemId,
},
{
Path: "system/domain/create_update_domain",
Inner: true,
Handler: c.Domain.CreateUpdate,
},
{
Path: "system/domain/get_domain_by_id",
Inner: true,
Handler: c.Domain.GetById,
},
{
Path: "system/domain/delete_domains",
Inner: true,
Handler: c.Domain.Delete,
},
}
}
func serviceCluster(c Controllers) []cluster.EndpointDescriptor {
return []cluster.EndpointDescriptor{
{
Path: "system/service/get_service",
Inner: true,
Handler: c.Service.Get,
},
{
Path: "system/service/get_services_by_domain_id",
Inner: true,
Handler: c.Service.GetByDomainId,
},
{
Path: "system/service/create_update_service",
Inner: true,
Handler: c.Service.CreateUpdate,
},
{
Path: "system/service/get_service_by_id",
Inner: true,
Handler: c.Service.GetById,
},
{
Path: "system/service/delete_service",
Inner: true,
Handler: c.Service.Delete,
},
}
}
func applicationCluster(c Controllers) []cluster.EndpointDescriptor {
return []cluster.EndpointDescriptor{
{
Path: "system/application/get_applications",
Inner: true,
Handler: c.Application.GetByIdList,
},
{
Path: "system/application/get_applications_by_service_id",
Inner: true,
Handler: c.Application.GetByServiceId,
},
{
Path: "system/application/create_update_application",
Inner: true,
Handler: c.Application.CreateUpdate,
},
{
Path: "system/application/get_application_by_id",
Inner: true,
Handler: c.Application.GetById,
},
{
Path: "system/application/delete_applications",
Inner: true,
Handler: c.Application.Delete,
},
{
Path: "system/application/get_system_tree",
Inner: true,
Handler: c.Application.GetSystemTree,
},
}
}
func tokenCluster(c Controllers) []cluster.EndpointDescriptor {
return []cluster.EndpointDescriptor{
{
Path: "system/token/create_token",
Inner: true,
Handler: c.Token.Create,
},
{
Path: "system/token/revoke_tokens",
Inner: true,
Handler: c.Token.Revoke,
},
{
Path: "system/token/revoke_tokens_for_app",
Inner: true,
Handler: c.Token.RevokeForApp,
},
{
Path: "system/token/get_tokens_by_app_id",
Inner: true,
Handler: c.Token.GetByAppId,
},
}
}
func concatCluster(clusters [][]cluster.EndpointDescriptor) []cluster.EndpointDescriptor {
var result []cluster.EndpointDescriptor
for _, c := range clusters {
result = append(result, c...)
}
return result
}