pg_admin_user_reponsitory.go
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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"
. "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/utils"
)
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
}