-
Notifications
You must be signed in to change notification settings - Fork 1
/
task.go
71 lines (57 loc) · 2.02 KB
/
task.go
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
package repository_manage
import (
"github.com/anden007/afocus-godf/src/interfaces"
"github.com/anden007/afocus-godf/src/lib"
"github.com/anden007/afocus-godf/src/model/model_manage"
"github.com/google/uuid"
"time"
)
type TaskRepository struct{}
func NewTaskRepository() *TaskRepository {
instance := new(TaskRepository)
return instance
}
func (m *TaskRepository) Add(entity model_manage.Task) (err error) {
db := interfaces.DI().GetDataBase()
if entity.CreateTime.IsZero() {
entity.CreateTime = time.Now()
}
err = db.GetDB().Create(&entity).Error
return
}
func (m *TaskRepository) Edit(entity model_manage.Task) (err error) {
db := interfaces.DI().GetDataBase()
err = db.GetDB().Save(&entity).Error
return
}
func (m *TaskRepository) DelByIds(ids []uuid.UUID) (err error) {
db := interfaces.DI().GetDataBase()
err = db.GetDB().Delete(model_manage.Task{}, "id in (?)", ids).Error
return
}
func (m *TaskRepository) GetById(id uuid.UUID) (result model_manage.Task, err error) {
db := interfaces.DI().GetDataBase()
err = db.GetDB().Model(&model_manage.Task{}).Where(&model_manage.Task{Id: id}).First(&result).Error
return
}
func (m *TaskRepository) GetAll() (result []model_manage.Task, err error) {
db := interfaces.DI().GetDataBase()
err = db.GetDB().Model(&model_manage.Task{}).Find(&result).Error
return
}
func (m *TaskRepository) Updates(id uuid.UUID, fieldValues map[string]interface{}) (err error) {
db := interfaces.DI().GetDataBase()
err = db.GetDB().Model(&model_manage.Task{}).Where(model_manage.Task{Id: id}).Updates(fieldValues).Error
return
}
func (m *TaskRepository) GetByCondition(condition map[string]string) (result []model_manage.Task, total int64, err error) {
db := interfaces.DI().GetDataBase()
Query := db.GetDB().Model(model_manage.Task{})
CountQuery := db.GetDB().Model(model_manage.Task{})
err = lib.NewQueryCondition().GetQuery(model_manage.Task{}.TableName(), condition, Query, CountQuery)
if err == nil {
err = CountQuery.Count(&total).Error
err = Query.Find(&result).Error
}
return
}