-
Notifications
You must be signed in to change notification settings - Fork 1
/
workduration.gno
80 lines (66 loc) · 1.97 KB
/
workduration.gno
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
package zentasktic_project
func (wd WorkDuration) AddWorkDuration() (err error) {
if WorkDurations.Size() != 0 {
_, exist := WorkDurations.Get(wd.Id)
if exist {
return ErrWorkDurationIdAlreadyExists
}
}
WorkDurations.Set(wd.Id, wd)
return nil
}
func (wd WorkDuration) EditWorkDuration() (err error) {
if WorkDurations.Size() != 0 {
_, exist := WorkDurations.Get(wd.Id)
if !exist {
return ErrWorkDurationNotFound
}
}
WorkDurations.Set(wd.Id, wd)
return nil
}
func (wd WorkDuration) RemoveWorkDuration() (err error) {
// implementation
if WorkDurations.Size() != 0 {
_, exist := WorkDurations.Get(wd.Id)
if !exist {
return ErrWorkDurationNotFound
}
}
_, removed := WorkDurations.Remove(wd.Id)
if !removed {
return ErrWorkDurationNotRemoved
}
return nil
}
// getters
func GetWorkDurationByOjectId(objectId string, objectType string) (wd WorkDuration, err error) {
// implementation
workDuration := WorkDuration{}
// Iterate over the WorkDuration AVL tree to see if we have a matching ObjectId.
WorkDurations.Iterate("", "", func(key string, value interface{}) bool {
if workDurationItem, ok := value.(WorkDuration); ok {
if workDurationItem.ObjectId == objectId && workDurationItem.ObjectType == objectType {
workDuration = workDurationItem
}
}
return false // Continue iteration until all nodes have been visited.
})
return workDuration, nil
}
func GetAllWorkDurations() (workDurations []WorkDuration, err error){
// implementation
var allWorkDurations []WorkDuration
// Iterate over the WorkDurations AVL tree to collect all WorkDurations objects.
if WorkDurations.Size() == 0 {
return nil, ErrWorkDurationsEmpty
} else {
WorkDurations.Iterate("", "", func(key string, value interface{}) bool {
if workDuration, ok := value.(WorkDuration); ok {
allWorkDurations = append(allWorkDurations, workDuration)
}
return false // Continue iteration until all nodes have been visited.
})
}
return allWorkDurations, nil
}