remove redundant code

This commit is contained in:
6543 2019-11-04 18:35:51 +01:00
parent 52cc73b14b
commit e607e9fcdb
No known key found for this signature in database
GPG Key ID: A1CA74D27FD13271

View File

@ -48,40 +48,7 @@ func AddIssueSubscription(ctx *context.APIContext) {
// description: User can only subscribe itself if he is no admin
// "404":
// description: Issue not found
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
if models.IsErrIssueNotExist(err) {
ctx.NotFound()
} else {
ctx.Error(500, "GetIssueByIndex", err)
}
return
}
user, err := models.GetUserByName(ctx.Params(":user"))
if err != nil {
if models.IsErrUserNotExist(err) {
ctx.NotFound()
} else {
ctx.Error(500, "GetUserByName", err)
}
return
}
//only admin and user for itself can change subscription
if user.ID != ctx.User.ID && !ctx.User.IsAdmin {
ctx.Error(403, "User", nil)
return
}
if err := models.CreateOrUpdateIssueWatch(user.ID, issue.ID, true); err != nil {
ctx.Error(500, "CreateOrUpdateIssueWatch", err)
return
}
ctx.Status(201)
setIssueSubscription(ctx, true)
}
// DelIssueSubscription Unsubscribe user from issue
@ -122,6 +89,10 @@ func DelIssueSubscription(ctx *context.APIContext) {
// description: User can only subscribe itself if he is no admin
// "404":
// description: Issue not found
setIssueSubscription(ctx, false)
}
func setIssueSubscription(ctx *context.APIContext, watch bool) {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
if models.IsErrIssueNotExist(err) {
@ -150,7 +121,7 @@ func DelIssueSubscription(ctx *context.APIContext) {
return
}
if err := models.CreateOrUpdateIssueWatch(user.ID, issue.ID, false); err != nil {
if err := models.CreateOrUpdateIssueWatch(user.ID, issue.ID, watch); err != nil {
ctx.Error(500, "CreateOrUpdateIssueWatch", err)
return
}