diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2020-01-11 10:59:41 +0800 |
---|---|---|
committer | techknowlogick <techknowlogick@gitea.io> | 2020-01-10 21:59:41 -0500 |
commit | 4d06d10dbafe7cfd404889b636d8e243058ee96f (patch) | |
tree | e8107acad719b45f2732b0736d4657cac65fb679 /modules/convert | |
parent | 705b1e49a8b2ac8df377120f70f3548df15cdf49 (diff) | |
download | gitea-4d06d10dbafe7cfd404889b636d8e243058ee96f.tar.gz gitea-4d06d10dbafe7cfd404889b636d8e243058ee96f.zip |
Move tracked time api convert to convert package (#9665)
Diffstat (limited to 'modules/convert')
-rw-r--r-- | modules/convert/issue.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/modules/convert/issue.go b/modules/convert/issue.go new file mode 100644 index 0000000000..d88a742dbb --- /dev/null +++ b/modules/convert/issue.go @@ -0,0 +1,38 @@ +// Copyright 2020 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package convert + +import ( + "code.gitea.io/gitea/models" + api "code.gitea.io/gitea/modules/structs" +) + +// ToTrackedTime converts TrackedTime to API format +func ToTrackedTime(t *models.TrackedTime) (apiT *api.TrackedTime) { + apiT = &api.TrackedTime{ + ID: t.ID, + IssueID: t.IssueID, + UserID: t.UserID, + UserName: t.User.Name, + Time: t.Time, + Created: t.Created, + } + if t.Issue != nil { + apiT.Issue = t.Issue.APIFormat() + } + if t.User != nil { + apiT.UserName = t.User.Name + } + return +} + +// ToTrackedTimeList converts TrackedTimeList to API format +func ToTrackedTimeList(tl models.TrackedTimeList) api.TrackedTimeList { + result := make([]*api.TrackedTime, 0, len(tl)) + for _, t := range tl { + result = append(result, ToTrackedTime(t)) + } + return result +} |