Skip to content

Commit

Permalink
CORE-6: added Swagger docs to the POST /secured/filetypes/type endp…
Browse files Browse the repository at this point in the history
…oint
  • Loading branch information
slr71 committed Feb 19, 2019
1 parent 458daf6 commit 0ec7428
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 8 deletions.
18 changes: 18 additions & 0 deletions resources/docs/post-filetypes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Sets or clears a file type. The file type can be set by passing in the name of one of the supported file types, which
can be obtained by calling the `GET /secured/filetypes/type-list` endpoint, for example:

``` json
{
"path": "/path/to/irods/file",
"type": "csv"
}
```

The file type can be cleared by passing in the empty string as the file type:

``` json
{
"path": "/path/to/irods/file",
"type": ""
}
```
17 changes: 15 additions & 2 deletions src/terrain/clients/data_info/raw.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@
:post http/post
:put http/put))

(defn- data-info-url
[& url-path]
(str (apply url/url (cfg/data-info-base-url) url-path)))

(defn- put-options
([user body]
(put-options user body {}))
([user body params]
{:form-params body
:query-params (assoc params :user user)
:content-type :json
:as :json}))

(defn request
"This function makes an HTTP request to the data-info service. It uses clj-http to make the
request."
Expand Down Expand Up @@ -325,8 +338,8 @@
(defn set-file-type
"Uses the data-info set-type endpoint to change the type of a file."
[user path-uuid type]
(request :put ["data" path-uuid "type"]
(mk-req-map user (json/encode {:type type}))))
(:body (http/put (data-info-url "data" path-uuid "type")
(put-options user {:type type}))))

(defn path-list-creator
"Uses the data-info path-list-creator endpoint to create an HT Path List files for a set of file/folder paths."
Expand Down
2 changes: 1 addition & 1 deletion src/terrain/routes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
{:name "coge", :description "CoGe Endpoints"}
{:name "collaborator-lists", :description "Collaborator List Endpoints"}
{:name "communities", :description "Community Endpoints"}
{:name "favorites", :description "Favorites Endpoints"}
{:name "data", :description "Data Endpoints"}
{:name "filesystem", :description "Filesystem Endpoints"}
{:name "subjects", :description "Subject Endpoints"}
{:name "teams", :description "Team Endpoints"}
Expand Down
19 changes: 14 additions & 5 deletions src/terrain/routes/data.clj
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
(ns terrain.routes.data
(:use [common-swagger-api.schema]
[ring.util.http-response :only [ok]]
[terrain.services.sharing :only [share unshare]]
[terrain.auth.user-attributes]
[terrain.util])
[terrain.routes.schemas.filetypes]
[terrain.util]
[terrain.util.transformers :only [add-current-user-to-map]])
(:require [terrain.util.config :as config]
[terrain.clients.data-info :as data]
[terrain.clients.saved-searches :as saved]))
Expand All @@ -13,11 +16,17 @@
(optional-routes
[config/data-routes-enabled]

(POST "/filetypes/type" [:as req]
(controller req data/set-file-type :params :body))
(context "/filetypes" []
:tags ["data"]

(GET "/filetypes/type-list" [:as req]
(controller req data/get-type-list))
(POST "/type" []
:summary "Set or Remove File Type Labels"
:body [body (describe FileType "The file type to set")]
:description-file "docs/post-filetypes.md"
(ok (data/set-file-type (add-current-user-to-map {}) body)))

(GET "/type-list" [:as req]
(controller req data/get-type-list)))

(POST "/share" [:as req]
(share req))
Expand Down
9 changes: 9 additions & 0 deletions src/terrain/routes/schemas/filetypes.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(ns terrain.routes.schemas.filetypes
(:use [common-swagger-api.schema :only [describe NonBlankString]])
(:require [common-swagger-api.schema.filetypes :as filetype-schema]))

(def FileType
(assoc filetype-schema/FileType
:path (describe NonBlankString "The iRODS path to the file")))

(def FileTypeReturn filetype-schema/FileTypeReturn)

0 comments on commit 0ec7428

Please sign in to comment.