From d1686c3aa29ccd6d85afa6f1564bce6dfa2ff575 Mon Sep 17 00:00:00 2001 From: Mickael Kerjean Date: Sat, 1 Sep 2018 02:47:10 +1000 Subject: [PATCH] feature (share): backend of the sharing feature --- server/ctrl/share.go | 51 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 server/ctrl/share.go diff --git a/server/ctrl/share.go b/server/ctrl/share.go new file mode 100644 index 00000000..8c423b1f --- /dev/null +++ b/server/ctrl/share.go @@ -0,0 +1,51 @@ +package ctrl + +import ( + "github.com/mickael-kerjean/mux" + . "github.com/mickael-kerjean/nuage/server/common" + "github.com/mickael-kerjean/nuage/server/model" + "net/http" +) + +type ShareAPI struct { + Id string `json:"id"` + Path string `json:"path"` + Role string `json:"role"` + Password string `json:"password"` + Users []string `json:"users"` + CanManageOwn bool `json:"can_manage_own"` + CanShare bool `json:"can_share"` + Expire int `json:"expire"` + Link string `json:"link"` +} + +func ShareList(ctx App, res http.ResponseWriter, req *http.Request) { + p := extractParams(req) + listOfSharedLinks := model.ShareList(p) + SendSuccessResults(res, listOfSharedLinks) +} + +func ShareUpsert(ctx App, res http.ResponseWriter, req *http.Request) { + p := extractParams(req) + err := model.ShareUpsert(p, model.ShareParams{}) + if err != nil { + SendErrorResult(res, err) + return + } + SendSuccessResult(res, nil) +} + +func ShareDelete(ctx App, res http.ResponseWriter, req *http.Request) { + p := extractParams(req) + err := model.ShareDelete(p) + if err != nil { + SendErrorResult(res, err) + return + } + SendSuccessResult(res, nil) +} + +func extractParams(req *http.Request) model.ShareKey { + vars := mux.Vars(req) + return model.ShareKey{vars["id"], "", ""} +}