MSP-5186 Remove redundant I prefix from interfaces
This commit is contained in:
1 parent
28cff347ab
commit
f095d338cf
7 files changed
+89
-86
No files matched your search
+3
-3
@@ -9,7 +9,7 @@ import (
|
||||
"isp-system-service/domain"
|
||||
)
|
||||
|
||||
type ITokenService interface {
|
||||
type TokenService interface {
|
||||
GetByAppId(ctx context.Context, appId int) ([]domain.Token, error)
|
||||
Create(ctx context.Context, req domain.TokenCreateRequest) (*domain.ApplicationWithTokens, error)
|
||||
Revoke(ctx context.Context, req domain.TokenRevokeRequest) (*domain.ApplicationWithTokens, error)
|
||||
@@ -17,10 +17,10 @@ type ITokenService interface {
|
||||
}
|
||||
|
||||
type Token struct {
|
||||
service ITokenService
|
||||
service TokenService
|
||||
}
|
||||
|
||||
func NewToken(service ITokenService) Token {
|
||||
func NewToken(service TokenService) Token {
|
||||
return Token{
|
||||
service: service,
|
||||
}
|
||||
|
||||
+17
-16
@@ -3,45 +3,46 @@ package service
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type IAccessListAccessListRep interface {
|
||||
type AccessListAccessListRep interface {
|
||||
GetAccessListByAppId(ctx context.Context, appId int) ([]entity.AccessList, error)
|
||||
}
|
||||
|
||||
type IAccessListApplicationRep interface { // nolint:iface
|
||||
type AccessListApplicationRep interface { // nolint:iface
|
||||
GetApplicationById(ctx context.Context, id int) (*entity.Application, error)
|
||||
}
|
||||
|
||||
type IAccessListSetOneTx interface {
|
||||
type AccessListSetOneTx interface {
|
||||
UpsertAccessList(ctx context.Context, e entity.AccessList) (int, error)
|
||||
}
|
||||
|
||||
type IAccessListSetListTx interface {
|
||||
type AccessListSetListTx interface {
|
||||
GetAccessListByAppId(ctx context.Context, appId int) ([]entity.AccessList, error)
|
||||
InsertArrayAccessList(ctx context.Context, entity []entity.AccessList) error
|
||||
DeleteAccessList(ctx context.Context, appId int, methods []string) error
|
||||
DeleteAccessListByAppId(ctx context.Context, appId int) ([]entity.AccessList, error)
|
||||
}
|
||||
|
||||
type IAccessListTxRunner interface {
|
||||
AccessListSetOneTx(ctx context.Context, tx func(ctx context.Context, tx IAccessListSetOneTx) error) error
|
||||
AccessListSetListTx(ctx context.Context, tx func(ctx context.Context, tx IAccessListSetListTx) error) error
|
||||
type AccessListTxRunner interface {
|
||||
AccessListSetOneTx(ctx context.Context, tx func(ctx context.Context, tx AccessListSetOneTx) error) error
|
||||
AccessListSetListTx(ctx context.Context, tx func(ctx context.Context, tx AccessListSetListTx) error) error
|
||||
}
|
||||
|
||||
type AccessList struct {
|
||||
tx IAccessListTxRunner
|
||||
accessListRep IAccessListAccessListRep
|
||||
applicationRep IAccessListApplicationRep
|
||||
tx AccessListTxRunner
|
||||
accessListRep AccessListAccessListRep
|
||||
applicationRep AccessListApplicationRep
|
||||
}
|
||||
|
||||
func NewAccessList(
|
||||
tx IAccessListTxRunner,
|
||||
accessListRep IAccessListAccessListRep,
|
||||
applicationRep IAccessListApplicationRep,
|
||||
tx AccessListTxRunner,
|
||||
accessListRep AccessListAccessListRep,
|
||||
applicationRep AccessListApplicationRep,
|
||||
) AccessList {
|
||||
return AccessList{
|
||||
tx: tx,
|
||||
@@ -79,7 +80,7 @@ func (s AccessList) SetOne(ctx context.Context, request domain.AccessListSetOneR
|
||||
}
|
||||
|
||||
var resp int
|
||||
err = s.tx.AccessListSetOneTx(ctx, func(ctx context.Context, tx IAccessListSetOneTx) error {
|
||||
err = s.tx.AccessListSetOneTx(ctx, func(ctx context.Context, tx AccessListSetOneTx) error {
|
||||
resp, err = tx.UpsertAccessList(ctx, entity.AccessList{
|
||||
AppId: request.AppId,
|
||||
Method: request.Method,
|
||||
@@ -106,7 +107,7 @@ func (s AccessList) SetList(ctx context.Context, req domain.AccessListSetListReq
|
||||
return nil, errors.WithMessage(err, "get application by id")
|
||||
}
|
||||
|
||||
err = s.tx.AccessListSetListTx(ctx, func(ctx context.Context, tx IAccessListSetListTx) error {
|
||||
err = s.tx.AccessListSetListTx(ctx, func(ctx context.Context, tx AccessListSetListTx) error {
|
||||
if req.RemoveOld {
|
||||
_, err = tx.DeleteAccessListByAppId(ctx, req.AppId)
|
||||
if err != nil {
|
||||
|
||||
+21
-20
@@ -3,12 +3,13 @@ package service
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"isp-system-service/domain"
|
||||
"isp-system-service/entity"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type IApplicationApplicationRep interface {
|
||||
type ApplicationApplicationRep interface {
|
||||
GetApplicationById(ctx context.Context, id int) (*entity.Application, error)
|
||||
GetApplicationByIdList(ctx context.Context, idList []int) ([]entity.Application, error)
|
||||
GetApplicationByServiceIdList(ctx context.Context, serviceIdList []int) ([]entity.Application, error)
|
||||
@@ -17,44 +18,44 @@ type IApplicationApplicationRep interface {
|
||||
UpdateApplication(ctx context.Context, id int, name string, description string) (*entity.Application, error)
|
||||
}
|
||||
|
||||
type IApplicationTokenRep interface { // nolint:iface
|
||||
type ApplicationTokenRep interface { // nolint:iface
|
||||
GetTokenByAppIdList(ctx context.Context, appIdList []int) ([]entity.Token, error)
|
||||
}
|
||||
|
||||
type IApplicationServiceRep interface {
|
||||
type ApplicationServiceRep interface {
|
||||
GetServiceById(ctx context.Context, id int) (*entity.Service, error)
|
||||
GetServiceByDomainId(ctx context.Context, domainIdList []int) ([]entity.Service, error)
|
||||
}
|
||||
|
||||
type IApplicationDomainRep interface {
|
||||
type ApplicationDomainRep interface {
|
||||
GetDomainBySystemId(ctx context.Context, systemId int) ([]entity.Domain, error)
|
||||
}
|
||||
|
||||
type IApplicationDeleteTx interface {
|
||||
type ApplicationDeleteTx interface {
|
||||
DeleteApplicationByIdList(ctx context.Context, idList []int) (int, error)
|
||||
}
|
||||
|
||||
type IApplicationTxRunner interface {
|
||||
ApplicationDeleteTx(ctx context.Context, tx func(ctx context.Context, tx IApplicationDeleteTx) error) error
|
||||
type ApplicationTxRunner interface {
|
||||
ApplicationDeleteTx(ctx context.Context, tx func(ctx context.Context, tx ApplicationDeleteTx) error) error
|
||||
}
|
||||
|
||||
type Application struct {
|
||||
tx IApplicationTxRunner
|
||||
applicationRep IApplicationApplicationRep
|
||||
domainRep IApplicationDomainRep
|
||||
serviceRep IApplicationServiceRep
|
||||
tokenRep IApplicationTokenRep
|
||||
txRunner ApplicationTxRunner
|
||||
applicationRep ApplicationApplicationRep
|
||||
domainRep ApplicationDomainRep
|
||||
serviceRep ApplicationServiceRep
|
||||
tokenRep ApplicationTokenRep
|
||||
}
|
||||
|
||||
func NewApplication(
|
||||
tx IApplicationTxRunner,
|
||||
applicationRep IApplicationApplicationRep,
|
||||
domainRep IApplicationDomainRep,
|
||||
serviceRep IApplicationServiceRep,
|
||||
tokenRep IApplicationTokenRep,
|
||||
txRunner ApplicationTxRunner,
|
||||
applicationRep ApplicationApplicationRep,
|
||||
domainRep ApplicationDomainRep,
|
||||
serviceRep ApplicationServiceRep,
|
||||
tokenRep ApplicationTokenRep,
|
||||
) Application {
|
||||
return Application{
|
||||
tx: tx,
|
||||
txRunner: txRunner,
|
||||
applicationRep: applicationRep,
|
||||
domainRep: domainRep,
|
||||
serviceRep: serviceRep,
|
||||
@@ -229,7 +230,7 @@ func (s Application) CreateUpdate(ctx context.Context, req domain.ApplicationCre
|
||||
|
||||
func (s Application) Delete(ctx context.Context, idList []int) (int, error) {
|
||||
count := 0
|
||||
err := s.tx.ApplicationDeleteTx(ctx, func(ctx context.Context, tx IApplicationDeleteTx) error {
|
||||
err := s.txRunner.ApplicationDeleteTx(ctx, func(ctx context.Context, tx ApplicationDeleteTx) error {
|
||||
deletedApp, err := tx.DeleteApplicationByIdList(ctx, idList)
|
||||
if err != nil {
|
||||
return errors.WithMessage(err, "delete application by id list")
|
||||
|
||||
+11
-11
@@ -8,7 +8,7 @@ import (
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
type IDomainDomainRep interface {
|
||||
type DomainDomainRep interface {
|
||||
GetDomainById(ctx context.Context, id int) (*entity.Domain, error)
|
||||
GetDomainBySystemId(ctx context.Context, systemId int) ([]entity.Domain, error)
|
||||
GetDomainByNameAndSystemId(ctx context.Context, name string, systemId int) (*entity.Domain, error)
|
||||
@@ -18,19 +18,19 @@ type IDomainDomainRep interface {
|
||||
}
|
||||
|
||||
type Domain struct {
|
||||
domainRep IDomainDomainRep
|
||||
repo DomainDomainRep
|
||||
}
|
||||
|
||||
func NewDomain(
|
||||
domainRep IDomainDomainRep,
|
||||
repo DomainDomainRep,
|
||||
) Domain {
|
||||
return Domain{
|
||||
domainRep: domainRep,
|
||||
repo: repo,
|
||||
}
|
||||
}
|
||||
|
||||
func (s Domain) GetById(ctx context.Context, id int) (*domain.Domain, error) {
|
||||
domainEntity, err := s.domainRep.GetDomainById(ctx, id)
|
||||
domainEntity, err := s.repo.GetDomainById(ctx, id)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get domain by id")
|
||||
}
|
||||
@@ -40,7 +40,7 @@ func (s Domain) GetById(ctx context.Context, id int) (*domain.Domain, error) {
|
||||
}
|
||||
|
||||
func (s Domain) GetBySystemId(ctx context.Context, systemId int) ([]domain.Domain, error) {
|
||||
domainEntity, err := s.domainRep.GetDomainBySystemId(ctx, systemId)
|
||||
domainEntity, err := s.repo.GetDomainBySystemId(ctx, systemId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get domain by system_id")
|
||||
}
|
||||
@@ -53,7 +53,7 @@ func (s Domain) GetBySystemId(ctx context.Context, systemId int) ([]domain.Domai
|
||||
}
|
||||
|
||||
func (s Domain) CreateUpdate(ctx context.Context, req domain.DomainCreateUpdateRequest, systemId int) (*domain.Domain, error) {
|
||||
existed, err := s.domainRep.GetDomainByNameAndSystemId(ctx, req.Name, systemId)
|
||||
existed, err := s.repo.GetDomainByNameAndSystemId(ctx, req.Name, systemId)
|
||||
switch {
|
||||
case errors.Is(err, domain.ErrDomainNotFound):
|
||||
case err != nil:
|
||||
@@ -65,7 +65,7 @@ func (s Domain) CreateUpdate(ctx context.Context, req domain.DomainCreateUpdateR
|
||||
return nil, domain.ErrDomainDuplicateName
|
||||
}
|
||||
|
||||
domainEntity, err := s.domainRep.CreateDomain(ctx, req.Name, req.Description, systemId)
|
||||
domainEntity, err := s.repo.CreateDomain(ctx, req.Name, req.Description, systemId)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessagef(err, "create domain")
|
||||
}
|
||||
@@ -78,12 +78,12 @@ func (s Domain) CreateUpdate(ctx context.Context, req domain.DomainCreateUpdateR
|
||||
return nil, domain.ErrDomainDuplicateName
|
||||
}
|
||||
|
||||
_, err = s.domainRep.GetDomainById(ctx, req.Id)
|
||||
_, err = s.repo.GetDomainById(ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "get domain by id")
|
||||
}
|
||||
|
||||
domainEntity, err := s.domainRep.UpdateDomain(ctx, req.Id, req.Name, req.Description)
|
||||
domainEntity, err := s.repo.UpdateDomain(ctx, req.Id, req.Name, req.Description)
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "update domain")
|
||||
}
|
||||
@@ -93,7 +93,7 @@ func (s Domain) CreateUpdate(ctx context.Context, req domain.DomainCreateUpdateR
|
||||
}
|
||||
|
||||
func (s Domain) Delete(ctx context.Context, idList []int) (int, error) {
|
||||
result, err := s.domainRep.DeleteDomain(ctx, idList)
|
||||
result, err := s.repo.DeleteDomain(ctx, idList)
|
||||
if err != nil {
|
||||
return 0, errors.WithMessage(err, "delete domain")
|
||||
}
|
||||
|
||||
+6
-6
@@ -8,7 +8,7 @@ import (
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
type IServiceServiceRep interface {
|
||||
type ServiceServiceRep interface {
|
||||
GetServiceById(ctx context.Context, id int) (*entity.Service, error)
|
||||
GetServiceByIdList(ctx context.Context, idList []int) ([]entity.Service, error)
|
||||
GetServiceByDomainId(ctx context.Context, domainIdList []int) ([]entity.Service, error)
|
||||
@@ -18,18 +18,18 @@ type IServiceServiceRep interface {
|
||||
DeleteService(ctx context.Context, idList []int) (int, error)
|
||||
}
|
||||
|
||||
type IServiceDomainRep interface { // nolint:iface
|
||||
type ServiceDomainRep interface { // nolint:iface
|
||||
GetDomainById(ctx context.Context, id int) (*entity.Domain, error)
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
domainRep IServiceDomainRep
|
||||
serviceRep IServiceServiceRep
|
||||
domainRep ServiceDomainRep
|
||||
serviceRep ServiceServiceRep
|
||||
}
|
||||
|
||||
func NewService(
|
||||
domainRep IServiceDomainRep,
|
||||
serviceRep IServiceServiceRep,
|
||||
domainRep ServiceDomainRep,
|
||||
serviceRep ServiceServiceRep,
|
||||
) Service {
|
||||
return Service{
|
||||
domainRep: domainRep,
|
||||
|
||||
+27
-27
@@ -8,61 +8,61 @@ import (
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
type ITokenSource interface {
|
||||
type ApplicationTokenCreator interface {
|
||||
CreateApplicationToken() (string, error)
|
||||
}
|
||||
|
||||
type ITokenAppEnrich interface {
|
||||
type TokenAppEnrich interface {
|
||||
EnrichWithTokens(ctx context.Context, apps []entity.Application) ([]*domain.ApplicationWithTokens, error)
|
||||
}
|
||||
|
||||
type ITokenApplicationRep interface { // nolint:iface
|
||||
type TokenApplicationRep interface { // nolint:iface
|
||||
GetApplicationById(ctx context.Context, id int) (*entity.Application, error)
|
||||
}
|
||||
|
||||
type ITokenServiceRep interface {
|
||||
type TokenServiceRep interface {
|
||||
GetServiceById(ctx context.Context, id int) (*entity.Service, error)
|
||||
}
|
||||
|
||||
type ITokenDomainRep interface { // nolint:iface
|
||||
type TokenDomainRep interface { // nolint:iface
|
||||
GetDomainById(ctx context.Context, id int) (*entity.Domain, error)
|
||||
}
|
||||
|
||||
type ITokenTokenRep interface { // nolint:iface
|
||||
type TokenTokenRep interface { // nolint:iface
|
||||
GetTokenByAppIdList(ctx context.Context, appIdList []int) ([]entity.Token, error)
|
||||
}
|
||||
|
||||
type ITokenCreateTx interface {
|
||||
type TokenCreateTx interface {
|
||||
SaveToken(ctx context.Context, token string, appId int, expireTime int) (*entity.Token, error)
|
||||
}
|
||||
|
||||
type ITokenRevokeTx interface {
|
||||
type TokenRevokeTx interface {
|
||||
DeleteToken(ctx context.Context, tokens []string) (int, error)
|
||||
}
|
||||
|
||||
type ITokenTxRunner interface {
|
||||
TokenCreateTx(ctx context.Context, tx func(ctx context.Context, tx ITokenCreateTx) error) error
|
||||
TokenRevokeTx(ctx context.Context, tx func(ctx context.Context, tx ITokenRevokeTx) error) error
|
||||
type TokenTxRunner interface {
|
||||
TokenCreateTx(ctx context.Context, tx func(ctx context.Context, tx TokenCreateTx) error) error
|
||||
TokenRevokeTx(ctx context.Context, tx func(ctx context.Context, tx TokenRevokeTx) error) error
|
||||
}
|
||||
|
||||
type Token struct {
|
||||
jwt ITokenSource
|
||||
appEnrich ITokenAppEnrich
|
||||
tx ITokenTxRunner
|
||||
appRep ITokenApplicationRep
|
||||
domainRep ITokenDomainRep
|
||||
serviceRep ITokenServiceRep
|
||||
tokenRep ITokenTokenRep
|
||||
jwt ApplicationTokenCreator
|
||||
appEnrich TokenAppEnrich
|
||||
tx TokenTxRunner
|
||||
appRep TokenApplicationRep
|
||||
domainRep TokenDomainRep
|
||||
serviceRep TokenServiceRep
|
||||
tokenRep TokenTokenRep
|
||||
}
|
||||
|
||||
func NewToken(
|
||||
jwtGenerate ITokenSource,
|
||||
appEnrich ITokenAppEnrich,
|
||||
tx ITokenTxRunner,
|
||||
appRep ITokenApplicationRep,
|
||||
domainRep ITokenDomainRep,
|
||||
serviceRep ITokenServiceRep,
|
||||
tokenRep ITokenTokenRep,
|
||||
jwtGenerate ApplicationTokenCreator,
|
||||
appEnrich TokenAppEnrich,
|
||||
tx TokenTxRunner,
|
||||
appRep TokenApplicationRep,
|
||||
domainRep TokenDomainRep,
|
||||
serviceRep TokenServiceRep,
|
||||
tokenRep TokenTokenRep,
|
||||
) Token {
|
||||
return Token{
|
||||
appEnrich: appEnrich,
|
||||
@@ -110,7 +110,7 @@ func (s Token) Create(ctx context.Context, req domain.TokenCreateRequest) (*doma
|
||||
return nil, errors.WithMessagef(err, "create application token")
|
||||
}
|
||||
|
||||
err = s.tx.TokenCreateTx(ctx, func(ctx context.Context, tx ITokenCreateTx) error {
|
||||
err = s.tx.TokenCreateTx(ctx, func(ctx context.Context, tx TokenCreateTx) error {
|
||||
_, err = tx.SaveToken(ctx, token, req.AppId, req.ExpireTimeMs)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "tx save token")
|
||||
@@ -169,7 +169,7 @@ func (s Token) revokeTokens(ctx context.Context, tokens []string) (*domain.Delet
|
||||
}
|
||||
|
||||
var count int
|
||||
err := s.tx.TokenRevokeTx(ctx, func(ctx context.Context, tx ITokenRevokeTx) error {
|
||||
err := s.tx.TokenRevokeTx(ctx, func(ctx context.Context, tx TokenRevokeTx) error {
|
||||
deleted, err := tx.DeleteToken(ctx, tokens)
|
||||
if err != nil {
|
||||
return errors.WithMessagef(err, "tx delete token")
|
||||
|
||||
@@ -4,9 +4,10 @@ import (
|
||||
"context"
|
||||
"isp-system-service/service/baseline"
|
||||
|
||||
"github.com/txix-open/isp-kit/db"
|
||||
"isp-system-service/repository"
|
||||
"isp-system-service/service"
|
||||
|
||||
"github.com/txix-open/isp-kit/db"
|
||||
)
|
||||
|
||||
type Manager struct {
|
||||
@@ -23,7 +24,7 @@ type accessListSetOneTx struct {
|
||||
repository.AccessList
|
||||
}
|
||||
|
||||
func (m Manager) AccessListSetOneTx(ctx context.Context, msgTx func(ctx context.Context, tx service.IAccessListSetOneTx) error) error {
|
||||
func (m Manager) AccessListSetOneTx(ctx context.Context, msgTx func(ctx context.Context, tx service.AccessListSetOneTx) error) error {
|
||||
return m.db.RunInTransaction(ctx, func(ctx context.Context, tx *db.Tx) error {
|
||||
accessListRepository := repository.NewAccessList(tx)
|
||||
return msgTx(ctx, accessListSetOneTx{
|
||||
@@ -49,7 +50,7 @@ type applicationDeleteTx struct {
|
||||
repository.Application
|
||||
}
|
||||
|
||||
func (m Manager) ApplicationDeleteTx(ctx context.Context, msgTx func(ctx context.Context, tx service.IApplicationDeleteTx) error) error {
|
||||
func (m Manager) ApplicationDeleteTx(ctx context.Context, msgTx func(ctx context.Context, tx service.ApplicationDeleteTx) error) error {
|
||||
return m.db.RunInTransaction(ctx, func(ctx context.Context, tx *db.Tx) error {
|
||||
applicationRep := repository.NewApplication(tx)
|
||||
return msgTx(ctx, applicationDeleteTx{
|
||||
|
||||
Reference in new issue
Block a user