From deaf69c801b08f347693f6d35103cd1bf6b8290d Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 29 Oct 2019 12:45:37 +0100 Subject: [PATCH] subscribers return []user.APIFormat --- modules/structs/issue.go | 6 ------ routers/api/v1/api.go | 2 +- routers/api/v1/repo/issue.go | 11 +++++------ 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/modules/structs/issue.go b/modules/structs/issue.go index fe74b5b1bc..58fd7344b4 100644 --- a/modules/structs/issue.go +++ b/modules/structs/issue.go @@ -113,9 +113,3 @@ type EditPriorityOption struct { // required:true Priority int `json:"priority"` } - -// IssueWatchers list of subscribers of an issue -type IssueWatchers struct { - // required:true - Subscribers []string `json:"subscribers"` -} diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 4c4b126ee4..d5889dd54a 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -689,7 +689,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Post("/stop", reqToken(), repo.StopIssueStopwatch) }) m.Group("/subscriptions", func() { - m.Get("", reqToken(), bind(api.IssueWatchers{}), repo.GetIssueWatchers) + m.Get("", reqToken(), bind(api.User{}), repo.GetIssueWatchers) m.Put("/:user", reqToken(), repo.AddIssueSubscription) m.Delete("/:user", reqToken(), repo.DelIssueSubscription) }) diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index f37c972ac9..e72d54f41d 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -744,7 +744,7 @@ func DelIssueSubscription(ctx *context.APIContext) { } // GetIssueWatchers return subscribers of an issue -func GetIssueWatchers(ctx *context.APIContext, form api.IssueWatchers) { +func GetIssueWatchers(ctx *context.APIContext, form api.User) { // swagger:operation GET /repos/{owner}/{repo}/issues/{index}/subscriptions issue issueSubscriptions // --- // summary: Get users who subscribed on an issue. @@ -785,21 +785,20 @@ func GetIssueWatchers(ctx *context.APIContext, form api.IssueWatchers) { return } - var subscribers []string - iw, err := models.GetIssueWatchers(issue.ID) if err != nil { ctx.Error(500, "GetIssueWatchers", err) return } - for _, s := range iw { + subscribers := make([]*api.User, len(iw)) + for i, s := range iw { user, err := models.GetUserByID(s.UserID) if err != nil { continue } - subscribers = append(subscribers, user.LoginName) + subscribers[i] = user.APIFormat() } - ctx.JSON(200, api.IssueWatchers{Subscribers: subscribers}) + ctx.JSON(200, subscribers) }