作者 tangxvhui

更新结构

... ... @@ -14,3 +14,12 @@ func CreatePartnerInfoRepository(options map[string]interface{}) (domain.Partner
}
return repository.NewPartnerInfoRepository(transactionContext)
}
//CreateAdminUserRepository 管理员信息
func CreateAdminUserRepository(options map[string]interface{}) (domain.AdminUserRepository, error) {
var transactionContext *transaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*transaction.TransactionContext)
}
return repository.NewAdminUserRepository(transactionContext)
}
... ...
... ... @@ -32,8 +32,8 @@ type AdminUserFindOneQuery struct {
}
type AdminUserRepository interface {
Save(*AdminUser) (*AdminUser, error)
Remove(user *AdminUser) (*AdminUser, error)
// Save(*AdminUser) (*AdminUser, error)
// Remove(user *AdminUser) (*AdminUser, error)
FindOne(qureyOptions AdminUserFindOneQuery) (*AdminUser, error)
Find(queryOptions AdminUserFindQuery) (int, []AdminUser, error)
// Find(queryOptions AdminUserFindQuery) (int, []*AdminUser, error)
}
... ...
... ... @@ -19,8 +19,9 @@ type AdminUser struct {
Password string
//是否是默认账号
IsDefault bool `pg:",use_zero"`
//删除时间
DeleteAt int64
//账号是否可用
IsUsable bool `json:"is_userable"`
CreateAt time.Time
UpdateAt time.Time
}
... ... @@ -37,6 +38,5 @@ var _ pg.BeforeInsertHook = (*AdminUser)(nil)
func (user *AdminUser) BeforeInsert(ctx context.Context) (context.Context, error) {
user.CreateAt = time.Now()
user.UpdateAt = time.Now()
user.DeleteAt = 0
return ctx, nil
}
... ...
package repository
import (
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
)
type AdminUserRepository struct {
transactionContext *transaction.TransactionContext
}
var (
_ domain.AdminUserRepository = (*AdminUserRepository)(nil)
)
func NewAdminUserRepository(transactionContext *transaction.TransactionContext) (*AdminUserRepository, error) {
if transactionContext == nil {
return nil, ERR_EMPTY_TC
}
return &AdminUserRepository{transactionContext: transactionContext}, nil
}
func (reponsitory AdminUserRepository) transformPgModelToDomainModel(adminuserModel *models.AdminUser) (domain.AdminUser, error) {
result := domain.AdminUser{}
return result, nil
}
func (reponsitory AdminUserRepository) FindOne(queryOption domain.AdminUserFindOneQuery) (*domain.AdminUser, error) {
db := reponsitory.transactionContext.PgDd
adminuserModel := new(models.AdminUser)
query := db.Model(adminuserModel)
if queryOption.AdminUserId > 0 {
query = query.Where("id=?", queryOption.AdminUserId)
}
if len(queryOption.AccountEqual) > 0 {
query = query.Where("admin_account=?", queryOption.AccountEqual)
}
err := query.First()
if err != nil {
return nil, err
}
adminUser, err := reponsitory.transformPgModelToDomainModel(adminuserModel)
return &adminUser, err
}
... ...
... ... @@ -4,10 +4,13 @@ import (
"github.com/astaxie/beego/context"
)
//根据权限编码检验请求是否可以执行
func PermissionCheck(permissionCode string, excludeUrl ...string) func(ctx *context.Context) {
//PermissionCheck 根据权限编码检验请求是否可以执行
//permissionCode:权限编码
//excludeURL:跳过url
func AdminPermissionCheck(permissionCode string, excludeURL ...string) func(ctx *context.Context) {
return func(ctx *context.Context) {
//根据code检查权限数据,并排除excludeUrl指定的url
//获取user 数据
}
}
... ...
... ... @@ -9,7 +9,7 @@ import (
func init() {
adminRouter := beego.NewNamespace("/admin_user",
//验证权限
beego.NSBefore(middleware.PermissionCheck(domain.PERMINSSION_ADMIN_USER)),
beego.NSBefore(middleware.AdminPermissionCheck(domain.PERMINSSION_ADMIN_USER)),
//其余的路由
//...
)
... ...