reworked to have two distinct REST handlers

This commit is contained in:
Ulrich Schreiner 2015-02-05 15:27:26 +01:00
parent 05b6dad81e
commit ae236a3d4d
4 changed files with 44 additions and 37 deletions

View file

@ -35,12 +35,12 @@ func (s *RepoService) Enable(host, owner, name string) error {
// DELETE /api/repos/{host}/{owner}/{name}
func (s *RepoService) Disable(host, owner, name string) error {
var path = fmt.Sprintf("/api/repos/%s/%s/%s", host, owner, name)
return s.run("DELETE", path, nil, nil)
return s.run("PATCH", path, nil, nil)
}
// DELETE /api/repos/{host}/{owner}/{name}?remove=true
func (s *RepoService) Delete(host, owner, name string) error {
var path = fmt.Sprintf("/api/repos/%s/%s/%s?remove=true", host, owner, name)
var path = fmt.Sprintf("/api/repos/%s/%s/%s", host, owner, name)
return s.run("DELETE", path, nil, nil)
}

View file

@ -43,9 +43,8 @@ func GetRepo(c web.C, w http.ResponseWriter, r *http.Request) {
}{repo, repo.PublicKey, repo.Params, role})
}
// DelRepo accepts a request to inactivate the named
// repository. This will disable all builds in the system
// for this repository.
// DelRepo accepts a request to delete the named
// repository.
//
// DEL /api/repos/:host/:owner/:name
//
@ -53,10 +52,7 @@ func DelRepo(c web.C, w http.ResponseWriter, r *http.Request) {
var ctx = context.FromC(c)
var repo = ToRepo(c)
var rm = r.FormValue("remove") // using ?remove=true
// completely remove the repository from the database
if len(rm) != 0 {
var user = ToUser(c)
var remote = remote.Lookup(repo.Host)
if remote == nil {
@ -70,6 +66,7 @@ func DelRepo(c web.C, w http.ResponseWriter, r *http.Request) {
if user_token != nil {
user.Access = user_token.AccessToken
user.Secret = user_token.RefreshToken
user.TokenExpiry = user_token.Expiry
datastore.PutUser(ctx, user)
}
// setup the post-commit hook with the remote system and
@ -87,8 +84,17 @@ func DelRepo(c web.C, w http.ResponseWriter, r *http.Request) {
} else {
w.WriteHeader(http.StatusNoContent)
}
return
}
}
// PatchRepo accepts a request to inactivate the named
// repository. This will disable all builds in the system
// for this repository.
//
// PATCH /api/repos/:host/:owner/:name
//
func PatchRepo(c web.C, w http.ResponseWriter, r *http.Request) {
var ctx = context.FromC(c)
var repo = ToRepo(c)
// disable everything
repo.Active = false

View file

@ -46,6 +46,7 @@ func New() *web.Mux {
repos.Put("/api/repos/:host/:owner/:name", handler.PutRepo)
repos.Post("/api/repos/:host/:owner/:name", handler.PostRepo)
repos.Delete("/api/repos/:host/:owner/:name", handler.DelRepo)
repos.Patch("/api/repos/:host/:owner/:name", handler.PatchRepo)
mux.Handle("/api/repos/:host/:owner/:name", repos)
mux.Handle("/api/repos/:host/:owner/:name/*", repos)

View file

@ -20,7 +20,7 @@ type User struct {
Created int64 `meddler:"user_created" json:"created_at"`
Updated int64 `meddler:"user_updated" json:"updated_at"`
Synced int64 `meddler:"user_synced" json:"synced_at"`
TokenExpiry int64 `meddler:"user_access_expires" json:"-"`
TokenExpiry int64 `meddler:"user_access_expires,zeroisnull" json:"-"`
}
func NewUser(remote, login, email string) *User {