diff options
author | 6543 <6543@obermui.de> | 2020-09-18 14:09:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-18 20:09:26 +0800 |
commit | 1418288734b430330023e4e17747175e4fea2f41 (patch) | |
tree | 270f7bdbb6aee5f732a6d1295ce3d021d3e98874 /models/issue_stopwatch.go | |
parent | 5995326d51ab42014c6d77d3313233641c258318 (diff) | |
download | gitea-1418288734b430330023e4e17747175e4fea2f41.tar.gz gitea-1418288734b430330023e4e17747175e4fea2f41.zip |
Refactor: move Commit To APIFormat Code & Lot of StopWatch related things (#12729)
* move GitCommit to APIFormat convertion into convert package
* rename Commit convert functions
* move stopwatch to api convertion into convert package & rm unused code & extend test
* fix compare time
* Gitea not Gogs ;)
Diffstat (limited to 'models/issue_stopwatch.go')
-rw-r--r-- | models/issue_stopwatch.go | 68 |
1 files changed, 3 insertions, 65 deletions
diff --git a/models/issue_stopwatch.go b/models/issue_stopwatch.go index 789f8ebdfc..4b2bf1505d 100644 --- a/models/issue_stopwatch.go +++ b/models/issue_stopwatch.go @@ -8,7 +8,6 @@ import ( "fmt" "time" - api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/timeutil" ) @@ -20,9 +19,6 @@ 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. @@ -33,14 +29,14 @@ func getStopwatch(e Engine, userID, issueID int64) (sw *Stopwatch, exists bool, } // GetUserStopwatches return list of all stopwatches of a user -func GetUserStopwatches(userID int64, listOptions ListOptions) (*Stopwatches, error) { - sws := new(Stopwatches) +func GetUserStopwatches(userID int64, listOptions ListOptions) ([]*Stopwatch, error) { + sws := make([]*Stopwatch, 0, 8) sess := x.Where("stopwatch.user_id = ?", userID) if listOptions.Page != 0 { sess = listOptions.setSessionPagination(sess) } - err := sess.Find(sws) + err := sess.Find(&sws) if err != nil { return nil, err } @@ -194,61 +190,3 @@ 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 - } - if err := issue.LoadRepo(); err != nil { - return api.StopWatch{}, err - } - return api.StopWatch{ - Created: sw.CreatedUnix.AsTime(), - IssueIndex: issue.Index, - IssueTitle: issue.Title, - RepoOwnerName: issue.Repo.OwnerName, - RepoName: issue.Repo.Name, - }, 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))) - - issueCache := make(map[int64]*Issue) - repoCache := make(map[int64]*Repository) - var ( - issue *Issue - repo *Repository - ok bool - err error - ) - - for _, sw := range sws { - issue, ok = issueCache[sw.IssueID] - if !ok { - issue, err = GetIssueByID(sw.IssueID) - if err != nil { - return nil, err - } - } - repo, ok = repoCache[issue.RepoID] - if !ok { - repo, err = GetRepositoryByID(issue.RepoID) - if err != nil { - return nil, err - } - } - - result = append(result, api.StopWatch{ - Created: sw.CreatedUnix.AsTime(), - IssueIndex: issue.Index, - IssueTitle: issue.Title, - RepoOwnerName: repo.OwnerName, - RepoName: repo.Name, - }) - } - return result, nil -} |