add access_list methods
This commit is contained in:
1 parent
8a0ebe803a
commit
f215008349
20 files changed
+1511
-141
No files matched your search
@@ -0,0 +1,65 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/go-pg/pg"
|
||||
"github.com/go-pg/pg/orm"
|
||||
"github.com/integration-system/isp-lib/database"
|
||||
"isp-system-service/entity"
|
||||
)
|
||||
|
||||
type AccessListRepository struct {
|
||||
DB orm.DB
|
||||
rxClient *database.RxDbClient
|
||||
}
|
||||
|
||||
func (r *AccessListRepository) GetByAppId(appId int32) ([]entity.AccessList, error) {
|
||||
model := make([]entity.AccessList, 0)
|
||||
if err := r.getDb().Model(&model).Where("app_id = ?", appId).Select(); err != nil {
|
||||
if err == pg.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return model, nil
|
||||
}
|
||||
|
||||
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 == pg.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
} else {
|
||||
return model, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r *AccessListRepository) Insert(model []entity.AccessList) (int, error) {
|
||||
if result, err := r.getDb().Model(&model).Insert(); err != nil {
|
||||
if err == pg.ErrNoRows {
|
||||
return 0, nil
|
||||
}
|
||||
return 0, err
|
||||
} else {
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r *AccessListRepository) Upsert(model entity.AccessList) (int, error) {
|
||||
if result, err := r.getDb().Model(&model).OnConflict("(app_id, method) DO UPDATE").Insert(); err != nil {
|
||||
if err == pg.ErrNoRows {
|
||||
return 0, nil
|
||||
}
|
||||
return 0, err
|
||||
} else {
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r *AccessListRepository) getDb() orm.DB {
|
||||
if r.DB != nil {
|
||||
return r.DB
|
||||
}
|
||||
return r.rxClient.Unsafe()
|
||||
}
|
||||
+6
-5
@@ -15,9 +15,10 @@ var (
|
||||
log.Error(log_code.ErrorDatabaseClient, err)
|
||||
}))
|
||||
|
||||
AppRep = AppRepository{rxClient: DbClient}
|
||||
DomainRep = DomainRepository{rxClient: DbClient}
|
||||
ServiceRep = ServiceRepository{rxClient: DbClient}
|
||||
SystemRep = SystemRepository{rxClient: DbClient}
|
||||
TokenRep = TokenRepository{rxClient: DbClient}
|
||||
AppRep = AppRepository{rxClient: DbClient}
|
||||
DomainRep = DomainRepository{rxClient: DbClient}
|
||||
ServiceRep = ServiceRepository{rxClient: DbClient}
|
||||
SystemRep = SystemRepository{rxClient: DbClient}
|
||||
TokenRep = TokenRepository{rxClient: DbClient}
|
||||
AccessListRep = AccessListRepository{rxClient: DbClient}
|
||||
)
|
||||
Reference in new issue
Block a user