2015-04-08 22:43:59 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/drone/drone/common"
|
2015-04-14 04:39:05 +00:00
|
|
|
"github.com/gin-gonic/gin"
|
2015-04-08 22:43:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Unubscribe accapets a request to unsubscribe the
|
|
|
|
// currently authenticated user to the repository.
|
|
|
|
//
|
|
|
|
// DEL /api/subscribers/:owner/:name
|
|
|
|
//
|
|
|
|
func Unsubscribe(c *gin.Context) {
|
|
|
|
store := ToDatastore(c)
|
|
|
|
repo := ToRepo(c)
|
|
|
|
user := ToUser(c)
|
2015-04-09 05:18:25 +00:00
|
|
|
|
2015-04-14 04:39:05 +00:00
|
|
|
err := store.DeleteSubscriber(user.Login, repo.FullName)
|
2015-04-08 22:43:59 +00:00
|
|
|
if err != nil {
|
|
|
|
c.Fail(400, err)
|
|
|
|
} else {
|
|
|
|
c.Writer.WriteHeader(200)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Subscribe accapets a request to subscribe the
|
|
|
|
// currently authenticated user to the repository.
|
|
|
|
//
|
|
|
|
// POST /api/subscriber/:owner/:name
|
|
|
|
//
|
|
|
|
func Subscribe(c *gin.Context) {
|
|
|
|
store := ToDatastore(c)
|
|
|
|
repo := ToRepo(c)
|
|
|
|
user := ToUser(c)
|
2015-04-14 04:39:05 +00:00
|
|
|
|
|
|
|
err := store.InsertSubscriber(user.Login, repo.FullName)
|
2015-04-08 22:43:59 +00:00
|
|
|
if err != nil {
|
|
|
|
c.Fail(400, err)
|
|
|
|
} else {
|
2015-04-09 05:18:25 +00:00
|
|
|
c.JSON(200, &common.Subscriber{Subscribed: true})
|
2015-04-08 22:43:59 +00:00
|
|
|
}
|
|
|
|
}
|