remove interfaces
This commit is contained in:
@@ -8,25 +8,15 @@ import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type RoleDao interface {
|
||||
GetByFilter(context.Context, dto.RoleRequestFilter, request.PageFilter) ([]*models.SysRole, uint64, error)
|
||||
FindByID(context.Context, uint64) (*models.SysRole, error)
|
||||
Create(context.Context, *models.SysRole) (*models.SysRole, error)
|
||||
UpdateByID(context.Context, *models.SysRole) (*models.SysRole, error)
|
||||
DeleteByID(context.Context, uint64) error
|
||||
DeletePermanentlyByID(context.Context, uint64) error
|
||||
All(context.Context) ([]*models.SysRole, error)
|
||||
}
|
||||
|
||||
type roleDaoImpl struct {
|
||||
type RoleDao struct {
|
||||
query *query.Query
|
||||
}
|
||||
|
||||
func NewRoleDao(query *query.Query) RoleDao {
|
||||
return &roleDaoImpl{query: query}
|
||||
func NewRoleDao(query *query.Query) *RoleDao {
|
||||
return &RoleDao{query: query}
|
||||
}
|
||||
|
||||
func (dao *roleDaoImpl) GetByFilter(ctx context.Context, filter dto.RoleRequestFilter, page request.PageFilter) ([]*models.SysRole, uint64, error) {
|
||||
func (dao *RoleDao) GetByFilter(ctx context.Context, filter dto.RoleRequestFilter, page request.PageFilter) ([]*models.SysRole, uint64, error) {
|
||||
role := dao.query.SysRole
|
||||
query := role.WithContext(ctx)
|
||||
|
||||
@@ -55,17 +45,17 @@ func (dao *roleDaoImpl) GetByFilter(ctx context.Context, filter dto.RoleRequestF
|
||||
return items, uint64(total), nil
|
||||
}
|
||||
|
||||
func (dao *roleDaoImpl) All(ctx context.Context) ([]*models.SysRole, error) {
|
||||
func (dao *RoleDao) All(ctx context.Context) ([]*models.SysRole, error) {
|
||||
role := dao.query.SysRole
|
||||
return role.WithContext(ctx).Find()
|
||||
}
|
||||
|
||||
func (dao *roleDaoImpl) FindByID(ctx context.Context, id uint64) (*models.SysRole, error) {
|
||||
func (dao *RoleDao) FindByID(ctx context.Context, id uint64) (*models.SysRole, error) {
|
||||
role := dao.query.SysRole
|
||||
return role.WithContext(ctx).Where(role.ID.Eq(id)).First()
|
||||
}
|
||||
|
||||
func (dao *roleDaoImpl) Create(ctx context.Context, model *models.SysRole) (*models.SysRole, error) {
|
||||
func (dao *RoleDao) Create(ctx context.Context, model *models.SysRole) (*models.SysRole, error) {
|
||||
role := dao.query.SysRole
|
||||
if err := role.WithContext(ctx).Create(model); err != nil {
|
||||
return nil, err
|
||||
@@ -73,7 +63,7 @@ func (dao *roleDaoImpl) Create(ctx context.Context, model *models.SysRole) (*mod
|
||||
return model, nil
|
||||
}
|
||||
|
||||
func (dao *roleDaoImpl) UpdateByID(ctx context.Context, model *models.SysRole) (*models.SysRole, error) {
|
||||
func (dao *RoleDao) UpdateByID(ctx context.Context, model *models.SysRole) (*models.SysRole, error) {
|
||||
role := dao.query.SysRole
|
||||
_, err := role.WithContext(ctx).Where(role.ID.Eq(model.ID)).Updates(model)
|
||||
if err != nil {
|
||||
@@ -82,13 +72,13 @@ func (dao *roleDaoImpl) UpdateByID(ctx context.Context, model *models.SysRole) (
|
||||
return model, nil
|
||||
}
|
||||
|
||||
func (dao *roleDaoImpl) DeleteByID(ctx context.Context, id uint64) error {
|
||||
func (dao *RoleDao) DeleteByID(ctx context.Context, id uint64) error {
|
||||
role := dao.query.SysRole
|
||||
_, err := role.WithContext(ctx).Where(role.ID.Eq(id)).Delete()
|
||||
return err
|
||||
}
|
||||
|
||||
func (dao *roleDaoImpl) DeletePermanentlyByID(ctx context.Context, id uint64) error {
|
||||
func (dao *RoleDao) DeletePermanentlyByID(ctx context.Context, id uint64) error {
|
||||
role := dao.query.SysRole
|
||||
_, err := role.WithContext(ctx).Unscoped().Where(role.ID.Eq(id)).Delete()
|
||||
return err
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
type RoleInjectParams struct {
|
||||
dig.In
|
||||
DB *gorm.DB
|
||||
Dao RoleDao
|
||||
Dao *RoleDao
|
||||
Query *query.Query
|
||||
Faker *gofakeit.Faker
|
||||
}
|
||||
|
||||
@@ -6,24 +6,20 @@ import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type UserDao interface {
|
||||
Create(context.Context, *models.User) (*models.User, error)
|
||||
}
|
||||
|
||||
type userDaoImpl struct {
|
||||
type UserDao struct {
|
||||
query *query.Query
|
||||
}
|
||||
|
||||
func NewUserDao(query *query.Query) UserDao {
|
||||
return &userDaoImpl{query: query}
|
||||
func NewUserDao(query *query.Query) *UserDao {
|
||||
return &UserDao{query: query}
|
||||
}
|
||||
|
||||
func (dao *userDaoImpl) FindByID(ctx context.Context, id uint64) (*models.User, error) {
|
||||
func (dao *UserDao) FindByID(ctx context.Context, id uint64) (*models.User, error) {
|
||||
user := dao.query.User
|
||||
return user.WithContext(ctx).Where(user.ID.Eq(id)).First()
|
||||
}
|
||||
|
||||
func (dao *userDaoImpl) Create(ctx context.Context, model *models.User) (*models.User, error) {
|
||||
func (dao *UserDao) Create(ctx context.Context, model *models.User) (*models.User, error) {
|
||||
user := dao.query.User
|
||||
if err := user.WithContext(ctx).Create(model); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -6,28 +6,21 @@ import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type UserRoleDao interface {
|
||||
Exists(context.Context, int) bool
|
||||
Create(context.Context, int, int) error
|
||||
Update(context.Context, int, int) error
|
||||
Delete(context.Context, int, int) error
|
||||
}
|
||||
|
||||
type userRoleDaoImpl struct {
|
||||
type UserRoleDao struct {
|
||||
query *query.Query
|
||||
}
|
||||
|
||||
func NewUserRoleDao(query *query.Query) UserRoleDao {
|
||||
return &userRoleDaoImpl{query: query}
|
||||
func NewUserRoleDao(query *query.Query) *UserRoleDao {
|
||||
return &UserRoleDao{query: query}
|
||||
}
|
||||
|
||||
func (dao *userRoleDaoImpl) Exists(ctx context.Context, userID int) bool {
|
||||
func (dao *UserRoleDao) Exists(ctx context.Context, userID int) bool {
|
||||
userRole := dao.query.UserRole
|
||||
count, _ := userRole.WithContext(ctx).Where(userRole.UserID.Eq(uint64(userID))).Count()
|
||||
return count > 0
|
||||
}
|
||||
|
||||
func (dao *userRoleDaoImpl) Create(ctx context.Context, userID, roleID int) error {
|
||||
func (dao *UserRoleDao) Create(ctx context.Context, userID, roleID int) error {
|
||||
userRole := dao.query.UserRole
|
||||
return userRole.WithContext(ctx).Create(&models.UserRole{
|
||||
UserID: uint64(userID),
|
||||
@@ -35,13 +28,13 @@ func (dao *userRoleDaoImpl) Create(ctx context.Context, userID, roleID int) erro
|
||||
})
|
||||
}
|
||||
|
||||
func (dao *userRoleDaoImpl) Update(ctx context.Context, userID, roleID int) error {
|
||||
func (dao *UserRoleDao) Update(ctx context.Context, userID, roleID int) error {
|
||||
userRole := dao.query.UserRole
|
||||
_, err := userRole.WithContext(ctx).Where(userRole.UserID.Eq(uint64(userID))).Update(userRole.RoleID, roleID)
|
||||
return err
|
||||
}
|
||||
|
||||
func (dao *userRoleDaoImpl) Delete(ctx context.Context, userID, roleID int) error {
|
||||
func (dao *UserRoleDao) Delete(ctx context.Context, userID, roleID int) error {
|
||||
userRole := dao.query.UserRole
|
||||
_, err := userRole.WithContext(ctx).
|
||||
Where(userRole.UserID.Eq(uint64(userID))).
|
||||
|
||||
@@ -24,7 +24,7 @@ type UserRoleInjectParams struct {
|
||||
dig.In
|
||||
|
||||
DB *gorm.DB
|
||||
Dao UserRoleDao
|
||||
Dao *UserRoleDao
|
||||
Query *query.Query
|
||||
Faker *gofakeit.Faker
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ type UserInjectParams struct {
|
||||
dig.In
|
||||
|
||||
DB *gorm.DB
|
||||
Dao UserDao
|
||||
Dao *UserDao
|
||||
Query *query.Query
|
||||
Faker *gofakeit.Faker
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user