refactoring
This commit is contained in:
1 parent
f215008349
commit
0aec014161
13 files changed
+330
-311
No files matched your search
+15
-14
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
rd "github.com/go-redis/redis"
|
||||
rdLib "github.com/integration-system/isp-lib/redis"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
"isp-system-service/model"
|
||||
"isp-system-service/redis"
|
||||
@@ -19,11 +20,11 @@ type accessListController struct{}
|
||||
// @Description Возвращает список методов для приложения, для которых заданы настройки доступа
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body controller.Identity false "идентификатор приложения"
|
||||
// @Success 200 {array} controller.ModuleMethods "список методов по названию модуля"
|
||||
// @Param body body domain.Identity false "идентификатор приложения"
|
||||
// @Success 200 {array} domain.ModuleMethods "список методов по названию модуля"
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /access_list/get_by_id [POST]
|
||||
func (a accessListController) GetById(req Identity) (ModuleMethods, error) {
|
||||
func (a accessListController) GetById(req domain.Identity) (domain.ModuleMethods, error) {
|
||||
if accessList, err := model.AccessListRep.GetByAppId(req.Id); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
@@ -38,10 +39,10 @@ func (a accessListController) GetById(req Identity) (ModuleMethods, error) {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body entity.AccessList false "объект для настройки доступа"
|
||||
// @Success 200 {object} controller.CountResponse "количество измененных строк"
|
||||
// @Success 200 {object} domain.CountResponse "количество измененных строк"
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /access_list/set_one [POST]
|
||||
func (c accessListController) SetOne(request entity.AccessList) (*CountResponse, error) {
|
||||
func (c accessListController) SetOne(request entity.AccessList) (*domain.CountResponse, error) {
|
||||
var (
|
||||
resp = 0
|
||||
err error
|
||||
@@ -65,7 +66,7 @@ func (c accessListController) SetOne(request entity.AccessList) (*CountResponse,
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return &CountResponse{Count: resp}, nil
|
||||
return &domain.CountResponse{Count: resp}, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,11 +76,11 @@ func (c accessListController) SetOne(request entity.AccessList) (*CountResponse,
|
||||
// @Description Возвращает массив приложений с токенами по их идентификаторам
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body controller.SetListRequest false "объект настройки доступа"
|
||||
// @Success 200 {object} controller.CountResponse "количество добавленных строк"
|
||||
// @Param body body domain.SetListRequest false "объект настройки доступа"
|
||||
// @Success 200 {object} domain.CountResponse "количество добавленных строк"
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /access_list/set_list [POST]
|
||||
func (c accessListController) SetList(request SetListRequest) (*CountResponse, error) {
|
||||
func (c accessListController) SetList(request domain.SetListRequest) (*domain.CountResponse, error) {
|
||||
resp := 0
|
||||
if err := model.DbClient.RunInTransaction(func(repository model.AccessListRepository) error {
|
||||
|
||||
@@ -127,18 +128,18 @@ func (c accessListController) SetList(request SetListRequest) (*CountResponse, e
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return &CountResponse{Count: resp}, nil
|
||||
return &domain.CountResponse{Count: resp}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c accessListController) convertAccessList(accessLists []entity.AccessList) ModuleMethods {
|
||||
response := make(map[string][]MethodInfo)
|
||||
func (c accessListController) convertAccessList(accessLists []entity.AccessList) domain.ModuleMethods {
|
||||
response := make(map[string][]domain.MethodInfo)
|
||||
for _, access := range accessLists {
|
||||
moduleName, method := c.extractModuleName(access.Method)
|
||||
if methodStore, ok := response[moduleName]; ok {
|
||||
response[moduleName] = append(methodStore, MethodInfo{Value: access.Value, Method: method})
|
||||
response[moduleName] = append(methodStore, domain.MethodInfo{Value: access.Value, Method: method})
|
||||
} else {
|
||||
response[moduleName] = []MethodInfo{{Value: access.Value, Method: method}}
|
||||
response[moduleName] = []domain.MethodInfo{{Value: access.Value, Method: method}}
|
||||
}
|
||||
}
|
||||
return response
|
||||
|
||||
+50
-48
@@ -9,11 +9,16 @@ import (
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"google.golang.org/grpc/status"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
"isp-system-service/model"
|
||||
"isp-system-service/redis"
|
||||
)
|
||||
|
||||
var Application applicationController
|
||||
|
||||
type applicationController struct{}
|
||||
|
||||
// GetApplications godoc
|
||||
// @Tags application
|
||||
// @Summary Получить список приложений
|
||||
@@ -21,15 +26,15 @@ import (
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов приложений"
|
||||
// @Success 200 {array} controller.AppWithToken
|
||||
// @Success 200 {array} domain.AppWithToken
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /application/get_applications [POST]
|
||||
func GetApplications(list []int32) ([]*AppWithToken, error) {
|
||||
func (c applicationController) GetApplications(list []int32) ([]*domain.AppWithToken, error) {
|
||||
res, err := model.AppRep.GetApplications(list)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return enrichWithTokens(res...)
|
||||
return c.enrichWithTokens(res...)
|
||||
}
|
||||
|
||||
// GetApplicationsByServiceId godoc
|
||||
@@ -38,16 +43,16 @@ func GetApplications(list []int32) ([]*AppWithToken, error) {
|
||||
// @Description Возвращает список приложений по запрошенныму идентификатору сервиса
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body controller.Identity true "Идентификатор серсиса"
|
||||
// @Success 200 {array} controller.AppWithToken
|
||||
// @Param body body domain.Identity true "Идентификатор серсиса"
|
||||
// @Success 200 {array} domain.AppWithToken
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /application/get_applications_by_service_id [POST]
|
||||
func GetApplicationsByServiceId(identity Identity) ([]*AppWithToken, error) {
|
||||
func (c applicationController) GetApplicationsByServiceId(identity domain.Identity) ([]*domain.AppWithToken, error) {
|
||||
arr, err := model.AppRep.GetApplicationsByServiceId(identity.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return enrichWithTokens(arr...)
|
||||
return c.enrichWithTokens(arr...)
|
||||
}
|
||||
|
||||
// CreateUpdateApplication godoc
|
||||
@@ -57,13 +62,13 @@ func GetApplicationsByServiceId(identity Identity) ([]*AppWithToken, error) {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body entity.Application true "Объект приложения"
|
||||
// @Success 200 {object} controller.AppWithToken
|
||||
// @Success 200 {object} domain.AppWithToken
|
||||
// @Failure 400 {object} structure.GrpcError
|
||||
// @Failure 404 {object} structure.GrpcError
|
||||
// @Failure 409 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /application/create_update_application [POST]
|
||||
func CreateUpdateApplication(app entity.Application) (*AppWithToken, error) {
|
||||
func (c applicationController) CreateUpdateApplication(app entity.Application) (*domain.AppWithToken, error) {
|
||||
existed, err := model.AppRep.GetApplicationByNameAndServiceId(app.Name, app.ServiceId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -80,8 +85,8 @@ func CreateUpdateApplication(app entity.Application) (*AppWithToken, error) {
|
||||
return nil, status.Errorf(codes.AlreadyExists, "Application with name %s already exists", app.Name)
|
||||
}
|
||||
app, e := model.AppRep.CreateApplication(app)
|
||||
enrichWithTokens(app)
|
||||
return &AppWithToken{App: app, Tokens: []entity.Token{}}, e
|
||||
_, _ = c.enrichWithTokens(app)
|
||||
return &domain.AppWithToken{App: app, Tokens: []entity.Token{}}, e
|
||||
} else {
|
||||
if existed != nil && existed.Id != app.Id {
|
||||
return nil, status.Errorf(codes.AlreadyExists, "Application with name %s already exists", app.Name)
|
||||
@@ -97,7 +102,7 @@ func CreateUpdateApplication(app entity.Application) (*AppWithToken, error) {
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
arr, err := enrichWithTokens(app)
|
||||
arr, err := c.enrichWithTokens(app)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -111,13 +116,13 @@ func CreateUpdateApplication(app entity.Application) (*AppWithToken, error) {
|
||||
// @Description Возвращает описание приложения по его идентификатору
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body controller.Identity true "Идентификатор приложения"
|
||||
// @Success 200 {object} controller.AppWithToken
|
||||
// @Param body body domain.Identity true "Идентификатор приложения"
|
||||
// @Success 200 {object} domain.AppWithToken
|
||||
// @Failure 400 {object} structure.GrpcError
|
||||
// @Failure 404 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /application/get_application_by_id [POST]
|
||||
func GetApplicationById(identity Identity) (*AppWithToken, error) {
|
||||
func (c applicationController) GetApplicationById(identity domain.Identity) (*domain.AppWithToken, error) {
|
||||
application, err := model.AppRep.GetApplicationById(identity.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -125,7 +130,7 @@ func GetApplicationById(identity Identity) (*AppWithToken, error) {
|
||||
if application == nil {
|
||||
return nil, status.Errorf(codes.NotFound, "Application with id %d not found", identity.Id)
|
||||
}
|
||||
arr, err := enrichWithTokens(*application)
|
||||
arr, err := c.enrichWithTokens(*application)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -139,13 +144,13 @@ func GetApplicationById(identity Identity) (*AppWithToken, error) {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов приложений"
|
||||
// @Success 200 {object} controller.AppWithToken
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 400 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /application/delete_applications [POST]
|
||||
func DeleteApplications(list []int32) (DeleteResponse, error) {
|
||||
func (applicationController) DeleteApplications(list []int32) (domain.DeleteResponse, error) {
|
||||
if len(list) == 0 {
|
||||
return DeleteResponse{}, status.Errorf(codes.InvalidArgument, "At least one id are required")
|
||||
return domain.DeleteResponse{}, status.Errorf(codes.InvalidArgument, "At least one id are required")
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -157,7 +162,7 @@ func DeleteApplications(list []int32) (DeleteResponse, error) {
|
||||
appRep model.AppRepository, tokenRep model.TokenRepository, accessRep model.AccessListRepository) error {
|
||||
|
||||
for _, appId := range list {
|
||||
if _, err := revokeTokensForApp(Identity{appId}, &tokenRep); err != nil {
|
||||
if _, err := Token.revokeTokensForApp(domain.Identity{appId}, &tokenRep); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -166,18 +171,16 @@ func DeleteApplications(list []int32) (DeleteResponse, error) {
|
||||
return err
|
||||
}
|
||||
|
||||
redisDelRequest := make([]string, 0)
|
||||
for _, id := range list {
|
||||
accessList, err := accessRep.DeleteById(id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
redisDelArray := make([]string, len(accessList))
|
||||
for i, access := range accessList {
|
||||
redisDelArray[i] = fmt.Sprintf("%d|%s", id, access.Method)
|
||||
}
|
||||
redisDelRequest = append(redisDelRequest, redisDelArray...)
|
||||
accessList, err := accessRep.DeleteByIdList(list)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
redisDelRequest := make([]string, len(accessList))
|
||||
for i, access := range accessList {
|
||||
redisDelRequest[i] = fmt.Sprintf("%d|%s", access.AppId, access.Method)
|
||||
}
|
||||
|
||||
if len(redisDelRequest) > 0 {
|
||||
if _, err := redis.Client.Get().UseDb(rdLib.ApplicationPermissionDb, func(p rd.Pipeliner) error {
|
||||
if _, err := p.Del(redisDelRequest...).Result(); err != nil {
|
||||
@@ -191,9 +194,9 @@ func DeleteApplications(list []int32) (DeleteResponse, error) {
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return DeleteResponse{}, err
|
||||
return domain.DeleteResponse{}, err
|
||||
} else {
|
||||
return DeleteResponse{Deleted: count}, nil
|
||||
return domain.DeleteResponse{Deleted: count}, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,10 +206,10 @@ func DeleteApplications(list []int32) (DeleteResponse, error) {
|
||||
// @Description Возвращает описание взаимосвязей сервисов и приложений
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {array} controller.DomainWithServices
|
||||
// @Success 200 {array} domain.DomainWithServices
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /application/get_system_tree [POST]
|
||||
func GetSystemTree(md metadata.MD) ([]*DomainWithServices, error) {
|
||||
func (applicationController) GetSystemTree(md metadata.MD) ([]*domain.DomainWithServices, error) {
|
||||
sysId, err := utils.ResolveMetadataIdentity(utils.SystemIdHeader, md)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -218,14 +221,14 @@ func GetSystemTree(md metadata.MD) ([]*DomainWithServices, error) {
|
||||
|
||||
l := len(domains)
|
||||
if l == 0 {
|
||||
return []*DomainWithServices{}, nil
|
||||
return []*domain.DomainWithServices{}, nil
|
||||
}
|
||||
idList := make([]int32, l)
|
||||
domainsMap := make(map[int32]*DomainWithServices, l)
|
||||
res := make([]*DomainWithServices, l)
|
||||
domainsMap := make(map[int32]*domain.DomainWithServices, l)
|
||||
res := make([]*domain.DomainWithServices, l)
|
||||
for i, d := range domains {
|
||||
idList[i] = d.Id
|
||||
dws := &DomainWithServices{Id: d.Id, Name: d.Name, Description: d.Description, Services: make([]*ServiceWithApps, 0)}
|
||||
dws := &domain.DomainWithServices{Id: d.Id, Name: d.Name, Description: d.Description, Services: make([]*domain.ServiceWithApps, 0)}
|
||||
domainsMap[d.Id] = dws
|
||||
res[i] = dws
|
||||
}
|
||||
@@ -236,11 +239,11 @@ func GetSystemTree(md metadata.MD) ([]*DomainWithServices, error) {
|
||||
|
||||
l = len(services)
|
||||
idList = make([]int32, l)
|
||||
servicesMap := make(map[int32]*ServiceWithApps, l)
|
||||
servicesMap := make(map[int32]*domain.ServiceWithApps, l)
|
||||
for i, s := range services {
|
||||
idList[i] = s.Id
|
||||
d := domainsMap[s.DomainId]
|
||||
swa := &ServiceWithApps{Id: s.Id, Name: s.Name, Description: s.Description, Apps: make([]*SimpleApp, 0)}
|
||||
swa := &domain.ServiceWithApps{Id: s.Id, Name: s.Name, Description: s.Description, Apps: make([]*domain.SimpleApp, 0)}
|
||||
d.Services = append(d.Services, swa)
|
||||
servicesMap[s.Id] = swa
|
||||
}
|
||||
@@ -251,7 +254,7 @@ func GetSystemTree(md metadata.MD) ([]*DomainWithServices, error) {
|
||||
|
||||
for _, app := range apps {
|
||||
s := servicesMap[app.ServiceId]
|
||||
s.Apps = append(s.Apps, &SimpleApp{Id: app.Id,
|
||||
s.Apps = append(s.Apps, &domain.SimpleApp{Id: app.Id,
|
||||
Name: app.Name,
|
||||
Type: app.Type,
|
||||
Description: app.Description,
|
||||
@@ -262,17 +265,17 @@ func GetSystemTree(md metadata.MD) ([]*DomainWithServices, error) {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func enrichWithTokens(apps ...entity.Application) ([]*AppWithToken, error) {
|
||||
func (applicationController) enrichWithTokens(apps ...entity.Application) ([]*domain.AppWithToken, error) {
|
||||
l := len(apps)
|
||||
if len(apps) == 0 {
|
||||
return []*AppWithToken{}, nil
|
||||
return []*domain.AppWithToken{}, nil
|
||||
}
|
||||
idList := make([]int32, l)
|
||||
appMap := make(map[int32]*AppWithToken, l)
|
||||
enriched := make([]*AppWithToken, l)
|
||||
appMap := make(map[int32]*domain.AppWithToken, l)
|
||||
enriched := make([]*domain.AppWithToken, l)
|
||||
for i, a := range apps {
|
||||
idList[i] = a.Id
|
||||
awt := &AppWithToken{App: a, Tokens: make([]entity.Token, 0)}
|
||||
awt := &domain.AppWithToken{App: a, Tokens: make([]entity.Token, 0)}
|
||||
appMap[a.Id] = awt
|
||||
enriched[i] = awt
|
||||
}
|
||||
@@ -285,5 +288,4 @@ func enrichWithTokens(apps ...entity.Application) ([]*AppWithToken, error) {
|
||||
app.Tokens = append(app.Tokens, v)
|
||||
}
|
||||
return enriched, nil
|
||||
|
||||
}
|
||||
+14
-18
@@ -1,23 +1,19 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"isp-system-service/entity"
|
||||
"isp-system-service/model"
|
||||
|
||||
_ "github.com/integration-system/isp-lib/structure"
|
||||
"github.com/integration-system/isp-lib/utils"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"google.golang.org/grpc/status"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
"isp-system-service/model"
|
||||
)
|
||||
|
||||
/*func GetDomains(list []int32) ([]entity.Domain, error) {
|
||||
res, err := model.DomainRep.GetDomains(list)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, nil
|
||||
}*/
|
||||
var Domain domainController
|
||||
|
||||
type domainController struct{}
|
||||
|
||||
// GetDomainsBySystemId godoc
|
||||
// @Tags domain
|
||||
@@ -29,7 +25,7 @@ import (
|
||||
// @Success 200 {array} entity.Domain
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /domain/get_domains_by_system_id [POST]
|
||||
func GetDomainsBySystemId(md metadata.MD) ([]entity.Domain, error) {
|
||||
func (domainController) GetDomainsBySystemId(md metadata.MD) ([]entity.Domain, error) {
|
||||
sysId, err := utils.ResolveMetadataIdentity(utils.SystemIdHeader, md)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -47,7 +43,7 @@ func GetDomainsBySystemId(md metadata.MD) ([]entity.Domain, error) {
|
||||
// @Success 200 {object} entity.Domain
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /domain/create_update_domain [POST]
|
||||
func CreateUpdateDomain(domain entity.Domain, md metadata.MD) (*entity.Domain, error) {
|
||||
func (domainController) CreateUpdateDomain(domain entity.Domain, md metadata.MD) (*entity.Domain, error) {
|
||||
existed, err := model.DomainRep.GetDomainByNameAndSystemId(domain.Name, domain.SystemId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -94,12 +90,12 @@ func CreateUpdateDomain(domain entity.Domain, md metadata.MD) (*entity.Domain, e
|
||||
// @Description Возвращает описание домена по его идентификатору
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body controller.Identity true "Идентификатор домена"
|
||||
// @Param body body domain.Identity true "Идентификатор домена"
|
||||
// @Success 200 {object} entity.Domain
|
||||
// @Failure 404 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /domain/get_domain_by_id [POST]
|
||||
func GetDomainById(identity Identity) (*entity.Domain, error) {
|
||||
func (domainController) GetDomainById(identity domain.Identity) (*entity.Domain, error) {
|
||||
domain, err := model.DomainRep.GetDomainById(identity.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -117,14 +113,14 @@ func GetDomainById(identity Identity) (*entity.Domain, error) {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов доменов"
|
||||
// @Success 200 {object} controller.DeleteResponse
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 400 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /domain/delete_domains [POST]
|
||||
func DeleteDomains(list []int32) (DeleteResponse, error) {
|
||||
func (domainController) DeleteDomains(list []int32) (domain.DeleteResponse, error) {
|
||||
if len(list) == 0 {
|
||||
return DeleteResponse{Deleted: 0}, status.Errorf(codes.InvalidArgument, "At least one id are required")
|
||||
return domain.DeleteResponse{Deleted: 0}, status.Errorf(codes.InvalidArgument, "At least one id are required")
|
||||
}
|
||||
res, err := model.DomainRep.DeleteDomains(list)
|
||||
return DeleteResponse{Deleted: res}, err
|
||||
return domain.DeleteResponse{Deleted: res}, err
|
||||
}
|
||||
+17
-13
@@ -1,13 +1,17 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"isp-system-service/entity"
|
||||
"isp-system-service/model"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
"isp-system-service/model"
|
||||
)
|
||||
|
||||
var Service serviceController
|
||||
|
||||
type serviceController struct{}
|
||||
|
||||
// GetService godoc
|
||||
// @Tags service
|
||||
// @Summary Получить список сервисов
|
||||
@@ -18,7 +22,7 @@ import (
|
||||
// @Success 200 {array} entity.Service
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /service/get_service [POST]
|
||||
func GetService(list []int32) ([]entity.Service, error) {
|
||||
func (serviceController) GetService(list []int32) ([]entity.Service, error) {
|
||||
res, err := model.ServiceRep.GetServices(list)
|
||||
if err != nil {
|
||||
return res, err
|
||||
@@ -32,11 +36,11 @@ func GetService(list []int32) ([]entity.Service, error) {
|
||||
// @Description Возвращает список сервисов по идентификатору домена
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body controller.Identity true "Идентификатор домена"
|
||||
// @Param body body domain.Identity true "Идентификатор домена"
|
||||
// @Success 200 {array} entity.Service
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /service/get_services_by_domain_id [POST]
|
||||
func GetServicesByDomainId(identity Identity) ([]entity.Service, error) {
|
||||
func (serviceController) GetServicesByDomainId(identity domain.Identity) ([]entity.Service, error) {
|
||||
return model.ServiceRep.GetServicesByDomainId(identity.Id)
|
||||
}
|
||||
|
||||
@@ -53,7 +57,7 @@ func GetServicesByDomainId(identity Identity) ([]entity.Service, error) {
|
||||
// @Failure 409 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /service/create_update_service [POST]
|
||||
func CreateUpdateService(service entity.Service) (*entity.Service, error) {
|
||||
func (serviceController) CreateUpdateService(service entity.Service) (*entity.Service, error) {
|
||||
existed, err := model.ServiceRep.GetServiceByNameAndDomainId(service.Name, service.DomainId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -93,12 +97,12 @@ func CreateUpdateService(service entity.Service) (*entity.Service, error) {
|
||||
// @Description Возвращает описание сервиса по его идентификатору
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body controller.Identity true "Идентификатор сервиса"
|
||||
// @Param body body domain.Identity true "Идентификатор сервиса"
|
||||
// @Success 200 {object} entity.Service
|
||||
// @Failure 404 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /service/get_service_by_id [POST]
|
||||
func GetServiceById(identity Identity) (*entity.Service, error) {
|
||||
func (serviceController) GetServiceById(identity domain.Identity) (*entity.Service, error) {
|
||||
service, err := model.ServiceRep.GetServiceById(identity.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -116,14 +120,14 @@ func GetServiceById(identity Identity) (*entity.Service, error) {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []integer true "Массив идентификаторов сервисов"
|
||||
// @Success 200 {object} controller.DeleteResponse
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 400 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /service/delete_service [POST]
|
||||
func DeleteService(list []int32) (DeleteResponse, error) {
|
||||
func (serviceController) DeleteService(list []int32) (domain.DeleteResponse, error) {
|
||||
if len(list) == 0 {
|
||||
return DeleteResponse{Deleted: 0}, status.Error(codes.InvalidArgument, "At least one id are required")
|
||||
return domain.DeleteResponse{Deleted: 0}, status.Error(codes.InvalidArgument, "At least one id are required")
|
||||
}
|
||||
res, err := model.ServiceRep.DeleteServices(list)
|
||||
return DeleteResponse{Deleted: res}, err
|
||||
return domain.DeleteResponse{Deleted: res}, err
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
type DeleteResponse struct {
|
||||
Deleted int
|
||||
}
|
||||
|
||||
type CountResponse struct {
|
||||
Count int
|
||||
}
|
||||
|
||||
type Identity struct {
|
||||
Id int32 `json:"id" valid:"required~Required"`
|
||||
}
|
||||
|
||||
type AppWithToken struct {
|
||||
App entity.Application
|
||||
Tokens []entity.Token
|
||||
}
|
||||
|
||||
type SimpleApp struct {
|
||||
Id int32
|
||||
Name string
|
||||
Description string
|
||||
Type string
|
||||
Tokens []entity.Token
|
||||
}
|
||||
|
||||
type ServiceWithApps struct {
|
||||
Id int32
|
||||
Name string
|
||||
Description string
|
||||
Apps []*SimpleApp
|
||||
}
|
||||
|
||||
type DomainWithServices struct {
|
||||
Id int32
|
||||
Name string
|
||||
Description string
|
||||
Services []*ServiceWithApps
|
||||
}
|
||||
|
||||
type RevokeTokensRequest struct {
|
||||
AppId int32 `valid:"required~Required"`
|
||||
Tokens []string
|
||||
}
|
||||
|
||||
type CreateTokenRequest struct {
|
||||
AppId int32 `valid:"required~Required"`
|
||||
ExpireTimeMs int64
|
||||
}
|
||||
|
||||
type ModuleMethods map[string][]MethodInfo
|
||||
|
||||
type MethodInfo struct {
|
||||
Method string
|
||||
Value bool
|
||||
}
|
||||
|
||||
type SetListRequest struct {
|
||||
AppId int32
|
||||
Methods []MethodInfo
|
||||
}
|
||||
+15
-12
@@ -2,15 +2,18 @@ package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
_ "github.com/integration-system/isp-lib/structure"
|
||||
"isp-system-service/entity"
|
||||
"isp-system-service/model"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
"isp-system-service/model"
|
||||
)
|
||||
|
||||
var System systemController
|
||||
|
||||
type systemController struct{}
|
||||
|
||||
// GetSystems godoc
|
||||
// @Tags system
|
||||
// @Summary Получить список систем
|
||||
@@ -21,7 +24,7 @@ import (
|
||||
// @Success 200 {array} entity.System
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /system/get_systems [POST]
|
||||
func GetSystems(list []int32) ([]entity.System, error) {
|
||||
func (systemController) GetSystems(list []int32) ([]entity.System, error) {
|
||||
res, err := model.SystemRep.GetSystems(list)
|
||||
if err != nil {
|
||||
return res, err
|
||||
@@ -41,7 +44,7 @@ func GetSystems(list []int32) ([]entity.System, error) {
|
||||
// @Failure 409 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /system/create_update_system [POST]
|
||||
func CreateUpdateSystem(system entity.System) (*entity.System, error) {
|
||||
func (systemController) CreateUpdateSystem(system entity.System) (*entity.System, error) {
|
||||
existed, err := model.SystemRep.GetSystemByName(system.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -74,12 +77,12 @@ func CreateUpdateSystem(system entity.System) (*entity.System, error) {
|
||||
// @Description Возвращает описание системы по ее идентификатору
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body controller.Identity true "Идентификатор системы"
|
||||
// @Param body body domain.Identity true "Идентификатор системы"
|
||||
// @Success 200 {object} entity.System
|
||||
// @Failure 404 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /system/get_system_by_id [POST]
|
||||
func GetSystemById(identity Identity) (*entity.System, error) {
|
||||
func (systemController) GetSystemById(identity domain.Identity) (*entity.System, error) {
|
||||
sys, err := model.SystemRep.GetSystemById(identity.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -97,14 +100,14 @@ func GetSystemById(identity Identity) (*entity.System, error) {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body []integer false "Массив идентификаторов систем"
|
||||
// @Success 200 {object} controller.DeleteResponse
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 400 {object} structure.GrpcError
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /system/delete_systems [POST]
|
||||
func DeleteSystems(list []int32) (DeleteResponse, error) {
|
||||
func (systemController) DeleteSystems(list []int32) (domain.DeleteResponse, error) {
|
||||
if len(list) == 0 {
|
||||
return DeleteResponse{}, status.Error(codes.InvalidArgument, "At least one id are required")
|
||||
return domain.DeleteResponse{}, status.Error(codes.InvalidArgument, "At least one id are required")
|
||||
}
|
||||
res, err := model.SystemRep.DeleteSystems(list)
|
||||
return DeleteResponse{Deleted: res}, err
|
||||
return domain.DeleteResponse{Deleted: res}, err
|
||||
}
|
||||
+38
-38
@@ -9,6 +9,7 @@ import (
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"isp-system-service/conf"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
"isp-system-service/model"
|
||||
"isp-system-service/redis"
|
||||
@@ -23,12 +24,11 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
Token tokenController
|
||||
generator = tg.NewGenerator(tg.DefaultAlphabet)
|
||||
)
|
||||
|
||||
type BoolResponse struct {
|
||||
Ok bool
|
||||
}
|
||||
type tokenController struct{}
|
||||
|
||||
// CreateToken godoc
|
||||
// @Tags token
|
||||
@@ -36,12 +36,12 @@ type BoolResponse struct {
|
||||
// @Description Созддает токен и привязывает его к приложению
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body controller.CreateTokenRequest true "Объект создания токена"
|
||||
// @Success 200 {object} controller.AppWithToken
|
||||
// @Param body body domain.CreateTokenRequest true "Объект создания токена"
|
||||
// @Success 200 {object} domain.AppWithToken
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /token/create_token [POST]
|
||||
func CreateToken(req CreateTokenRequest) (*AppWithToken, error) {
|
||||
m, err, app := GetIdMap(req.AppId)
|
||||
func (c tokenController) CreateToken(req domain.CreateTokenRequest) (*domain.AppWithToken, error) {
|
||||
m, err, app := c.getIdMap(req.AppId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -70,7 +70,7 @@ func CreateToken(req CreateTokenRequest) (*AppWithToken, error) {
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
|
||||
err = SetIdentityMapForToken(token, m)
|
||||
err = c.setIdentityMapForToken(token, m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -81,7 +81,7 @@ func CreateToken(req CreateTokenRequest) (*AppWithToken, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
arr, err := enrichWithTokens(*app)
|
||||
arr, err := Application.enrichWithTokens(*app)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -95,20 +95,20 @@ func CreateToken(req CreateTokenRequest) (*AppWithToken, error) {
|
||||
// @Description Отвязывает токены от приложений и удялет их
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body controller.RevokeTokensRequest true "Объект отзыва токенов"
|
||||
// @Success 200 {object} controller.AppWithToken
|
||||
// @Param body body domain.RevokeTokensRequest true "Объект отзыва токенов"
|
||||
// @Success 200 {object} domain.AppWithToken
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /token/revoke_tokens [POST]
|
||||
func RevokeTokens(req RevokeTokensRequest) (*AppWithToken, error) {
|
||||
func (c tokenController) RevokeTokens(req domain.RevokeTokensRequest) (*domain.AppWithToken, error) {
|
||||
app, err := model.AppRep.GetApplicationById(req.AppId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, err = revokeTokens(req.Tokens, &model.TokenRep)
|
||||
_, err = c.revokeTokens(req.Tokens, &model.TokenRep)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res, err := enrichWithTokens(*app)
|
||||
res, err := Application.enrichWithTokens(*app)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -121,12 +121,12 @@ func RevokeTokens(req RevokeTokensRequest) (*AppWithToken, error) {
|
||||
// @Description Отвязывает токены от приложений и удаляет их по идентификатору приложения
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body controller.Identity true "Идентификатор приложения"
|
||||
// @Success 200 {object} controller.DeleteResponse
|
||||
// @Param body body domain.Identity true "Идентификатор приложения"
|
||||
// @Success 200 {object} domain.DeleteResponse
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /token/revoke_tokens_for_app [POST]
|
||||
func RevokeTokensForApp(identity Identity) (*DeleteResponse, error) {
|
||||
return revokeTokensForApp(identity, &model.TokenRep)
|
||||
func (c tokenController) RevokeTokensForApp(identity domain.Identity) (*domain.DeleteResponse, error) {
|
||||
return c.revokeTokensForApp(identity, &model.TokenRep)
|
||||
}
|
||||
|
||||
// GetTokensByAppId godoc
|
||||
@@ -135,15 +135,19 @@ func RevokeTokensForApp(identity Identity) (*DeleteResponse, error) {
|
||||
// @Description Возвращает список токенов, привязанных к приложению
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param body body controller.Identity true "Идентификатор приложения"
|
||||
// @Param body body domain.Identity true "Идентификатор приложения"
|
||||
// @Success 200 {array} entity.Token
|
||||
// @Failure 500 {object} structure.GrpcError
|
||||
// @Router /token/get_tokens_by_app_id [POST]
|
||||
func GetTokensByAppId(identity Identity) ([]entity.Token, error) {
|
||||
func (tokenController) GetTokensByAppId(identity domain.Identity) ([]entity.Token, error) {
|
||||
return model.TokenRep.GetTokensByAppId(identity.Id)
|
||||
}
|
||||
|
||||
func SetIdentityMapForTokenV2(token string, expireTime int64, idMap map[string]interface{}) error {
|
||||
func (c tokenController) setIdentityMapForToken(token entity.Token, idMap map[string]interface{}) error {
|
||||
return c.SetIdentityMapForTokenV2(token.Token, token.ExpireTime, idMap)
|
||||
}
|
||||
|
||||
func (tokenController) SetIdentityMapForTokenV2(token string, expireTime int64, idMap map[string]interface{}) error {
|
||||
cfg := config.Get().(*conf.Configuration)
|
||||
_, e := redis.Client.Get().UseDbTx(redisLib.ApplicationTokenDb, func(p rd.Pipeliner) error {
|
||||
t := fmt.Sprintf("%s|%s", token, cfg.InstanceUuid)
|
||||
@@ -160,11 +164,7 @@ func SetIdentityMapForTokenV2(token string, expireTime int64, idMap map[string]i
|
||||
return e
|
||||
}
|
||||
|
||||
func SetIdentityMapForToken(token entity.Token, idMap map[string]interface{}) error {
|
||||
return SetIdentityMapForTokenV2(token.Token, token.ExpireTime, idMap)
|
||||
}
|
||||
|
||||
func GetIdMap(appId int32) (map[string]interface{}, error, *entity.Application) {
|
||||
func (tokenController) getIdMap(appId int32) (map[string]interface{}, error, *entity.Application) {
|
||||
app, err := model.AppRep.GetApplicationById(appId)
|
||||
if err != nil {
|
||||
return nil, err, nil
|
||||
@@ -181,50 +181,50 @@ func GetIdMap(appId int32) (map[string]interface{}, error, *entity.Application)
|
||||
return nil, status.Errorf(codes.NotFound, "Service with id %d not found", app.ServiceId), app
|
||||
}
|
||||
|
||||
domain, err := model.DomainRep.GetDomainById(service.DomainId)
|
||||
domainInfo, err := model.DomainRep.GetDomainById(service.DomainId)
|
||||
if err != nil {
|
||||
return nil, err, app
|
||||
}
|
||||
if domain == nil {
|
||||
if domainInfo == nil {
|
||||
return nil, status.Errorf(codes.NotFound, "Domain with id %d not found", service.DomainId), app
|
||||
}
|
||||
|
||||
system, err := model.SystemRep.GetSystemById(domain.SystemId)
|
||||
system, err := model.SystemRep.GetSystemById(domainInfo.SystemId)
|
||||
if err != nil {
|
||||
return nil, err, app
|
||||
}
|
||||
if system == nil {
|
||||
return nil, status.Errorf(codes.NotFound, "System with id %d not found", domain.SystemId), app
|
||||
return nil, status.Errorf(codes.NotFound, "System with id %d not found", domainInfo.SystemId), app
|
||||
}
|
||||
|
||||
return map[string]interface{}{
|
||||
SystemIdentityFieldInDb: system.Id,
|
||||
DomainIdentityFieldInDb: domain.Id,
|
||||
DomainIdentityFieldInDb: domainInfo.Id,
|
||||
ServiceIdentityFieldInDb: service.Id,
|
||||
ApplicationIdentityFieldInDb: app.Id,
|
||||
}, nil, app
|
||||
}
|
||||
|
||||
func revokeTokensForApp(identity Identity, tokenRep *model.TokenRepository) (*DeleteResponse, error) {
|
||||
tokens, err := GetTokensByAppId(identity)
|
||||
func (c tokenController) revokeTokensForApp(identity domain.Identity, tokenRep *model.TokenRepository) (*domain.DeleteResponse, error) {
|
||||
tokens, err := c.GetTokensByAppId(identity)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
l := len(tokens)
|
||||
if l == 0 {
|
||||
return &DeleteResponse{0}, nil
|
||||
return &domain.DeleteResponse{Deleted: 0}, nil
|
||||
}
|
||||
tokenIdList := make([]string, l)
|
||||
for i, t := range tokens {
|
||||
tokenIdList[i] = t.Token
|
||||
}
|
||||
return revokeTokens(tokenIdList, tokenRep)
|
||||
return c.revokeTokens(tokenIdList, tokenRep)
|
||||
}
|
||||
|
||||
func revokeTokens(tokens []string, tokenRep *model.TokenRepository) (*DeleteResponse, error) {
|
||||
func (tokenController) revokeTokens(tokens []string, tokenRep *model.TokenRepository) (*domain.DeleteResponse, error) {
|
||||
var count = 0
|
||||
if len(tokens) == 0 {
|
||||
return &DeleteResponse{0}, nil
|
||||
return &domain.DeleteResponse{Deleted: 0}, nil
|
||||
}
|
||||
_, e := redis.Client.Get().UseDbTx(redisLib.ApplicationTokenDb, func(p rd.Pipeliner) error {
|
||||
deleted, err := tokenRep.DeleteTokens(tokens)
|
||||
@@ -238,5 +238,5 @@ func revokeTokens(tokens []string, tokenRep *model.TokenRepository) (*DeleteResp
|
||||
if e != nil {
|
||||
return nil, e
|
||||
}
|
||||
return &DeleteResponse{count}, nil
|
||||
return &domain.DeleteResponse{Deleted: count}, nil
|
||||
}
|
||||
+42
-42
@@ -1,6 +1,6 @@
|
||||
basePath: /api/system
|
||||
definitions:
|
||||
controller.AppWithToken:
|
||||
domain.AppWithToken:
|
||||
properties:
|
||||
app:
|
||||
$ref: '#/definitions/entity.Application'
|
||||
@@ -10,12 +10,12 @@ definitions:
|
||||
$ref: '#/definitions/entity.Token'
|
||||
type: array
|
||||
type: object
|
||||
controller.CountResponse:
|
||||
domain.CountResponse:
|
||||
properties:
|
||||
count:
|
||||
type: integer
|
||||
type: object
|
||||
controller.CreateTokenRequest:
|
||||
domain.CreateTokenRequest:
|
||||
properties:
|
||||
appId:
|
||||
type: integer
|
||||
@@ -24,12 +24,12 @@ definitions:
|
||||
required:
|
||||
- appId
|
||||
type: object
|
||||
controller.DeleteResponse:
|
||||
domain.DeleteResponse:
|
||||
properties:
|
||||
deleted:
|
||||
type: integer
|
||||
type: object
|
||||
controller.DomainWithServices:
|
||||
domain.DomainWithServices:
|
||||
properties:
|
||||
description:
|
||||
type: string
|
||||
@@ -39,24 +39,24 @@ definitions:
|
||||
type: string
|
||||
services:
|
||||
items:
|
||||
$ref: '#/definitions/controller.ServiceWithApps'
|
||||
$ref: '#/definitions/domain.ServiceWithApps'
|
||||
type: array
|
||||
type: object
|
||||
controller.Identity:
|
||||
domain.Identity:
|
||||
properties:
|
||||
id:
|
||||
type: integer
|
||||
required:
|
||||
- id
|
||||
type: object
|
||||
controller.MethodInfo:
|
||||
domain.MethodInfo:
|
||||
properties:
|
||||
method:
|
||||
type: string
|
||||
value:
|
||||
type: boolean
|
||||
type: object
|
||||
controller.ModuleMethods:
|
||||
domain.ModuleMethods:
|
||||
additionalProperties:
|
||||
items:
|
||||
properties:
|
||||
@@ -67,7 +67,7 @@ definitions:
|
||||
type: object
|
||||
type: array
|
||||
type: object
|
||||
controller.RevokeTokensRequest:
|
||||
domain.RevokeTokensRequest:
|
||||
properties:
|
||||
appId:
|
||||
type: integer
|
||||
@@ -78,11 +78,11 @@ definitions:
|
||||
required:
|
||||
- appId
|
||||
type: object
|
||||
controller.ServiceWithApps:
|
||||
domain.ServiceWithApps:
|
||||
properties:
|
||||
apps:
|
||||
items:
|
||||
$ref: '#/definitions/controller.SimpleApp'
|
||||
$ref: '#/definitions/domain.SimpleApp'
|
||||
type: array
|
||||
description:
|
||||
type: string
|
||||
@@ -91,16 +91,16 @@ definitions:
|
||||
name:
|
||||
type: string
|
||||
type: object
|
||||
controller.SetListRequest:
|
||||
domain.SetListRequest:
|
||||
properties:
|
||||
appId:
|
||||
type: integer
|
||||
methods:
|
||||
items:
|
||||
$ref: '#/definitions/controller.MethodInfo'
|
||||
$ref: '#/definitions/domain.MethodInfo'
|
||||
type: array
|
||||
type: object
|
||||
controller.SimpleApp:
|
||||
domain.SimpleApp:
|
||||
properties:
|
||||
description:
|
||||
type: string
|
||||
@@ -243,7 +243,7 @@ paths:
|
||||
in: body
|
||||
name: body
|
||||
schema:
|
||||
$ref: '#/definitions/controller.Identity'
|
||||
$ref: '#/definitions/domain.Identity'
|
||||
type: object
|
||||
produces:
|
||||
- application/json
|
||||
@@ -252,7 +252,7 @@ paths:
|
||||
description: список методов по названию модуля
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/controller.ModuleMethods'
|
||||
$ref: '#/definitions/domain.ModuleMethods'
|
||||
type: array
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
@@ -271,7 +271,7 @@ paths:
|
||||
in: body
|
||||
name: body
|
||||
schema:
|
||||
$ref: '#/definitions/controller.SetListRequest'
|
||||
$ref: '#/definitions/domain.SetListRequest'
|
||||
type: object
|
||||
produces:
|
||||
- application/json
|
||||
@@ -279,7 +279,7 @@ paths:
|
||||
"200":
|
||||
description: количество добавленных строк
|
||||
schema:
|
||||
$ref: '#/definitions/controller.CountResponse'
|
||||
$ref: '#/definitions/domain.CountResponse'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
@@ -305,7 +305,7 @@ paths:
|
||||
"200":
|
||||
description: количество измененных строк
|
||||
schema:
|
||||
$ref: '#/definitions/controller.CountResponse'
|
||||
$ref: '#/definitions/domain.CountResponse'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
@@ -333,7 +333,7 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/controller.AppWithToken'
|
||||
$ref: '#/definitions/domain.AppWithToken'
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
@@ -373,7 +373,7 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/controller.AppWithToken'
|
||||
$ref: '#/definitions/domain.DeleteResponse'
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
@@ -396,7 +396,7 @@ paths:
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/controller.Identity'
|
||||
$ref: '#/definitions/domain.Identity'
|
||||
type: object
|
||||
produces:
|
||||
- application/json
|
||||
@@ -404,7 +404,7 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/controller.AppWithToken'
|
||||
$ref: '#/definitions/domain.AppWithToken'
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
@@ -440,7 +440,7 @@ paths:
|
||||
description: OK
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/controller.AppWithToken'
|
||||
$ref: '#/definitions/domain.AppWithToken'
|
||||
type: array
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
@@ -460,7 +460,7 @@ paths:
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/controller.Identity'
|
||||
$ref: '#/definitions/domain.Identity'
|
||||
type: object
|
||||
produces:
|
||||
- application/json
|
||||
@@ -469,7 +469,7 @@ paths:
|
||||
description: OK
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/controller.AppWithToken'
|
||||
$ref: '#/definitions/domain.AppWithToken'
|
||||
type: array
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
@@ -490,7 +490,7 @@ paths:
|
||||
description: OK
|
||||
schema:
|
||||
items:
|
||||
$ref: '#/definitions/controller.DomainWithServices'
|
||||
$ref: '#/definitions/domain.DomainWithServices'
|
||||
type: array
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
@@ -547,7 +547,7 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/controller.DeleteResponse'
|
||||
$ref: '#/definitions/domain.DeleteResponse'
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
@@ -570,7 +570,7 @@ paths:
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/controller.Identity'
|
||||
$ref: '#/definitions/domain.Identity'
|
||||
type: object
|
||||
produces:
|
||||
- application/json
|
||||
@@ -678,7 +678,7 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/controller.DeleteResponse'
|
||||
$ref: '#/definitions/domain.DeleteResponse'
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
@@ -730,7 +730,7 @@ paths:
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/controller.Identity'
|
||||
$ref: '#/definitions/domain.Identity'
|
||||
type: object
|
||||
produces:
|
||||
- application/json
|
||||
@@ -761,7 +761,7 @@ paths:
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/controller.Identity'
|
||||
$ref: '#/definitions/domain.Identity'
|
||||
type: object
|
||||
produces:
|
||||
- application/json
|
||||
@@ -835,7 +835,7 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/controller.DeleteResponse'
|
||||
$ref: '#/definitions/domain.DeleteResponse'
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
@@ -858,7 +858,7 @@ paths:
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/controller.Identity'
|
||||
$ref: '#/definitions/domain.Identity'
|
||||
type: object
|
||||
produces:
|
||||
- application/json
|
||||
@@ -918,7 +918,7 @@ paths:
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/controller.CreateTokenRequest'
|
||||
$ref: '#/definitions/domain.CreateTokenRequest'
|
||||
type: object
|
||||
produces:
|
||||
- application/json
|
||||
@@ -926,7 +926,7 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/controller.AppWithToken'
|
||||
$ref: '#/definitions/domain.AppWithToken'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
@@ -945,7 +945,7 @@ paths:
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/controller.Identity'
|
||||
$ref: '#/definitions/domain.Identity'
|
||||
type: object
|
||||
produces:
|
||||
- application/json
|
||||
@@ -974,7 +974,7 @@ paths:
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/controller.RevokeTokensRequest'
|
||||
$ref: '#/definitions/domain.RevokeTokensRequest'
|
||||
type: object
|
||||
produces:
|
||||
- application/json
|
||||
@@ -982,7 +982,7 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/controller.AppWithToken'
|
||||
$ref: '#/definitions/domain.AppWithToken'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
@@ -1002,7 +1002,7 @@ paths:
|
||||
name: body
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/controller.Identity'
|
||||
$ref: '#/definitions/domain.Identity'
|
||||
type: object
|
||||
produces:
|
||||
- application/json
|
||||
@@ -1010,7 +1010,7 @@ paths:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/controller.DeleteResponse'
|
||||
$ref: '#/definitions/domain.DeleteResponse'
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package domain
|
||||
|
||||
type (
|
||||
Identity struct {
|
||||
Id int32 `json:"id" valid:"required~Required"`
|
||||
}
|
||||
|
||||
RevokeTokensRequest struct {
|
||||
AppId int32 `valid:"required~Required"`
|
||||
Tokens []string
|
||||
}
|
||||
|
||||
CreateTokenRequest struct {
|
||||
AppId int32 `valid:"required~Required"`
|
||||
ExpireTimeMs int64
|
||||
}
|
||||
)
|
||||
@@ -0,0 +1,52 @@
|
||||
package domain
|
||||
|
||||
import "isp-system-service/entity"
|
||||
|
||||
type (
|
||||
DeleteResponse struct {
|
||||
Deleted int
|
||||
}
|
||||
|
||||
CountResponse struct {
|
||||
Count int
|
||||
}
|
||||
|
||||
AppWithToken struct {
|
||||
App entity.Application
|
||||
Tokens []entity.Token
|
||||
}
|
||||
|
||||
DomainWithServices struct {
|
||||
Id int32
|
||||
Name string
|
||||
Description string
|
||||
Services []*ServiceWithApps
|
||||
}
|
||||
|
||||
ServiceWithApps struct {
|
||||
Id int32
|
||||
Name string
|
||||
Description string
|
||||
Apps []*SimpleApp
|
||||
}
|
||||
|
||||
SimpleApp struct {
|
||||
Id int32
|
||||
Name string
|
||||
Description string
|
||||
Type string
|
||||
Tokens []entity.Token
|
||||
}
|
||||
|
||||
ModuleMethods map[string][]MethodInfo
|
||||
|
||||
MethodInfo struct {
|
||||
Method string
|
||||
Value bool
|
||||
}
|
||||
|
||||
SetListRequest struct {
|
||||
AppId int32
|
||||
Methods []MethodInfo
|
||||
}
|
||||
)
|
||||
+48
-49
@@ -2,102 +2,101 @@ 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(controller.Identity) (*entity.System, error) `method:"get_system_by_id" group:"system" inner:"true"`
|
||||
DeleteSystems func([]int32) (controller.DeleteResponse, error) `method:"delete_systems" group:"system" inner:"true"`
|
||||
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 {
|
||||
//GetDomains func([]int32) ([]entity.Domain, error) `method:"get_domains" group:"domain" inner:"true"`
|
||||
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(controller.Identity) (*entity.Domain, error) `method:"get_domain_by_id" group:"domain" inner:"true"`
|
||||
DeleteDomains func([]int32) (controller.DeleteResponse, error) `method:"delete_domains" 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(controller.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(controller.Identity) (*entity.Service, error) `method:"get_service_by_id" group:"service" inner:"true"`
|
||||
DeleteService func([]int32) (controller.DeleteResponse, error) `method:"delete_service" group:"service" inner:"true"`
|
||||
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) ([]*controller.AppWithToken, error) `method:"get_applications" group:"application" inner:"true"`
|
||||
GetApplicationsByServiceId func(controller.Identity) ([]*controller.AppWithToken, error) `method:"get_applications_by_service_id" group:"application" inner:"true"`
|
||||
CreateUpdateApplication func(entity.Application) (*controller.AppWithToken, error) `method:"create_update_application" group:"application" inner:"true"`
|
||||
GetApplicationById func(controller.Identity) (*controller.AppWithToken, error) `method:"get_application_by_id" group:"application" inner:"true"`
|
||||
DeleteApplications func([]int32) (controller.DeleteResponse, error) `method:"delete_applications" group:"application" inner:"true"`
|
||||
GetSystemTree func(metadata.MD) ([]*controller.DomainWithServices, error) `method:"get_system_tree" group:"application" inner:"true"`
|
||||
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(controller.CreateTokenRequest) (*controller.AppWithToken, error) `method:"create_token" group:"token" inner:"true"`
|
||||
RevokeTokens func(controller.RevokeTokensRequest) (*controller.AppWithToken, error) `method:"revoke_tokens" group:"token" inner:"true"`
|
||||
RevokeTokensForApp func(controller.Identity) (*controller.DeleteResponse, error) `method:"revoke_tokens_for_app" group:"token" inner:"true"`
|
||||
GetTokensByAppId func(controller.Identity) ([]entity.Token, error) `method:"get_tokens_by_app_id" group:"token" inner:"true"`
|
||||
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(controller.Identity) (controller.ModuleMethods, error) `method:"get_by_id" group:"access_list" inner:"true"`
|
||||
SetOne func(entity.AccessList) (*controller.CountResponse, error) `method:"set_one" group:"access_list" inner:"true"`
|
||||
SetList func(controller.SetListRequest) (*controller.CountResponse, error) `method:"set_list" group:"access_list" inner:"true"`
|
||||
GetById func(domain.Identity) (domain.ModuleMethods, 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.CountResponse, error) `method:"set_list" group:"access_list" inner:"true"`
|
||||
}
|
||||
|
||||
func GetSystemHandler() *SystemHandler {
|
||||
return &SystemHandler{
|
||||
GetSystems: controller.GetSystems,
|
||||
CreateUpdateSystem: controller.CreateUpdateSystem,
|
||||
GetSystemById: controller.GetSystemById,
|
||||
DeleteSystems: controller.DeleteSystems,
|
||||
GetSystems: controller.System.GetSystems,
|
||||
CreateUpdateSystem: controller.System.CreateUpdateSystem,
|
||||
GetSystemById: controller.System.GetSystemById,
|
||||
DeleteSystems: controller.System.DeleteSystems,
|
||||
}
|
||||
}
|
||||
|
||||
func GetDomainHandler() *DomainHandler {
|
||||
return &DomainHandler{
|
||||
//GetDomains: controller.GetDomains,
|
||||
GetDomainsBySystemId: controller.GetDomainsBySystemId,
|
||||
CreateUpdateDomain: controller.CreateUpdateDomain,
|
||||
GetDomainById: controller.GetDomainById,
|
||||
DeleteDomains: controller.DeleteDomains,
|
||||
GetDomainsBySystemId: controller.Domain.GetDomainsBySystemId,
|
||||
CreateUpdateDomain: controller.Domain.CreateUpdateDomain,
|
||||
GetDomainById: controller.Domain.GetDomainById,
|
||||
DeleteDomains: controller.Domain.DeleteDomains,
|
||||
}
|
||||
}
|
||||
|
||||
func GetServiceHandler() *ServiceHandler {
|
||||
return &ServiceHandler{
|
||||
GetService: controller.GetService,
|
||||
GetServicesByDomainId: controller.GetServicesByDomainId,
|
||||
CreateUpdateService: controller.CreateUpdateService,
|
||||
GetServiceById: controller.GetServiceById,
|
||||
DeleteService: controller.DeleteService,
|
||||
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.GetApplications,
|
||||
GetApplicationsByServiceId: controller.GetApplicationsByServiceId,
|
||||
CreateUpdateApplication: controller.CreateUpdateApplication,
|
||||
GetApplicationById: controller.GetApplicationById,
|
||||
DeleteApplications: controller.DeleteApplications,
|
||||
GetSystemTree: controller.GetSystemTree,
|
||||
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.CreateToken,
|
||||
GetTokensByAppId: controller.GetTokensByAppId,
|
||||
RevokeTokens: controller.RevokeTokens,
|
||||
RevokeTokensForApp: controller.RevokeTokensForApp,
|
||||
CreateToken: controller.Token.CreateToken,
|
||||
GetTokensByAppId: controller.Token.GetTokensByAppId,
|
||||
RevokeTokens: controller.Token.RevokeTokens,
|
||||
RevokeTokensForApp: controller.Token.RevokeTokensForApp,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"io/ioutil"
|
||||
"isp-system-service/conf"
|
||||
"isp-system-service/controller"
|
||||
"isp-system-service/domain"
|
||||
path2 "path"
|
||||
)
|
||||
|
||||
@@ -35,7 +36,7 @@ func Up(tx *sql.Tx) error {
|
||||
return err
|
||||
}
|
||||
|
||||
var list []controller.DomainWithServices
|
||||
var list []domain.DomainWithServices
|
||||
if err := json.Unmarshal(bytes, &list); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -44,16 +45,16 @@ func Up(tx *sql.Tx) error {
|
||||
lastDomainId := int64(0)
|
||||
lastServiceId := int64(0)
|
||||
lastAppId := int64(0)
|
||||
for _, domain := range list {
|
||||
for _, domainInfo := range list {
|
||||
domainId := int64(0)
|
||||
if domainId, err = insertNode(tx, insertDomain, true, schema, domain.Id, domain.Name, domain.Description, 1); err != nil {
|
||||
if domainId, err = insertNode(tx, insertDomain, true, schema, domainInfo.Id, domainInfo.Name, domainInfo.Description, 1); err != nil {
|
||||
return err
|
||||
}
|
||||
if domainId > lastDomainId {
|
||||
lastDomainId = domainId
|
||||
}
|
||||
|
||||
for _, service := range domain.Services {
|
||||
for _, service := range domainInfo.Services {
|
||||
serviceId := int64(0)
|
||||
if serviceId, err = insertNode(tx, insertService, true, schema, service.Id, service.Name, service.Description, domainId); err != nil {
|
||||
return err
|
||||
@@ -81,7 +82,7 @@ func Up(tx *sql.Tx) error {
|
||||
controller.ServiceIdentityFieldInDb: serviceId,
|
||||
controller.ApplicationIdentityFieldInDb: appId,
|
||||
}
|
||||
if err := controller.SetIdentityMapForTokenV2(t.Token, t.ExpireTime, idMap); err != nil {
|
||||
if err := controller.Token.SetIdentityMapForTokenV2(t.Token, t.ExpireTime, idMap); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -107,14 +108,12 @@ func Down(tx *sql.Tx) error {
|
||||
|
||||
func insertNode(tx *sql.Tx, query string, scan bool, args ...interface{}) (int64, error) {
|
||||
var id int64
|
||||
var err error
|
||||
query = fmt.Sprintf(query, args...)
|
||||
row := tx.QueryRow(query)
|
||||
if scan {
|
||||
row.Scan(&id)
|
||||
}
|
||||
if err != nil {
|
||||
return 0, err
|
||||
if err := row.Scan(&id); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
return id, nil
|
||||
}
|
||||
|
||||
+13
-1
@@ -25,7 +25,19 @@ func (r *AccessListRepository) GetByAppId(appId int32) ([]entity.AccessList, err
|
||||
|
||||
func (r *AccessListRepository) DeleteById(id int32) ([]entity.AccessList, error) {
|
||||
model := make([]entity.AccessList, 0)
|
||||
if _, err := r.getDb().Model(&model).Where("app_id = ?", id).Delete(); err != nil {
|
||||
if _, err := r.getDb().Model(&model).Where("app_id = ?", id).Returning("*").Delete(); err != nil {
|
||||
if err == pg.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
} else {
|
||||
return model, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r *AccessListRepository) DeleteByIdList(list []int32) ([]entity.AccessList, error) {
|
||||
model := make([]entity.AccessList, 0)
|
||||
if _, err := r.getDb().Model(&model).Where("app_id IN (?)", pg.In(list)).Returning("*").Delete(); err != nil {
|
||||
if err == pg.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user