pg_company_reponsitory.go
2.4 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package repository
import (
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/pg/transaction"
)
type CompanyRepository struct {
transactionContext *transaction.TransactionContext
}
var (
_ domain.CompanyRepository = (*CompanyRepository)(nil)
)
func NewCompanyRepository(transactionContext *transaction.TransactionContext) (*CompanyRepository, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
}
return &CompanyRepository{transactionContext: transactionContext}, nil
}
func (repository CompanyRepository) transformPgModelToDomainModel(m *models.Company) (domain.Company, error) {
return domain.Company{
Id: m.Id,
Name: m.Name,
Phone: m.Phone,
Logo: m.Logo,
Remarks: m.Remarks,
AdminCompanyId: m.AdminCompanyId,
Status: m.Status,
Enable: m.Enable,
CreateAt: m.CreateAt,
UpdateAt: m.UpdateAt,
}, nil
}
func (reponsitory CompanyRepository) Add(m *domain.Company) error {
var (
err error
tx = reponsitory.transactionContext.PgTx
)
companyModel := models.Company{
Id: m.Id,
Name: m.Name,
Phone: m.Phone,
Logo: m.Logo,
Remarks: m.Remarks,
AdminCompanyId: m.AdminCompanyId,
Status: m.Status,
Enable: m.Enable,
CreateAt: m.CreateAt,
UpdateAt: m.UpdateAt,
}
_, err = tx.Model(&companyModel).Insert()
return err
}
func (reponsitory CompanyRepository) Edit(m *domain.Company) error {
var (
err error
tx = reponsitory.transactionContext.PgTx
)
companyModel := models.Company{
Id: m.Id,
Name: m.Name,
Phone: m.Phone,
Logo: m.Logo,
Remarks: m.Remarks,
AdminCompanyId: m.AdminCompanyId,
Status: m.Status,
Enable: m.Enable,
CreateAt: m.CreateAt,
DeleteAt: m.DeleteAt,
UpdateAt: m.UpdateAt,
}
_, err = tx.Model(&companyModel).Update()
return err
}
func (reponsitory CompanyRepository) FindOne(queryOptions map[string]interface{}) (domain.Company, error) {
return domain.Company{}, nil
}
func (reponsitory CompanyRepository) Find(queryOptions map[string]interface{}) (int64, []domain.Company, error) {
return 0, nil, nil
}