diff options
author | 6543 <6543@obermui.de> | 2019-12-12 05:23:05 +0100 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2019-12-11 23:23:05 -0500 |
commit | aceb1085c79e4c75268ce794a8ee84631382a403 (patch) | |
tree | 0e2a9137e07d04ff33c034f2a610e4a51fa0897a /models/issue_stopwatch.go | |
parent | 382936a668c48b3c83fe80cdf138f76fb74a5f8f (diff) | |
download | gitea-aceb1085c79e4c75268ce794a8ee84631382a403.tar.gz gitea-aceb1085c79e4c75268ce794a8ee84631382a403.zip |
[API] extend StopWatch (#9196)
* squash api-stopwatch
* fix prepair logic! + add Tests
* fix lint
* more robust time compare
* delete responce 202 -> 204
* change http responce in test too
Diffstat (limited to 'models/issue_stopwatch.go')
-rw-r--r-- | models/issue_stopwatch.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/models/issue_stopwatch.go b/models/issue_stopwatch.go index d7c3a9f73b..8047f122b5 100644 --- a/models/issue_stopwatch.go +++ b/models/issue_stopwatch.go @@ -8,6 +8,7 @@ import ( "fmt" "time" + api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/timeutil" ) @@ -19,6 +20,9 @@ type Stopwatch struct { CreatedUnix timeutil.TimeStamp `xorm:"created"` } +// Stopwatches is a List ful of Stopwatch +type Stopwatches []Stopwatch + func getStopwatch(e Engine, userID, issueID int64) (sw *Stopwatch, exists bool, err error) { sw = new(Stopwatch) exists, err = e. @@ -28,6 +32,16 @@ func getStopwatch(e Engine, userID, issueID int64) (sw *Stopwatch, exists bool, return } +// GetUserStopwatches return list of all stopwatches of a user +func GetUserStopwatches(userID int64) (sws *Stopwatches, err error) { + sws = new(Stopwatches) + err = x.Where("stopwatch.user_id = ?", userID).Find(sws) + if err != nil { + return nil, err + } + return sws, nil +} + // StopwatchExists returns true if the stopwatch exists func StopwatchExists(userID int64, issueID int64) bool { _, exists, _ := getStopwatch(x, userID, issueID) @@ -160,3 +174,28 @@ func SecToTime(duration int64) string { return hrs } + +// APIFormat convert Stopwatch type to api.StopWatch type +func (sw *Stopwatch) APIFormat() (api.StopWatch, error) { + issue, err := getIssueByID(x, sw.IssueID) + if err != nil { + return api.StopWatch{}, err + } + return api.StopWatch{ + Created: sw.CreatedUnix.AsTime(), + IssueIndex: issue.Index, + }, nil +} + +// APIFormat convert Stopwatches type to api.StopWatches type +func (sws Stopwatches) APIFormat() (api.StopWatches, error) { + result := api.StopWatches(make([]api.StopWatch, 0, len(sws))) + for _, sw := range sws { + apiSW, err := sw.APIFormat() + if err != nil { + return nil, err + } + result = append(result, apiSW) + } + return result, nil +} |