-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Use api.TrackedTime in API #2807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,18 @@ package repo | |
import ( | ||
"code.gitea.io/gitea/models" | ||
"code.gitea.io/gitea/modules/context" | ||
"code.gitea.io/gitea/routers/api/v1/convert" | ||
api "code.gitea.io/sdk/gitea" | ||
) | ||
|
||
func convertTrackedTimes(trackedTimes []*models.TrackedTime) []*api.TrackedTime { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed to |
||
apiTrackedTimes := make([]*api.TrackedTime, len(trackedTimes)) | ||
for i, trackedTime := range trackedTimes { | ||
apiTrackedTimes[i] = convert.ToTrackedTime(trackedTime) | ||
} | ||
return apiTrackedTimes | ||
} | ||
|
||
// ListTrackedTimes list all the tracked times of an issue | ||
func ListTrackedTimes(ctx *context.APIContext) { | ||
// swagger:route GET /repos/{username}/{reponame}/issues/{issue}/times repository issueTrackedTimes | ||
|
@@ -35,11 +44,13 @@ func ListTrackedTimes(ctx *context.APIContext) { | |
return | ||
} | ||
|
||
if trackedTimes, err := models.GetTrackedTimes(models.FindTrackedTimesOptions{IssueID: issue.ID}); err != nil { | ||
trackedTimes, err := models.GetTrackedTimes(models.FindTrackedTimesOptions{IssueID: issue.ID}) | ||
if err != nil { | ||
ctx.Error(500, "GetTrackedTimesByIssue", err) | ||
} else { | ||
ctx.JSON(200, &trackedTimes) | ||
return | ||
} | ||
apiTrackedTimes := convertTrackedTimes(trackedTimes) | ||
ctx.JSON(200, &apiTrackedTimes) | ||
} | ||
|
||
// AddTime adds time manual to the given issue | ||
|
@@ -73,13 +84,12 @@ func AddTime(ctx *context.APIContext, form api.AddTimeOption) { | |
ctx.Status(403) | ||
return | ||
} | ||
var tt *models.TrackedTime | ||
if tt, err = models.AddTime(ctx.User, issue, form.Time); err != nil { | ||
trackedTime, err := models.AddTime(ctx.User, issue, form.Time) | ||
if err != nil { | ||
ctx.Error(500, "AddTime", err) | ||
return | ||
} | ||
ctx.JSON(200, tt) | ||
|
||
ctx.JSON(200, convert.ToTrackedTime(trackedTime)) | ||
} | ||
|
||
// ListTrackedTimesByUser lists all tracked times of the user | ||
|
@@ -111,11 +121,15 @@ func ListTrackedTimesByUser(ctx *context.APIContext) { | |
ctx.Status(404) | ||
return | ||
} | ||
if trackedTimes, err := models.GetTrackedTimes(models.FindTrackedTimesOptions{UserID: user.ID, RepositoryID: ctx.Repo.Repository.ID}); err != nil { | ||
trackedTimes, err := models.GetTrackedTimes(models.FindTrackedTimesOptions{ | ||
UserID: user.ID, | ||
RepositoryID: ctx.Repo.Repository.ID}) | ||
if err != nil { | ||
ctx.Error(500, "GetTrackedTimesByUser", err) | ||
} else { | ||
ctx.JSON(200, &trackedTimes) | ||
return | ||
} | ||
apiTrackedTimes := convertTrackedTimes(trackedTimes) | ||
ctx.JSON(200, &apiTrackedTimes) | ||
} | ||
|
||
// ListTrackedTimesByRepository lists all tracked times of the user | ||
|
@@ -133,11 +147,14 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) { | |
ctx.JSON(400, struct{ Message string }{Message: "time tracking disabled"}) | ||
return | ||
} | ||
if trackedTimes, err := models.GetTrackedTimes(models.FindTrackedTimesOptions{RepositoryID: ctx.Repo.Repository.ID}); err != nil { | ||
trackedTimes, err := models.GetTrackedTimes(models.FindTrackedTimesOptions{ | ||
RepositoryID: ctx.Repo.Repository.ID}) | ||
if err != nil { | ||
ctx.Error(500, "GetTrackedTimesByUser", err) | ||
} else { | ||
ctx.JSON(200, &trackedTimes) | ||
return | ||
} | ||
apiTrackedTimes := convertTrackedTimes(trackedTimes) | ||
ctx.JSON(200, &apiTrackedTimes) | ||
} | ||
|
||
// ListMyTrackedTimes lists all tracked times of the current user | ||
|
@@ -150,9 +167,11 @@ func ListMyTrackedTimes(ctx *context.APIContext) { | |
// Responses: | ||
// 200: TrackedTimes | ||
// 500: error | ||
if trackedTimes, err := models.GetTrackedTimes(models.FindTrackedTimesOptions{UserID: ctx.User.ID}); err != nil { | ||
trackedTimes, err := models.GetTrackedTimes(models.FindTrackedTimesOptions{UserID: ctx.User.ID}) | ||
if err != nil { | ||
ctx.Error(500, "GetTrackedTimesByUser", err) | ||
} else { | ||
ctx.JSON(200, &trackedTimes) | ||
return | ||
} | ||
apiTrackedTimes := convertTrackedTimes(trackedTimes) | ||
ctx.JSON(200, &apiTrackedTimes) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this better would be as model method APIFormat() like this:
gitea/models/issue.go
Line 268 in aa962de
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lafriks Done. Out of curiosity, why do you prefer a
TrackedTime.APIFormat()
method to aconvert.ToTrackedTeam
function?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ethantkoenig it's just more straightforward and when just converting model to api type (1:1) I think there is no need for special function