diff options
author | 6543 <6543@obermui.de> | 2020-04-21 15:48:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-21 14:48:53 +0100 |
commit | bb4261a5ed678235fadef279fe1ba1505993a406 (patch) | |
tree | e3134123a4ccd273ddf5cd93701fef6db21d593b /routers/api/v1/repo/issue_subscription.go | |
parent | 33176e8d27eeb47c6d63fbd24bf11ac9e5c60acd (diff) | |
download | gitea-bb4261a5ed678235fadef279fe1ba1505993a406.tar.gz gitea-bb4261a5ed678235fadef279fe1ba1505993a406.zip |
Add issue subscription check to API (#10967)
close #10962
Adds `GET /api/v1/repos/{owner}/{repo}/issues/{index}/subscriptions/check`
-> return a `WachInfo`
Diffstat (limited to 'routers/api/v1/repo/issue_subscription.go')
-rw-r--r-- | routers/api/v1/repo/issue_subscription.go | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/routers/api/v1/repo/issue_subscription.go b/routers/api/v1/repo/issue_subscription.go index 0406edd207..999dda1738 100644 --- a/routers/api/v1/repo/issue_subscription.go +++ b/routers/api/v1/repo/issue_subscription.go @@ -9,6 +9,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" + api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/routers/api/v1/utils" ) @@ -133,6 +134,64 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) { ctx.Status(http.StatusCreated) } +// CheckIssueSubscription check if user is subscribed to an issue +func CheckIssueSubscription(ctx *context.APIContext) { + // swagger:operation GET /repos/{owner}/{repo}/issues/{index}/subscriptions/check issue issueCheckSubscription + // --- + // summary: Check if user is subscribed to an issue + // consumes: + // - application/json + // produces: + // - application/json + // parameters: + // - name: owner + // in: path + // description: owner of the repo + // type: string + // required: true + // - name: repo + // in: path + // description: name of the repo + // type: string + // required: true + // - name: index + // in: path + // description: index of the issue + // type: integer + // format: int64 + // required: true + // responses: + // "200": + // "$ref": "#/responses/WatchInfo" + // "404": + // "$ref": "#/responses/notFound" + + issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) + if err != nil { + if models.IsErrIssueNotExist(err) { + ctx.NotFound() + } else { + ctx.Error(http.StatusInternalServerError, "GetIssueByIndex", err) + } + + return + } + + watching, err := models.CheckIssueWatch(ctx.User, issue) + if err != nil { + ctx.InternalServerError(err) + return + } + ctx.JSON(http.StatusOK, api.WatchInfo{ + Subscribed: watching, + Ignored: !watching, + Reason: nil, + CreatedAt: issue.CreatedUnix.AsTime(), + URL: issue.APIURL() + "/subscriptions", + RepositoryURL: ctx.Repo.Repository.APIURL(), + }) +} + // GetIssueSubscribers return subscribers of an issue func GetIssueSubscribers(ctx *context.APIContext) { // swagger:operation GET /repos/{owner}/{repo}/issues/{index}/subscriptions issue issueSubscriptions |