Skip to content

Commit

Permalink
Added gene/{id}/update-other-names PUT and DELETE REST API endpoints …
Browse files Browse the repository at this point in the history
…to add/delete a set of other-names from a gene its other-names #304
  • Loading branch information
mluypaert committed Jul 9, 2020
1 parent 529fb3a commit fc6a6d4
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/wormbase/names/entity.clj
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,27 @@
(not-found
(format "%s '%s' does not exist" ent-ns (last lur)))))))))))

(defn update-multi-card
[identify-fn uiident dt-transact-fn attr]
(fn handle-multi-card [request identifier]
(let [{conn :conn payload :body-params} request
ent-ns (namespace uiident)
data (some-> payload :data)
[lur entity] (identify-fn request identifier)]
(when (and entity data)
(let [build-tx (fn [id attr ^String val] (vec [dt-transact-fn id attr val]))
;;retriev db-id to add values to
db-id (:db/id entity)
;;build transaction statements to make
txes (map #(build-tx db-id attr %) data)
;;transact data to datomic
tx-result @(d/transact-async conn txes)]
(when-let [db-after (:db-after tx-result)]
(if-let [updated (wdb/pull db-after [attr uiident] lur)]
(ok (or (attr updated) []))
(not-found
(format "%s '%s' does not exist" ent-ns (last lur))))))))))

(defn status-changer
"Return a handler to change the status of an entity to `to-status`.
Expand Down
26 changes: 26 additions & 0 deletions src/wormbase/names/gene.clj
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,32 @@
(nil? (:cgc-name data)))
(bad-request! {:message "CGC name cannot be removed from an uncloned gene."}))
(update-gene request identifier)))}})
(sweet/context "/update-other-names" []
(sweet/resource
{:put
{:summary "Add a set of other-names to a gene."
:x-name ::add-other-names-gene
:parameters {:body-params {:data ::wsg/update-other-names
:prov ::wsp/provenance}}
:responses (-> wnu/default-responses
(dissoc conflict)
(assoc bad-request {:schema ::wsv/error-response})
(wnu/response-map))
:handler (fn [request]
(let [add-other-names (wne/update-multi-card identify :gene/id :db/add ':gene/other-names)]
(add-other-names request identifier)))}
:delete
{:summary "Delete a set of other-names from a gene."
:x-name ::delete-other-names-gene
:parameters {:body-params {:data ::wsg/update-other-names
:prov ::wsp/provenance}}
:responses (-> wnu/default-responses
(dissoc conflict)
(assoc bad-request {:schema ::wsv/error-response})
(wnu/response-map))
:handler (fn [request]
(let [delete-other-names (wne/update-multi-card identify :gene/id :db/retract ':gene/other-names)]
(delete-other-names request identifier)))}}))
(sweet/context "/merge/:from-identifier" [from-identifier]
(sweet/resource
{:post
Expand Down
4 changes: 3 additions & 1 deletion src/wormbase/specs/gene.clj
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@

(s/def ::update (stc/spec {:spec (s/and (s/keys :opt-un [:gene/cgc-name
:gene/sequence-name
:gene/other-names
:gene/biotype
:gene/species])
seq)
Expand All @@ -94,6 +93,9 @@
(s/def ::updated (stc/spec {:spec (s/keys :req-un [:gene/id])
:description "The response data from updating a Gene."}))

(s/def ::update-other-names (stc/spec {:spec :gene/other-names
:description "A collection of other names."}))

(s/def ::merge (stc/spec {:spec (s/keys :req-un [:gene/biotype])
:description "The data requried to update a Gene."}))

Expand Down

0 comments on commit fc6a6d4

Please sign in to comment.