-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeentry.go
62 lines (53 loc) · 1.47 KB
/
timeentry.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
package redmine
import (
"errors"
"fmt"
"time"
)
// Time Entries filtration by range of dates and user id.
type TimeEntriesFilter struct {
StartDate time.Time
EndDate time.Time
UserId string
}
// A Redmine time entries.
type TimeEntry struct {
Id int `json:"id"`
Project `json:"project"`
Issue `json:"issue"`
User `json:"user"`
Hours float32 `json:"hours"`
Comment string `json:"comments"`
SpentOn Date `json:"spent_on"`
}
func (t TimeEntry) String() string {
return fmt.Sprintf(
"%-5d %5.2f %s %-15s %s", t.Issue.Id, t.Hours, t.SpentOn, t.User.Name, t.Comment)
}
type TimeEntries struct {
Items []TimeEntry `json:"time_entries"`
Pagination
}
// Payload of Redmine API POST /time_entries.
type CreateTimeEntryPayload struct {
ProjectID int `json:"project_id,omitempty"`
IssueID int `json:"issue_id,omitempty"`
ActivityID int `json:"activity_id,omitempty"`
UserID int `json:"user_id,omitempty"`
SpentOn Date `json:"spent_on,omitempty"`
Comments string `json:"comments,omitempty"`
Hours float32 `json:"hours,omitempty"`
}
// Validate payload.
func (p CreateTimeEntryPayload) Validate() error {
if p.SpentOn.IsZero() {
return errors.Join(ValidationError, ZeroTimeDetectedError)
}
if p.ProjectID > 0 && p.IssueID > 0 {
return errors.Join(ValidationError, ProjectAndIssuePassedError)
}
if p.ProjectID == 0 && p.IssueID == 0 {
return errors.Join(ValidationError, ProjectAndIssueMissedError)
}
return nil
}