mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
[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
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user