mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-24 19:02:58 +01:00
Return issue subscription status from API subscribe (#10966)
* [API] issue subscription indicate by http status * CI.restart()
This commit is contained in:
parent
4974b7c120
commit
e9e8638f18
3 changed files with 35 additions and 4 deletions
|
@ -58,9 +58,17 @@ func TestAPIIssueSubscriptions(t *testing.T) {
|
||||||
session.MakeRequest(t, req, http.StatusCreated)
|
session.MakeRequest(t, req, http.StatusCreated)
|
||||||
testSubscription(issue1, false)
|
testSubscription(issue1, false)
|
||||||
|
|
||||||
|
req = NewRequest(t, "DELETE", urlStr)
|
||||||
|
session.MakeRequest(t, req, http.StatusOK)
|
||||||
|
testSubscription(issue1, false)
|
||||||
|
|
||||||
issue5Repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: issue5.RepoID}).(*models.Repository)
|
issue5Repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: issue5.RepoID}).(*models.Repository)
|
||||||
urlStr = fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/subscriptions/%s?token=%s", issue5Repo.OwnerName, issue5Repo.Name, issue5.Index, owner.Name, token)
|
urlStr = fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/subscriptions/%s?token=%s", issue5Repo.OwnerName, issue5Repo.Name, issue5.Index, owner.Name, token)
|
||||||
req = NewRequest(t, "PUT", urlStr)
|
req = NewRequest(t, "PUT", urlStr)
|
||||||
session.MakeRequest(t, req, http.StatusCreated)
|
session.MakeRequest(t, req, http.StatusCreated)
|
||||||
testSubscription(issue5, true)
|
testSubscription(issue5, true)
|
||||||
|
|
||||||
|
req = NewRequest(t, "PUT", urlStr)
|
||||||
|
session.MakeRequest(t, req, http.StatusOK)
|
||||||
|
testSubscription(issue5, true)
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,8 +45,10 @@ func AddIssueSubscription(ctx *context.APIContext) {
|
||||||
// type: string
|
// type: string
|
||||||
// required: true
|
// required: true
|
||||||
// responses:
|
// responses:
|
||||||
|
// "200":
|
||||||
|
// description: Already subscribed
|
||||||
// "201":
|
// "201":
|
||||||
// "$ref": "#/responses/empty"
|
// description: Successfully Subscribed
|
||||||
// "304":
|
// "304":
|
||||||
// description: User can only subscribe itself if he is no admin
|
// description: User can only subscribe itself if he is no admin
|
||||||
// "404":
|
// "404":
|
||||||
|
@ -87,8 +89,10 @@ func DelIssueSubscription(ctx *context.APIContext) {
|
||||||
// type: string
|
// type: string
|
||||||
// required: true
|
// required: true
|
||||||
// responses:
|
// responses:
|
||||||
|
// "200":
|
||||||
|
// description: Already unsubscribed
|
||||||
// "201":
|
// "201":
|
||||||
// "$ref": "#/responses/empty"
|
// description: Successfully Unsubscribed
|
||||||
// "304":
|
// "304":
|
||||||
// description: User can only subscribe itself if he is no admin
|
// description: User can only subscribe itself if he is no admin
|
||||||
// "404":
|
// "404":
|
||||||
|
@ -126,6 +130,19 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
current, err := models.CheckIssueWatch(user, issue)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Error(http.StatusInternalServerError, "CheckIssueWatch", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// If watch state wont change
|
||||||
|
if current == watch {
|
||||||
|
ctx.Status(http.StatusOK)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update watch state
|
||||||
if err := models.CreateOrUpdateIssueWatch(user.ID, issue.ID, watch); err != nil {
|
if err := models.CreateOrUpdateIssueWatch(user.ID, issue.ID, watch); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "CreateOrUpdateIssueWatch", err)
|
ctx.Error(http.StatusInternalServerError, "CreateOrUpdateIssueWatch", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -5315,8 +5315,11 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Already subscribed"
|
||||||
|
},
|
||||||
"201": {
|
"201": {
|
||||||
"$ref": "#/responses/empty"
|
"description": "Successfully Subscribed"
|
||||||
},
|
},
|
||||||
"304": {
|
"304": {
|
||||||
"description": "User can only subscribe itself if he is no admin"
|
"description": "User can only subscribe itself if he is no admin"
|
||||||
|
@ -5370,8 +5373,11 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Already unsubscribed"
|
||||||
|
},
|
||||||
"201": {
|
"201": {
|
||||||
"$ref": "#/responses/empty"
|
"description": "Successfully Unsubscribed"
|
||||||
},
|
},
|
||||||
"304": {
|
"304": {
|
||||||
"description": "User can only subscribe itself if he is no admin"
|
"description": "User can only subscribe itself if he is no admin"
|
||||||
|
|
Loading…
Reference in a new issue