Merge remote-tracking branch 'origin/dev' into dev
正在显示
24 个修改的文件
包含
1250 行增加
和
59 行删除
cmd/discuss/doc/dsl/api/department.api
0 → 100644
1 | + | ||
2 | +syntax = "v1" | ||
3 | + | ||
4 | +info( | ||
5 | + title: "xx实例" | ||
6 | + desc: "xx实例" | ||
7 | + author: "author" | ||
8 | + email: "email" | ||
9 | + version: "v1" | ||
10 | +) | ||
11 | + | ||
12 | +@server( | ||
13 | + prefix: department/v1 | ||
14 | + group: department | ||
15 | + jwt: JwtAuth | ||
16 | +) | ||
17 | +service Core { | ||
18 | + @handler getDepartment | ||
19 | + post /department/:id (DepartmentGetRequest) returns (DepartmentGetResponse) | ||
20 | + @handler saveDepartment | ||
21 | + post /department (DepartmentSaveRequest) returns (DepartmentSaveResponse) | ||
22 | + @handler deleteDepartment | ||
23 | + delete /department/:id (DepartmentDeleteRequest) returns (DepartmentDeleteResponse) | ||
24 | + @handler updateDepartment | ||
25 | + put /department/:id (DepartmentUpdateRequest) returns (DepartmentUpdateResponse) | ||
26 | + @handler searchDepartment | ||
27 | + post /department/search (DepartmentSearchRequest) returns (DepartmentSearchResponse) | ||
28 | +} | ||
29 | + | ||
30 | +type ( | ||
31 | + DepartmentGetRequest { | ||
32 | + Id int64 `path:"id"` | ||
33 | + } | ||
34 | + DepartmentGetResponse struct{ | ||
35 | + Department DepartmentItem `json:"department"` | ||
36 | + } | ||
37 | + | ||
38 | + DepartmentSaveRequest struct{ | ||
39 | + Department DepartmentItem `json:"department"` | ||
40 | + } | ||
41 | + DepartmentSaveResponse struct{} | ||
42 | + | ||
43 | + DepartmentDeleteRequest struct{ | ||
44 | + Id int64 `path:"id"` | ||
45 | + } | ||
46 | + DepartmentDeleteResponse struct{} | ||
47 | + | ||
48 | + DepartmentUpdateRequest struct{ | ||
49 | + Id int64 `path:"id"` | ||
50 | + Department DepartmentItem `json:"department"` | ||
51 | + } | ||
52 | + DepartmentUpdateResponse struct{} | ||
53 | + | ||
54 | + DepartmentSearchRequest struct{ | ||
55 | + Page int `json:"page"` | ||
56 | + Size int `json:"size"` | ||
57 | + } | ||
58 | + DepartmentSearchResponse{ | ||
59 | + List []DepartmentItem `json:"list"` | ||
60 | + Total int64 `json:"total"` | ||
61 | + } | ||
62 | + DepartmentItem struct{ | ||
63 | + | ||
64 | + } | ||
65 | +) |
cmd/discuss/doc/dsl/api/role.api
0 → 100644
1 | + | ||
2 | +syntax = "v1" | ||
3 | + | ||
4 | +info( | ||
5 | + title: "xx实例" | ||
6 | + desc: "xx实例" | ||
7 | + author: "author" | ||
8 | + email: "email" | ||
9 | + version: "v1" | ||
10 | +) | ||
11 | + | ||
12 | +@server( | ||
13 | + prefix: role/v1 | ||
14 | + group: role | ||
15 | + jwt: JwtAuth | ||
16 | +) | ||
17 | +service Core { | ||
18 | + @handler getRole | ||
19 | + post /role/:id (RoleGetRequest) returns (RoleGetResponse) | ||
20 | + @handler saveRole | ||
21 | + post /role (RoleSaveRequest) returns (RoleSaveResponse) | ||
22 | + @handler deleteRole | ||
23 | + delete /role/:id (RoleDeleteRequest) returns (RoleDeleteResponse) | ||
24 | + @handler updateRole | ||
25 | + put /role/:id (RoleUpdateRequest) returns (RoleUpdateResponse) | ||
26 | + @handler searchRole | ||
27 | + post /role/search (RoleSearchRequest) returns (RoleSearchResponse) | ||
28 | +} | ||
29 | + | ||
30 | +type ( | ||
31 | + RoleGetRequest { | ||
32 | + Id int64 `path:"id"` | ||
33 | + } | ||
34 | + RoleGetResponse struct{ | ||
35 | + Role RoleItem `json:"role"` | ||
36 | + } | ||
37 | + | ||
38 | + RoleSaveRequest struct{ | ||
39 | + Role RoleItem `json:"role"` | ||
40 | + } | ||
41 | + RoleSaveResponse struct{} | ||
42 | + | ||
43 | + RoleDeleteRequest struct{ | ||
44 | + Id int64 `path:"id"` | ||
45 | + } | ||
46 | + RoleDeleteResponse struct{} | ||
47 | + | ||
48 | + RoleUpdateRequest struct{ | ||
49 | + Id int64 `path:"id"` | ||
50 | + Role RoleItem `json:"role"` | ||
51 | + } | ||
52 | + RoleUpdateResponse struct{} | ||
53 | + | ||
54 | + RoleSearchRequest struct{ | ||
55 | + Page int `json:"page"` | ||
56 | + Size int `json:"size"` | ||
57 | + } | ||
58 | + RoleSearchResponse{ | ||
59 | + List []RoleItem `json:"list"` | ||
60 | + Total int64 `json:"total"` | ||
61 | + } | ||
62 | + RoleItem struct{ | ||
63 | + | ||
64 | + } | ||
65 | +) |
cmd/discuss/doc/dsl/api/user.api
0 → 100644
1 | + | ||
2 | +syntax = "v1" | ||
3 | + | ||
4 | +info( | ||
5 | + title: "xx实例" | ||
6 | + desc: "xx实例" | ||
7 | + author: "author" | ||
8 | + email: "email" | ||
9 | + version: "v1" | ||
10 | +) | ||
11 | + | ||
12 | +@server( | ||
13 | + prefix: user/v1 | ||
14 | + group: user | ||
15 | + jwt: JwtAuth | ||
16 | +) | ||
17 | +service Core { | ||
18 | + @handler getUser | ||
19 | + post /user/:id (UserGetRequest) returns (UserGetResponse) | ||
20 | + @handler saveUser | ||
21 | + post /user (UserSaveRequest) returns (UserSaveResponse) | ||
22 | + @handler deleteUser | ||
23 | + delete /user/:id (UserDeleteRequest) returns (UserDeleteResponse) | ||
24 | + @handler updateUser | ||
25 | + put /user/:id (UserUpdateRequest) returns (UserUpdateResponse) | ||
26 | + @handler searchUser | ||
27 | + post /user/search (UserSearchRequest) returns (UserSearchResponse) | ||
28 | +} | ||
29 | + | ||
30 | +type ( | ||
31 | + UserGetRequest { | ||
32 | + Id int64 `path:"id"` | ||
33 | + } | ||
34 | + UserGetResponse struct{ | ||
35 | + User UserItem `json:"user"` | ||
36 | + } | ||
37 | + | ||
38 | + UserSaveRequest struct{ | ||
39 | + User UserItem `json:"user"` | ||
40 | + } | ||
41 | + UserSaveResponse struct{} | ||
42 | + | ||
43 | + UserDeleteRequest struct{ | ||
44 | + Id int64 `path:"id"` | ||
45 | + } | ||
46 | + UserDeleteResponse struct{} | ||
47 | + | ||
48 | + UserUpdateRequest struct{ | ||
49 | + Id int64 `path:"id"` | ||
50 | + User UserItem `json:"user"` | ||
51 | + } | ||
52 | + UserUpdateResponse struct{} | ||
53 | + | ||
54 | + UserSearchRequest struct{ | ||
55 | + Page int `json:"page"` | ||
56 | + Size int `json:"size"` | ||
57 | + } | ||
58 | + UserSearchResponse{ | ||
59 | + List []UserItem `json:"list"` | ||
60 | + Total int64 `json:"total"` | ||
61 | + } | ||
62 | + UserItem struct{ | ||
63 | + | ||
64 | + } | ||
65 | +) |
cmd/discuss/doc/dsl/rpc/department.proto
0 → 100644
1 | + | ||
2 | +syntax = "proto3"; | ||
3 | + | ||
4 | +option go_package ="./pb"; | ||
5 | + | ||
6 | +package pb; | ||
7 | + | ||
8 | +message DepartmentGetReq { | ||
9 | + int64 Id = 1; | ||
10 | +} | ||
11 | +message DepartmentGetResp{ | ||
12 | + DepartmentItem User = 1; | ||
13 | +} | ||
14 | + | ||
15 | +message DepartmentSaveReq { | ||
16 | + | ||
17 | +} | ||
18 | +message DepartmentSaveResp{ | ||
19 | + | ||
20 | +} | ||
21 | + | ||
22 | +message DepartmentDeleteReq { | ||
23 | + int64 Id = 1; | ||
24 | +} | ||
25 | +message DepartmentDeleteResp{ | ||
26 | + | ||
27 | +} | ||
28 | + | ||
29 | +message DepartmentUpdateReq { | ||
30 | + int64 Id = 1; | ||
31 | +} | ||
32 | +message DepartmentUpdateResp{ | ||
33 | + | ||
34 | +} | ||
35 | + | ||
36 | +message DepartmentSearchReq { | ||
37 | + int64 PageNumber = 1; | ||
38 | + int64 PageSize = 2; | ||
39 | +} | ||
40 | +message DepartmentSearchResp{ | ||
41 | + repeated DepartmentItem List =1; | ||
42 | + int64 Total =2; | ||
43 | +} | ||
44 | +message DepartmentItem { | ||
45 | + | ||
46 | +} | ||
47 | + | ||
48 | +service DepartmentService { | ||
49 | + rpc DepartmentGet(DepartmentGetReq) returns(DepartmentGetResp); | ||
50 | + rpc DepartmentSave(DepartmentSaveReq) returns(DepartmentSaveResp); | ||
51 | + rpc DepartmentDelete(DepartmentDeleteReq) returns(DepartmentDeleteResp); | ||
52 | + rpc DepartmentUpdate(DepartmentUpdateReq) returns(DepartmentUpdateResp); | ||
53 | + rpc DepartmentSearch(DepartmentSearchReq) returns(DepartmentSearchResp); | ||
54 | +} |
cmd/discuss/doc/dsl/rpc/role.proto
0 → 100644
1 | + | ||
2 | +syntax = "proto3"; | ||
3 | + | ||
4 | +option go_package ="./pb"; | ||
5 | + | ||
6 | +package pb; | ||
7 | + | ||
8 | +message RoleGetReq { | ||
9 | + int64 Id = 1; | ||
10 | +} | ||
11 | +message RoleGetResp{ | ||
12 | + RoleItem User = 1; | ||
13 | +} | ||
14 | + | ||
15 | +message RoleSaveReq { | ||
16 | + | ||
17 | +} | ||
18 | +message RoleSaveResp{ | ||
19 | + | ||
20 | +} | ||
21 | + | ||
22 | +message RoleDeleteReq { | ||
23 | + int64 Id = 1; | ||
24 | +} | ||
25 | +message RoleDeleteResp{ | ||
26 | + | ||
27 | +} | ||
28 | + | ||
29 | +message RoleUpdateReq { | ||
30 | + int64 Id = 1; | ||
31 | +} | ||
32 | +message RoleUpdateResp{ | ||
33 | + | ||
34 | +} | ||
35 | + | ||
36 | +message RoleSearchReq { | ||
37 | + int64 PageNumber = 1; | ||
38 | + int64 PageSize = 2; | ||
39 | +} | ||
40 | +message RoleSearchResp{ | ||
41 | + repeated RoleItem List =1; | ||
42 | + int64 Total =2; | ||
43 | +} | ||
44 | +message RoleItem { | ||
45 | + | ||
46 | +} | ||
47 | + | ||
48 | +service RoleService { | ||
49 | + rpc RoleGet(RoleGetReq) returns(RoleGetResp); | ||
50 | + rpc RoleSave(RoleSaveReq) returns(RoleSaveResp); | ||
51 | + rpc RoleDelete(RoleDeleteReq) returns(RoleDeleteResp); | ||
52 | + rpc RoleUpdate(RoleUpdateReq) returns(RoleUpdateResp); | ||
53 | + rpc RoleSearch(RoleSearchReq) returns(RoleSearchResp); | ||
54 | +} |
cmd/discuss/doc/dsl/rpc/user.proto
0 → 100644
1 | + | ||
2 | +syntax = "proto3"; | ||
3 | + | ||
4 | +option go_package ="./pb"; | ||
5 | + | ||
6 | +package pb; | ||
7 | + | ||
8 | +message UserGetReq { | ||
9 | + int64 Id = 1; | ||
10 | +} | ||
11 | +message UserGetResp{ | ||
12 | + UserItem User = 1; | ||
13 | +} | ||
14 | + | ||
15 | +message UserSaveReq { | ||
16 | + | ||
17 | +} | ||
18 | +message UserSaveResp{ | ||
19 | + | ||
20 | +} | ||
21 | + | ||
22 | +message UserDeleteReq { | ||
23 | + int64 Id = 1; | ||
24 | +} | ||
25 | +message UserDeleteResp{ | ||
26 | + | ||
27 | +} | ||
28 | + | ||
29 | +message UserUpdateReq { | ||
30 | + int64 Id = 1; | ||
31 | +} | ||
32 | +message UserUpdateResp{ | ||
33 | + | ||
34 | +} | ||
35 | + | ||
36 | +message UserSearchReq { | ||
37 | + int64 PageNumber = 1; | ||
38 | + int64 PageSize = 2; | ||
39 | +} | ||
40 | +message UserSearchResp{ | ||
41 | + repeated UserItem List =1; | ||
42 | + int64 Total =2; | ||
43 | +} | ||
44 | +message UserItem { | ||
45 | + | ||
46 | +} | ||
47 | + | ||
48 | +service UserService { | ||
49 | + rpc UserGet(UserGetReq) returns(UserGetResp); | ||
50 | + rpc UserSave(UserSaveReq) returns(UserSaveResp); | ||
51 | + rpc UserDelete(UserDeleteReq) returns(UserDeleteResp); | ||
52 | + rpc UserUpdate(UserUpdateReq) returns(UserUpdateResp); | ||
53 | + rpc UserSearch(UserSearchReq) returns(UserSearchResp); | ||
54 | +} |
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
6 | + "gorm.io/gorm" | ||
7 | +) | ||
8 | + | ||
9 | +type Department struct { | ||
10 | + Id int64 // 唯一标识 | ||
11 | + | ||
12 | + CreatedAt int64 `json:"createdAt,omitempty"` | ||
13 | + UpdatedAt int64 `json:"updatedAt,omitempty"` | ||
14 | + DeletedAt int64 `json:"deletedAt,omitempty"` | ||
15 | + Version int `json:"version,omitempty"` | ||
16 | +} | ||
17 | + | ||
18 | +func (m *Department) TableName() string { | ||
19 | + return "department" | ||
20 | +} | ||
21 | + | ||
22 | +func (m *Department) BeforeCreate(tx *gorm.DB) (err error) { | ||
23 | + // m.CreatedAt = time.Now().Unix() | ||
24 | + // m.UpdatedAt = time.Now().Unix() | ||
25 | + return | ||
26 | +} | ||
27 | + | ||
28 | +func (m *Department) BeforeUpdate(tx *gorm.DB) (err error) { | ||
29 | + // m.UpdatedAt = time.Now().Unix() | ||
30 | + return | ||
31 | +} | ||
32 | + | ||
33 | +func (m *Department) CacheKeyFunc() string { | ||
34 | + if m.Id == 0 { | ||
35 | + return "" | ||
36 | + } | ||
37 | + return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id) | ||
38 | +} | ||
39 | + | ||
40 | +func (m *Department) CacheKeyFuncByObject(obj interface{}) string { | ||
41 | + if v, ok := obj.(*Department); ok { | ||
42 | + return v.CacheKeyFunc() | ||
43 | + } | ||
44 | + return "" | ||
45 | +} | ||
46 | + | ||
47 | +func (m *Department) CachePrimaryKeyFunc() string { | ||
48 | + if len("") == 0 { | ||
49 | + return "" | ||
50 | + } | ||
51 | + return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key") | ||
52 | +} |
cmd/discuss/interanl/pkg/db/models/role.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
6 | + "gorm.io/gorm" | ||
7 | + "time" | ||
8 | +) | ||
9 | + | ||
10 | +type Role struct { | ||
11 | + Id int64 // 唯一标识 | ||
12 | + | ||
13 | + CreatedAt int64 `json:"createdAt,omitempty"` | ||
14 | + UpdatedAt int64 `json:"updatedAt,omitempty"` | ||
15 | + DeletedAt int64 `json:"deletedAt,omitempty"` | ||
16 | + Version int `json:"version,omitempty"` | ||
17 | +} | ||
18 | + | ||
19 | +func (m *Role) TableName() string { | ||
20 | + return "role" | ||
21 | +} | ||
22 | + | ||
23 | +func (m *Role) BeforeCreate(tx *gorm.DB) (err error) { | ||
24 | + m.CreatedAt = time.Now().Unix() | ||
25 | + m.UpdatedAt = time.Now().Unix() | ||
26 | + return | ||
27 | +} | ||
28 | + | ||
29 | +func (m *Role) BeforeUpdate(tx *gorm.DB) (err error) { | ||
30 | + m.UpdatedAt = time.Now().Unix() | ||
31 | + return | ||
32 | +} | ||
33 | + | ||
34 | +func (m *Role) CacheKeyFunc() string { | ||
35 | + if m.Id == 0 { | ||
36 | + return "" | ||
37 | + } | ||
38 | + return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id) | ||
39 | +} | ||
40 | + | ||
41 | +func (m *Role) CacheKeyFuncByObject(obj interface{}) string { | ||
42 | + if v, ok := obj.(*Role); ok { | ||
43 | + return v.CacheKeyFunc() | ||
44 | + } | ||
45 | + return "" | ||
46 | +} | ||
47 | + | ||
48 | +func (m *Role) CachePrimaryKeyFunc() string { | ||
49 | + if len("") == 0 { | ||
50 | + return "" | ||
51 | + } | ||
52 | + return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key") | ||
53 | +} |
cmd/discuss/interanl/pkg/db/models/user.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
6 | + "gorm.io/gorm" | ||
7 | + "time" | ||
8 | +) | ||
9 | + | ||
10 | +type User struct { | ||
11 | + Id int64 // 唯一标识 | ||
12 | + | ||
13 | + CreatedAt int64 `json:"createdAt,omitempty"` | ||
14 | + UpdatedAt int64 `json:"updatedAt,omitempty"` | ||
15 | + DeletedAt int64 `json:"deletedAt,omitempty"` | ||
16 | + Version int `json:"version,omitempty"` | ||
17 | +} | ||
18 | + | ||
19 | +func (m *User) TableName() string { | ||
20 | + return "user" | ||
21 | +} | ||
22 | + | ||
23 | +func (m *User) BeforeCreate(tx *gorm.DB) (err error) { | ||
24 | + m.CreatedAt = time.Now().Unix() | ||
25 | + m.UpdatedAt = time.Now().Unix() | ||
26 | + return | ||
27 | +} | ||
28 | + | ||
29 | +func (m *User) BeforeUpdate(tx *gorm.DB) (err error) { | ||
30 | + m.UpdatedAt = time.Now().Unix() | ||
31 | + return | ||
32 | +} | ||
33 | + | ||
34 | +func (m *User) CacheKeyFunc() string { | ||
35 | + if m.Id == 0 { | ||
36 | + return "" | ||
37 | + } | ||
38 | + return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id) | ||
39 | +} | ||
40 | + | ||
41 | +func (m *User) CacheKeyFuncByObject(obj interface{}) string { | ||
42 | + if v, ok := obj.(*User); ok { | ||
43 | + return v.CacheKeyFunc() | ||
44 | + } | ||
45 | + return "" | ||
46 | +} | ||
47 | + | ||
48 | +func (m *User) CachePrimaryKeyFunc() string { | ||
49 | + if len("") == 0 { | ||
50 | + return "" | ||
51 | + } | ||
52 | + return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key") | ||
53 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + "github.com/jinzhu/copier" | ||
6 | + "github.com/pkg/errors" | ||
7 | + "github.com/tiptok/gocomm/pkg/cache" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/models" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
11 | + "gorm.io/gorm" | ||
12 | +) | ||
13 | + | ||
14 | +type DepartmentRepository struct { | ||
15 | + *cache.CachedRepository | ||
16 | +} | ||
17 | + | ||
18 | +func (repository *DepartmentRepository) Insert(ctx context.Context, conn transaction.Conn, dm *domain.Department) (*domain.Department, error) { | ||
19 | + var ( | ||
20 | + err error | ||
21 | + m = &models.Department{} | ||
22 | + tx = conn.DB() | ||
23 | + ) | ||
24 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
25 | + return nil, err | ||
26 | + } | ||
27 | + if tx = tx.Model(m).Save(m); tx.Error != nil { | ||
28 | + return nil, tx.Error | ||
29 | + } | ||
30 | + dm.Id = m.Id | ||
31 | + return repository.ModelToDomainModel(m) | ||
32 | + | ||
33 | +} | ||
34 | + | ||
35 | +func (repository *DepartmentRepository) Update(ctx context.Context, conn transaction.Conn, dm *domain.Department) (*domain.Department, error) { | ||
36 | + var ( | ||
37 | + err error | ||
38 | + m *models.Department | ||
39 | + tx = conn.DB() | ||
40 | + ) | ||
41 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
42 | + return nil, err | ||
43 | + } | ||
44 | + queryFunc := func() (interface{}, error) { | ||
45 | + tx = tx.Model(m).Updates(m) | ||
46 | + return nil, tx.Error | ||
47 | + } | ||
48 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
49 | + return nil, err | ||
50 | + } | ||
51 | + return repository.ModelToDomainModel(m) | ||
52 | +} | ||
53 | + | ||
54 | +func (repository *DepartmentRepository) UpdateWithVersion(ctx context.Context, transaction transaction.Conn, dm *domain.Department) (*domain.Department, error) { | ||
55 | + var ( | ||
56 | + err error | ||
57 | + m *models.Department | ||
58 | + tx = transaction.DB() | ||
59 | + ) | ||
60 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
61 | + return nil, err | ||
62 | + } | ||
63 | + oldVersion := dm.Version | ||
64 | + m.Version += 1 | ||
65 | + queryFunc := func() (interface{}, error) { | ||
66 | + tx = tx.Model(m).Select("*").Where("id = ?", m.Id).Where("version = ?", oldVersion).Updates(m) | ||
67 | + if tx.RowsAffected == 0 { | ||
68 | + return nil, domain.ErrUpdateFail | ||
69 | + } | ||
70 | + return nil, tx.Error | ||
71 | + } | ||
72 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
73 | + return nil, err | ||
74 | + } | ||
75 | + return repository.ModelToDomainModel(m) | ||
76 | +} | ||
77 | + | ||
78 | +func (repository *DepartmentRepository) Delete(ctx context.Context, conn transaction.Conn, dm *domain.Department) (*domain.Department, error) { | ||
79 | + var ( | ||
80 | + tx = conn.DB() | ||
81 | + m = &models.Department{Id: dm.Identify().(int64)} | ||
82 | + ) | ||
83 | + queryFunc := func() (interface{}, error) { | ||
84 | + tx = tx.Where("id = ?", m.Id).Delete(m) | ||
85 | + return m, tx.Error | ||
86 | + } | ||
87 | + if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
88 | + return dm, err | ||
89 | + } | ||
90 | + return repository.ModelToDomainModel(m) | ||
91 | +} | ||
92 | + | ||
93 | +func (repository *DepartmentRepository) FindOne(ctx context.Context, conn transaction.Conn, id int64) (*domain.Department, error) { | ||
94 | + var ( | ||
95 | + err error | ||
96 | + tx = conn.DB() | ||
97 | + m = new(models.Department) | ||
98 | + ) | ||
99 | + queryFunc := func() (interface{}, error) { | ||
100 | + tx = tx.Model(m).Where("id = ?", id).First(m) | ||
101 | + if errors.Is(tx.Error, gorm.ErrRecordNotFound) { | ||
102 | + return nil, domain.ErrNotFound | ||
103 | + } | ||
104 | + return m, tx.Error | ||
105 | + } | ||
106 | + cacheModel := new(models.Department) | ||
107 | + cacheModel.Id = id | ||
108 | + if err = repository.QueryCache(cacheModel.CacheKeyFunc, m, queryFunc); err != nil { | ||
109 | + return nil, err | ||
110 | + } | ||
111 | + return repository.ModelToDomainModel(m) | ||
112 | +} | ||
113 | + | ||
114 | +func (repository *DepartmentRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.Department, error) { | ||
115 | + var ( | ||
116 | + tx = conn.DB() | ||
117 | + ms []*models.Department | ||
118 | + dms = make([]*domain.Department, 0) | ||
119 | + total int64 | ||
120 | + ) | ||
121 | + queryFunc := func() (interface{}, error) { | ||
122 | + tx = tx.Model(&ms).Order("id desc") | ||
123 | + if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | ||
124 | + return dms, tx.Error | ||
125 | + } | ||
126 | + return dms, nil | ||
127 | + } | ||
128 | + | ||
129 | + if _, err := repository.Query(queryFunc); err != nil { | ||
130 | + return 0, nil, err | ||
131 | + } | ||
132 | + | ||
133 | + for _, item := range ms { | ||
134 | + if dm, err := repository.ModelToDomainModel(item); err != nil { | ||
135 | + return 0, dms, err | ||
136 | + } else { | ||
137 | + dms = append(dms, dm) | ||
138 | + } | ||
139 | + } | ||
140 | + return total, dms, nil | ||
141 | +} | ||
142 | + | ||
143 | +func (repository *DepartmentRepository) ModelToDomainModel(from *models.Department) (*domain.Department, error) { | ||
144 | + to := &domain.Department{} | ||
145 | + err := copier.Copy(to, from) | ||
146 | + return to, err | ||
147 | +} | ||
148 | + | ||
149 | +func (repository *DepartmentRepository) DomainModelToModel(from *domain.Department) (*models.Department, error) { | ||
150 | + to := &models.Department{} | ||
151 | + err := copier.Copy(to, from) | ||
152 | + return to, err | ||
153 | +} | ||
154 | + | ||
155 | +func NewDepartmentRepository(cache *cache.CachedRepository) domain.DepartmentRepository { | ||
156 | + return &DepartmentRepository{CachedRepository: cache} | ||
157 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + "github.com/jinzhu/copier" | ||
6 | + "github.com/pkg/errors" | ||
7 | + "github.com/tiptok/gocomm/pkg/cache" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/models" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
11 | + "gorm.io/gorm" | ||
12 | +) | ||
13 | + | ||
14 | +type RoleRepository struct { | ||
15 | + *cache.CachedRepository | ||
16 | +} | ||
17 | + | ||
18 | +func (repository *RoleRepository) Insert(ctx context.Context, conn transaction.Conn, dm *domain.Role) (*domain.Role, error) { | ||
19 | + var ( | ||
20 | + err error | ||
21 | + m = &models.Role{} | ||
22 | + tx = conn.DB() | ||
23 | + ) | ||
24 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
25 | + return nil, err | ||
26 | + } | ||
27 | + if tx = tx.Model(m).Save(m); tx.Error != nil { | ||
28 | + return nil, tx.Error | ||
29 | + } | ||
30 | + dm.Id = m.Id | ||
31 | + return repository.ModelToDomainModel(m) | ||
32 | + | ||
33 | +} | ||
34 | + | ||
35 | +func (repository *RoleRepository) Update(ctx context.Context, conn transaction.Conn, dm *domain.Role) (*domain.Role, error) { | ||
36 | + var ( | ||
37 | + err error | ||
38 | + m *models.Role | ||
39 | + tx = conn.DB() | ||
40 | + ) | ||
41 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
42 | + return nil, err | ||
43 | + } | ||
44 | + queryFunc := func() (interface{}, error) { | ||
45 | + tx = tx.Model(m).Updates(m) | ||
46 | + return nil, tx.Error | ||
47 | + } | ||
48 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
49 | + return nil, err | ||
50 | + } | ||
51 | + return repository.ModelToDomainModel(m) | ||
52 | +} | ||
53 | + | ||
54 | +func (repository *RoleRepository) UpdateWithVersion(ctx context.Context, transaction transaction.Conn, dm *domain.Role) (*domain.Role, error) { | ||
55 | + var ( | ||
56 | + err error | ||
57 | + m *models.Role | ||
58 | + tx = transaction.DB() | ||
59 | + ) | ||
60 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
61 | + return nil, err | ||
62 | + } | ||
63 | + oldVersion := dm.Version | ||
64 | + m.Version += 1 | ||
65 | + queryFunc := func() (interface{}, error) { | ||
66 | + tx = tx.Model(m).Select("*").Where("id = ?", m.Id).Where("version = ?", oldVersion).Updates(m) | ||
67 | + if tx.RowsAffected == 0 { | ||
68 | + return nil, domain.ErrUpdateFail | ||
69 | + } | ||
70 | + return nil, tx.Error | ||
71 | + } | ||
72 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
73 | + return nil, err | ||
74 | + } | ||
75 | + return repository.ModelToDomainModel(m) | ||
76 | +} | ||
77 | + | ||
78 | +func (repository *RoleRepository) Delete(ctx context.Context, conn transaction.Conn, dm *domain.Role) (*domain.Role, error) { | ||
79 | + var ( | ||
80 | + tx = conn.DB() | ||
81 | + m = &models.Role{Id: dm.Identify().(int64)} | ||
82 | + ) | ||
83 | + queryFunc := func() (interface{}, error) { | ||
84 | + tx = tx.Where("id = ?", m.Id).Delete(m) | ||
85 | + return m, tx.Error | ||
86 | + } | ||
87 | + if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
88 | + return dm, err | ||
89 | + } | ||
90 | + return repository.ModelToDomainModel(m) | ||
91 | +} | ||
92 | + | ||
93 | +func (repository *RoleRepository) FindOne(ctx context.Context, conn transaction.Conn, id int64) (*domain.Role, error) { | ||
94 | + var ( | ||
95 | + err error | ||
96 | + tx = conn.DB() | ||
97 | + m = new(models.Role) | ||
98 | + ) | ||
99 | + queryFunc := func() (interface{}, error) { | ||
100 | + tx = tx.Model(m).Where("id = ?", id).First(m) | ||
101 | + if errors.Is(tx.Error, gorm.ErrRecordNotFound) { | ||
102 | + return nil, domain.ErrNotFound | ||
103 | + } | ||
104 | + return m, tx.Error | ||
105 | + } | ||
106 | + cacheModel := new(models.Role) | ||
107 | + cacheModel.Id = id | ||
108 | + if err = repository.QueryCache(cacheModel.CacheKeyFunc, m, queryFunc); err != nil { | ||
109 | + return nil, err | ||
110 | + } | ||
111 | + return repository.ModelToDomainModel(m) | ||
112 | +} | ||
113 | + | ||
114 | +func (repository *RoleRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.Role, error) { | ||
115 | + var ( | ||
116 | + tx = conn.DB() | ||
117 | + ms []*models.Role | ||
118 | + dms = make([]*domain.Role, 0) | ||
119 | + total int64 | ||
120 | + ) | ||
121 | + queryFunc := func() (interface{}, error) { | ||
122 | + tx = tx.Model(&ms).Order("id desc") | ||
123 | + if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | ||
124 | + return dms, tx.Error | ||
125 | + } | ||
126 | + return dms, nil | ||
127 | + } | ||
128 | + | ||
129 | + if _, err := repository.Query(queryFunc); err != nil { | ||
130 | + return 0, nil, err | ||
131 | + } | ||
132 | + | ||
133 | + for _, item := range ms { | ||
134 | + if dm, err := repository.ModelToDomainModel(item); err != nil { | ||
135 | + return 0, dms, err | ||
136 | + } else { | ||
137 | + dms = append(dms, dm) | ||
138 | + } | ||
139 | + } | ||
140 | + return total, dms, nil | ||
141 | +} | ||
142 | + | ||
143 | +func (repository *RoleRepository) ModelToDomainModel(from *models.Role) (*domain.Role, error) { | ||
144 | + to := &domain.Role{} | ||
145 | + err := copier.Copy(to, from) | ||
146 | + return to, err | ||
147 | +} | ||
148 | + | ||
149 | +func (repository *RoleRepository) DomainModelToModel(from *domain.Role) (*models.Role, error) { | ||
150 | + to := &models.Role{} | ||
151 | + err := copier.Copy(to, from) | ||
152 | + return to, err | ||
153 | +} | ||
154 | + | ||
155 | +func NewRoleRepository(cache *cache.CachedRepository) domain.RoleRepository { | ||
156 | + return &RoleRepository{CachedRepository: cache} | ||
157 | +} |
1 | +package repository | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + "github.com/jinzhu/copier" | ||
6 | + "github.com/pkg/errors" | ||
7 | + "github.com/tiptok/gocomm/pkg/cache" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/models" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
11 | + "gorm.io/gorm" | ||
12 | +) | ||
13 | + | ||
14 | +type UserRepository struct { | ||
15 | + *cache.CachedRepository | ||
16 | +} | ||
17 | + | ||
18 | +func (repository *UserRepository) Insert(ctx context.Context, conn transaction.Conn, dm *domain.User) (*domain.User, error) { | ||
19 | + var ( | ||
20 | + err error | ||
21 | + m = &models.User{} | ||
22 | + tx = conn.DB() | ||
23 | + ) | ||
24 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
25 | + return nil, err | ||
26 | + } | ||
27 | + if tx = tx.Model(m).Save(m); tx.Error != nil { | ||
28 | + return nil, tx.Error | ||
29 | + } | ||
30 | + dm.Id = m.Id | ||
31 | + return repository.ModelToDomainModel(m) | ||
32 | + | ||
33 | +} | ||
34 | + | ||
35 | +func (repository *UserRepository) Update(ctx context.Context, conn transaction.Conn, dm *domain.User) (*domain.User, error) { | ||
36 | + var ( | ||
37 | + err error | ||
38 | + m *models.User | ||
39 | + tx = conn.DB() | ||
40 | + ) | ||
41 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
42 | + return nil, err | ||
43 | + } | ||
44 | + queryFunc := func() (interface{}, error) { | ||
45 | + tx = tx.Model(m).Updates(m) | ||
46 | + return nil, tx.Error | ||
47 | + } | ||
48 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
49 | + return nil, err | ||
50 | + } | ||
51 | + return repository.ModelToDomainModel(m) | ||
52 | +} | ||
53 | + | ||
54 | +func (repository *UserRepository) UpdateWithVersion(ctx context.Context, transaction transaction.Conn, dm *domain.User) (*domain.User, error) { | ||
55 | + var ( | ||
56 | + err error | ||
57 | + m *models.User | ||
58 | + tx = transaction.DB() | ||
59 | + ) | ||
60 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
61 | + return nil, err | ||
62 | + } | ||
63 | + oldVersion := dm.Version | ||
64 | + m.Version += 1 | ||
65 | + queryFunc := func() (interface{}, error) { | ||
66 | + tx = tx.Model(m).Select("*").Where("id = ?", m.Id).Where("version = ?", oldVersion).Updates(m) | ||
67 | + if tx.RowsAffected == 0 { | ||
68 | + return nil, domain.ErrUpdateFail | ||
69 | + } | ||
70 | + return nil, tx.Error | ||
71 | + } | ||
72 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
73 | + return nil, err | ||
74 | + } | ||
75 | + return repository.ModelToDomainModel(m) | ||
76 | +} | ||
77 | + | ||
78 | +func (repository *UserRepository) Delete(ctx context.Context, conn transaction.Conn, dm *domain.User) (*domain.User, error) { | ||
79 | + var ( | ||
80 | + tx = conn.DB() | ||
81 | + m = &models.User{Id: dm.Identify().(int64)} | ||
82 | + ) | ||
83 | + queryFunc := func() (interface{}, error) { | ||
84 | + tx = tx.Where("id = ?", m.Id).Delete(m) | ||
85 | + return m, tx.Error | ||
86 | + } | ||
87 | + if _, err := repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
88 | + return dm, err | ||
89 | + } | ||
90 | + return repository.ModelToDomainModel(m) | ||
91 | +} | ||
92 | + | ||
93 | +func (repository *UserRepository) FindOne(ctx context.Context, conn transaction.Conn, id int64) (*domain.User, error) { | ||
94 | + var ( | ||
95 | + err error | ||
96 | + tx = conn.DB() | ||
97 | + m = new(models.User) | ||
98 | + ) | ||
99 | + queryFunc := func() (interface{}, error) { | ||
100 | + tx = tx.Model(m).Where("id = ?", id).First(m) | ||
101 | + if errors.Is(tx.Error, gorm.ErrRecordNotFound) { | ||
102 | + return nil, domain.ErrNotFound | ||
103 | + } | ||
104 | + return m, tx.Error | ||
105 | + } | ||
106 | + cacheModel := new(models.User) | ||
107 | + cacheModel.Id = id | ||
108 | + if err = repository.QueryCache(cacheModel.CacheKeyFunc, m, queryFunc); err != nil { | ||
109 | + return nil, err | ||
110 | + } | ||
111 | + return repository.ModelToDomainModel(m) | ||
112 | +} | ||
113 | + | ||
114 | +func (repository *UserRepository) Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*domain.User, error) { | ||
115 | + var ( | ||
116 | + tx = conn.DB() | ||
117 | + ms []*models.User | ||
118 | + dms = make([]*domain.User, 0) | ||
119 | + total int64 | ||
120 | + ) | ||
121 | + queryFunc := func() (interface{}, error) { | ||
122 | + tx = tx.Model(&ms).Order("id desc") | ||
123 | + if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | ||
124 | + return dms, tx.Error | ||
125 | + } | ||
126 | + return dms, nil | ||
127 | + } | ||
128 | + | ||
129 | + if _, err := repository.Query(queryFunc); err != nil { | ||
130 | + return 0, nil, err | ||
131 | + } | ||
132 | + | ||
133 | + for _, item := range ms { | ||
134 | + if dm, err := repository.ModelToDomainModel(item); err != nil { | ||
135 | + return 0, dms, err | ||
136 | + } else { | ||
137 | + dms = append(dms, dm) | ||
138 | + } | ||
139 | + } | ||
140 | + return total, dms, nil | ||
141 | +} | ||
142 | + | ||
143 | +func (repository *UserRepository) ModelToDomainModel(from *models.User) (*domain.User, error) { | ||
144 | + to := &domain.User{} | ||
145 | + err := copier.Copy(to, from) | ||
146 | + return to, err | ||
147 | +} | ||
148 | + | ||
149 | +func (repository *UserRepository) DomainModelToModel(from *domain.User) (*models.User, error) { | ||
150 | + to := &models.User{} | ||
151 | + err := copier.Copy(to, from) | ||
152 | + return to, err | ||
153 | +} | ||
154 | + | ||
155 | +func NewUserRepository(cache *cache.CachedRepository) domain.UserRepository { | ||
156 | + return &UserRepository{CachedRepository: cache} | ||
157 | +} |
@@ -8,17 +8,20 @@ import ( | @@ -8,17 +8,20 @@ import ( | ||
8 | ) | 8 | ) |
9 | 9 | ||
10 | type Article struct { | 10 | type Article struct { |
11 | - Id int64 | ||
12 | - CreatedAt time.Time | ||
13 | - UpdatedAt time.Time | ||
14 | - DeletedAt *time.Time | ||
15 | - AuthorId int64 // 发布人 | ||
16 | - Author UserSimple // 发布人 | ||
17 | - Title string // 文章标题 | ||
18 | - Images []Image // 图片 | ||
19 | - WhoRead []int64 // 谁可以看 | ||
20 | - WhoReview []int64 // 评论人 | ||
21 | - Location Location // 坐标 | 11 | + Id int64 `json:"id"` |
12 | + CreatedAt time.Time `json:"createdAt"` | ||
13 | + UpdatedAt time.Time `json:"updatedAt"` | ||
14 | + DeletedAt *time.Time `json:"deletedAt"` | ||
15 | + AuthorId int64 `json:"authorId"` // 发布人 | ||
16 | + Author UserSimple `json:"author"` // 发布人 | ||
17 | + Title string `json:"title"` // 文章标题 | ||
18 | + Images []Image `json:"images"` // 图片 | ||
19 | + WhoRead []int64 `json:"whoRead"` // 谁可以看 | ||
20 | + WhoReview []int64 `json:"whoReview"` // 评论人 | ||
21 | + Location Location `json:"location"` // 坐标 | ||
22 | + CountLove int `json:"countLove"` // 点赞数量 | ||
23 | + CountComment int `json:"countComment"` // 评论数量 | ||
24 | + Tags []int `json:"tags"` // 标签 | ||
22 | // ...more | 25 | // ...more |
23 | } | 26 | } |
24 | 27 |
1 | package domain | 1 | package domain |
2 | 2 | ||
3 | +import "time" | ||
4 | + | ||
3 | // 编辑文章后保存的历史记录 | 5 | // 编辑文章后保存的历史记录 |
4 | type ArticleBackup struct { | 6 | type ArticleBackup struct { |
5 | Id int64 | 7 | Id int64 |
8 | + UpdatedAt time.Time `json:"updatedAt"` // 更新时间 | ||
9 | + DeletedAt *time.Time `json:"deletedAt"` // | ||
10 | + CreatedAt time.Time `json:"createdAt"` // | ||
11 | + Operator UserSimple `json:"operator"` // 操作人 | ||
12 | + Title string `json:"title"` // 标题 | ||
13 | + Section []ArticleSection `json:"section"` // 分段内容 | ||
14 | + Images []Image `json:"images"` // 图片 | ||
15 | + Action string `json:"action"` // 操作 | ||
6 | } | 16 | } |
1 | package domain | 1 | package domain |
2 | 2 | ||
3 | -import "time" | 3 | +import ( |
4 | + "context" | ||
5 | + "time" | ||
6 | + | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
8 | +) | ||
4 | 9 | ||
5 | // 文章评论 | 10 | // 文章评论 |
6 | type ArticleComment struct { | 11 | type ArticleComment struct { |
7 | - Id int64 // 评论id | ||
8 | - UpdatedAt time.Time // 更新时间 | ||
9 | - DeletedAt *time.Time | ||
10 | - CreatedAt time.Time | ||
11 | - Pid int64 // 对哪个评论进行回复 | ||
12 | - TopId int64 // 归属于最上级的哪个评论 | ||
13 | - ArticleId int64 // 文章id | ||
14 | - ArticleSectionId int64 // 文本内容id | ||
15 | - SectionContent string // 引用的文章内容文本 | ||
16 | - FromUserId int64 // 谁填写的评论 | ||
17 | - FromUser UserSimple // 谁填写的评论 | ||
18 | - ToUserId int64 // 回复谁的评论 | ||
19 | - ToUser UserSimple // 回复谁的评论 | ||
20 | - Content string // 评论内容 | ||
21 | - CountReply int // 回复数量 | ||
22 | - CountUserLove int // 用户点赞数量 | ||
23 | - CountAdminLove int // 运营点赞数量 | 12 | + Id int64 `json:"id"` // 评论id |
13 | + UpdatedAt time.Time `json:"updatedAt"` // 更新时间 | ||
14 | + DeletedAt *time.Time `json:"deletedAt"` | ||
15 | + CreatedAt time.Time `json:"createdAt"` | ||
16 | + Pid int64 `json:"pid"` // 对哪个评论进行回复 | ||
17 | + TopId int64 `json:"topId"` // 归属于最上级的哪个评论 | ||
18 | + ArticleId int64 `json:"articleId"` // 文章id | ||
19 | + ArticleSectionId int64 `json:"articleSectionId"` // 文本内容id | ||
20 | + SectionContent string `json:"sectionContent"` // 引用的文章内容文本 | ||
21 | + FromUserId int64 `json:"fromUserId"` // 谁填写的评论 | ||
22 | + FromUser UserSimple `json:"fromUser"` // 谁填写的评论 | ||
23 | + ToUserId int64 `json:"toUserId"` // 回复谁的评论 | ||
24 | + ToUser UserSimple `json:"toUser"` // 回复谁的评论 | ||
25 | + Content string `json:"content"` // 评论内容 | ||
26 | + CountReply int `json:"countReply"` // 回复数量 | ||
27 | + CountUserLove int `json:"countUserLove"` // 用户点赞数量 | ||
28 | + CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 | ||
29 | + Show int `json:"showState"` // 评论的展示状态(0显示、1不显示) | ||
24 | // ...more | 30 | // ...more |
25 | } | 31 | } |
32 | + | ||
33 | +// 评论的展示状态(0显示、1不显示) | ||
34 | +type CommentShow int | ||
35 | + | ||
36 | +const ( | ||
37 | + CommentShowEnable CommentShow = 0 | ||
38 | + CommentShowDisable CommentShow = 1 | ||
39 | +) | ||
40 | + | ||
41 | +type ArticleCommentRepository interface { | ||
42 | + Insert(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error) | ||
43 | + Update(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error) | ||
44 | + Delete(ctx context.Context, conn transaction.Conn, dm *ArticleComment) (*ArticleComment, error) | ||
45 | + FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleComment, error) | ||
46 | + Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleComment, error) | ||
47 | +} |
1 | package domain | 1 | package domain |
2 | 2 | ||
3 | -import "time" | 3 | +import ( |
4 | + "context" | ||
5 | + "time" | ||
6 | + | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
8 | +) | ||
4 | 9 | ||
5 | // 填写文章时保存的草稿 | 10 | // 填写文章时保存的草稿 |
6 | 11 | ||
7 | type ArticleDraft struct { | 12 | type ArticleDraft struct { |
8 | - Id int64 | ||
9 | - CreatedAt time.Time | ||
10 | - UpdatedAt time.Time | ||
11 | - DeletedAt *time.Time | ||
12 | - Template int // 填写内容时用的样板 1、演绎式 2、归纳式 | ||
13 | - Content []string // 文章内容 | ||
14 | - AuthorId int64 // 发布人 | ||
15 | - Title string // 文章标题 | ||
16 | - Images []Image // 图片 | ||
17 | - WhoRead []int64 // 谁可以看 | ||
18 | - WhoReview []int64 // 评论人 | ||
19 | - Location Location // 坐标 | 13 | + Id int64 `json:"id"` |
14 | + CreatedAt time.Time `json:"createdAt"` | ||
15 | + UpdatedAt time.Time `json:"updatedAt"` | ||
16 | + DeletedAt *time.Time `json:"deletedAt"` | ||
17 | + Template int `json:"template"` // 填写内容时用的样板 1、演绎式 2、归纳式 | ||
18 | + Content []string `json:"content"` // 文章内容 | ||
19 | + AuthorId int64 `json:"authorId"` // 发布人 | ||
20 | + Title string `json:"title"` // 文章标题 | ||
21 | + Images []Image `json:"images"` // 图片 | ||
22 | + WhoRead []int64 `json:"whoRead"` // 谁可以看 | ||
23 | + WhoReview []int64 `json:"whoReview"` // 评论人 | ||
24 | + Location Location `json:"location"` // 坐标 | ||
25 | +} | ||
26 | +type ArticleDraftRepository interface { | ||
27 | + Insert(ctx context.Context, conn transaction.Conn, dm *ArticleDraft) (*ArticleDraft, error) | ||
28 | + Update(ctx context.Context, conn transaction.Conn, dm *ArticleDraft) (*ArticleDraft, error) | ||
29 | + Delete(ctx context.Context, conn transaction.Conn, dm *ArticleDraft) (*ArticleDraft, error) | ||
30 | + FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleDraft, error) | ||
31 | + Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleDraft, error) | ||
20 | } | 32 | } |
@@ -9,15 +9,14 @@ import ( | @@ -9,15 +9,14 @@ import ( | ||
9 | 9 | ||
10 | // 文章段落 | 10 | // 文章段落 |
11 | type ArticleSection struct { | 11 | type ArticleSection struct { |
12 | - Id int64 | ||
13 | - UpdatedAt time.Time // 更新时间 | ||
14 | - DeletedAt *time.Time // | ||
15 | - CreatedAt time.Time // | ||
16 | - ArticleId int64 // 文章id | ||
17 | - Content string // 文本内容 | ||
18 | - SortBy int // 排序 | ||
19 | - TotalComment int // 评论的数量 | ||
20 | - // ...more | 12 | + Id int64 `json:"id"` |
13 | + UpdatedAt time.Time `json:"updatedAt"` // 更新时间 | ||
14 | + DeletedAt *time.Time `json:"deletedAt"` // | ||
15 | + CreatedAt time.Time `json:"createdAt"` // | ||
16 | + ArticleId int64 `json:"articleId"` // 文章id | ||
17 | + Content string `json:"content"` // 文本内容 | ||
18 | + SortBy int `json:"sortBy"` // 排序 | ||
19 | + TotalComment int `json:"totalComment"` // 评论的数量 | ||
21 | } | 20 | } |
22 | 21 | ||
23 | type ArticleSectionRepository interface { | 22 | type ArticleSectionRepository interface { |
1 | +package domain | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + "time" | ||
6 | + | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
8 | +) | ||
9 | + | ||
10 | +// 文章的标签 | ||
11 | + | ||
12 | +type ArticleTag struct { | ||
13 | + Id int64 `json:"id"` | ||
14 | + UpdatedAt time.Time `json:"updatedAt"` // 更新时间 | ||
15 | + DeletedAt *time.Time `json:"deletedAt"` // | ||
16 | + CreatedAt time.Time `json:"createdAt"` // | ||
17 | + Image Image `json:"image"` //图片 | ||
18 | + Name string `json:"name"` //标签名称 | ||
19 | + Group string `json:"group"` //标签分类 | ||
20 | + Remark string `json:"remark"` //备注 | ||
21 | +} | ||
22 | +type ArticleTagRepository interface { | ||
23 | + Insert(ctx context.Context, conn transaction.Conn, dm *ArticleTag) (*ArticleTag, error) | ||
24 | + Update(ctx context.Context, conn transaction.Conn, dm *ArticleTag) (*ArticleSection, error) | ||
25 | + Delete(ctx context.Context, conn transaction.Conn, dm *ArticleTag) (*ArticleTag, error) | ||
26 | + FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleTag, error) | ||
27 | + Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleTag, error) | ||
28 | +} |
1 | +package domain | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
6 | +) | ||
7 | + | ||
8 | +type Department struct { | ||
9 | + Id int64 `json:"id,omitempty"` // 部门ID | ||
10 | + CompanyId int64 `json:"companyId,omitempty"` // 公司ID | ||
11 | + ParentId int64 `json:"parentId,omitempty"` // 父级ID | ||
12 | + Name string `json:"name,omitempty"` // 部门名称 | ||
13 | + | ||
14 | + CreatedAt int64 `json:"createdAt,omitempty"` | ||
15 | + UpdatedAt int64 `json:"updatedAt,omitempty"` | ||
16 | + DeletedAt int64 `json:"deletedAt,omitempty"` | ||
17 | + Version int `json:"version,omitempty"` | ||
18 | +} | ||
19 | + | ||
20 | +type DepartmentRepository interface { | ||
21 | + Insert(ctx context.Context, conn transaction.Conn, dm *Department) (*Department, error) | ||
22 | + Update(ctx context.Context, conn transaction.Conn, dm *Department) (*Department, error) | ||
23 | + UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Department) (*Department, error) | ||
24 | + Delete(ctx context.Context, conn transaction.Conn, dm *Department) (*Department, error) | ||
25 | + FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Department, error) | ||
26 | + Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*Department, error) | ||
27 | +} | ||
28 | + | ||
29 | +func (m *Department) Identify() interface{} { | ||
30 | + if m.Id == 0 { | ||
31 | + return nil | ||
32 | + } | ||
33 | + return m.Id | ||
34 | +} |
cmd/discuss/interanl/pkg/domain/role.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
6 | +) | ||
7 | + | ||
8 | +type Role struct { | ||
9 | + Id int64 `json:"id"` // 角色ID | ||
10 | + Name string `json:"name"` // 角色名称 | ||
11 | + Auths []int64 `json:"auths"` // 角色权限列表 | ||
12 | + Remark string `json:"remark"` // 备注 | ||
13 | + Users []int64 `json:"users"` // 绑定的用户 | ||
14 | + | ||
15 | + CreatedAt int64 `json:"createdAt,omitempty"` | ||
16 | + UpdatedAt int64 `json:"updatedAt,omitempty"` | ||
17 | + DeletedAt int64 `json:"deletedAt,omitempty"` | ||
18 | + Version int `json:"version,omitempty"` | ||
19 | +} | ||
20 | + | ||
21 | +type RoleRepository interface { | ||
22 | + Insert(ctx context.Context, conn transaction.Conn, dm *Role) (*Role, error) | ||
23 | + Update(ctx context.Context, conn transaction.Conn, dm *Role) (*Role, error) | ||
24 | + UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *Role) (*Role, error) | ||
25 | + Delete(ctx context.Context, conn transaction.Conn, dm *Role) (*Role, error) | ||
26 | + FindOne(ctx context.Context, conn transaction.Conn, id int64) (*Role, error) | ||
27 | + Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*Role, error) | ||
28 | +} | ||
29 | + | ||
30 | +func (m *Role) Identify() interface{} { | ||
31 | + if m.Id == 0 { | ||
32 | + return nil | ||
33 | + } | ||
34 | + return m.Id | ||
35 | +} |
cmd/discuss/interanl/pkg/domain/user.go
0 → 100644
1 | +package domain | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
6 | +) | ||
7 | + | ||
8 | +type User struct { | ||
9 | + Id int64 `json:"id,omitempty"` // 用户ID | ||
10 | + CompanyId int64 `json:"companyId,omitempty"` // 公司ID | ||
11 | + DepartmentId int64 `json:"departmentId,omitempty"` // 部门ID | ||
12 | + Roles []int64 `json:"roleId,omitempty"` // 角色 | ||
13 | + Flag int `json:"flag"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员) | ||
14 | + Name string `json:"name,omitempty"` // 名称 | ||
15 | + Avatar string `json:"avatar,omitempty"` // 头像 | ||
16 | + Phone string `json:"phone,omitempty"` // 手机号 唯一 | ||
17 | + Position string `json:"position,omitempty"` // 职位 | ||
18 | + Enable int `json:"enable,omitempty"` // 启用状态 1:启用 2:禁用 | ||
19 | + AuditStatus int `json:"auditStatus,omitempty"` // 审核状态 0:待审核 1:审核通过 2:拒绝 | ||
20 | + | ||
21 | + CreatedAt int64 `json:"createdAt,omitempty"` | ||
22 | + UpdatedAt int64 `json:"updatedAt,omitempty"` | ||
23 | + DeletedAt int64 `json:"deletedAt,omitempty"` | ||
24 | + Version int `json:"version,omitempty"` | ||
25 | +} | ||
26 | + | ||
27 | +type UserRepository interface { | ||
28 | + Insert(ctx context.Context, conn transaction.Conn, dm *User) (*User, error) | ||
29 | + Update(ctx context.Context, conn transaction.Conn, dm *User) (*User, error) | ||
30 | + UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *User) (*User, error) | ||
31 | + Delete(ctx context.Context, conn transaction.Conn, dm *User) (*User, error) | ||
32 | + FindOne(ctx context.Context, conn transaction.Conn, id int64) (*User, error) | ||
33 | + Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*User, error) | ||
34 | +} | ||
35 | + | ||
36 | +func (m *User) Identify() interface{} { | ||
37 | + if m.Id == 0 { | ||
38 | + return nil | ||
39 | + } | ||
40 | + return m.Id | ||
41 | +} |
@@ -5,11 +5,11 @@ import "time" | @@ -5,11 +5,11 @@ import "time" | ||
5 | // 人员点赞标记 | 5 | // 人员点赞标记 |
6 | 6 | ||
7 | type UserLoveFlag struct { | 7 | type UserLoveFlag struct { |
8 | - Id int64 | ||
9 | - ArticleId int64 //点赞文章时,填文章id | ||
10 | - CommentId int64 //点赞评论时,填评论id | ||
11 | - UserId int64 | ||
12 | - CreatedAt time.Time | ||
13 | - UpdatedAt time.Time | ||
14 | - DeletedAt *time.Time | 8 | + Id int64 `json:"id"` |
9 | + ArticleId int64 `json:"articleId"` //点赞文章时,填文章id | ||
10 | + CommentId int64 `json:"commentId"` //点赞评论时,填评论id | ||
11 | + UserId int64 `json:"userId"` | ||
12 | + CreatedAt time.Time `json:"createdAt"` | ||
13 | + UpdatedAt time.Time `json:"updatedAt"` | ||
14 | + DeletedAt *time.Time `json:"deletedAt"` | ||
15 | } | 15 | } |
@@ -2,4 +2,10 @@ package domain | @@ -2,4 +2,10 @@ package domain | ||
2 | 2 | ||
3 | // 人员查看文章详情后,标记一个记录 | 3 | // 人员查看文章详情后,标记一个记录 |
4 | 4 | ||
5 | -type UserReadArticle struct{} | 5 | +type UserReadArticle struct { |
6 | + Id int64 `json:"id"` | ||
7 | + UserId int64 `json:"userId"` | ||
8 | + ArticleId int64 `json:"articleId"` | ||
9 | + Title string `json:"title"` | ||
10 | + ArticleAuthor UserSimple `json:"author"` // 发布人 | ||
11 | +} |
@@ -2,3 +2,18 @@ CREATE TABLE `comment` ( | @@ -2,3 +2,18 @@ CREATE TABLE `comment` ( | ||
2 | `id` int(0) NOT NULL COMMENT '唯一标识', | 2 | `id` int(0) NOT NULL COMMENT '唯一标识', |
3 | PRIMARY KEY (`id`) USING BTREE | 3 | PRIMARY KEY (`id`) USING BTREE |
4 | ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; | 4 | ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; |
5 | + | ||
6 | +CREATE TABLE `department` ( | ||
7 | + `id` int(0) NOT NULL COMMENT '唯一标识', | ||
8 | + PRIMARY KEY (`id`) USING BTREE | ||
9 | +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; | ||
10 | + | ||
11 | +CREATE TABLE `role` ( | ||
12 | + `id` int(0) NOT NULL COMMENT '唯一标识', | ||
13 | + PRIMARY KEY (`id`) USING BTREE | ||
14 | +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; | ||
15 | + | ||
16 | +CREATE TABLE `user` ( | ||
17 | + `id` int(0) NOT NULL COMMENT '唯一标识', | ||
18 | + PRIMARY KEY (`id`) USING BTREE | ||
19 | +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; |
-
请 注册 或 登录 后发表评论