Skip to content
Browse files

Add endpoint for creating relation. TODO: more testing & write test.

  • Loading branch information...
perweij committed Nov 8, 2019
1 parent cda222a commit da233b72d9d27e1aeebe3f23dfdcef1b1acca9ca
Showing with 25 additions and 3 deletions.
  1. +19 −3 src/clj/jobtech_taxonomy_api/routes/services.clj
  2. +6 −0 src/clj/taxonomy.clj
@@ -282,9 +282,6 @@
{:swagger {:tags ["Private"]}
:middleware [cors/cors auth authorized-private?]}

;; for now used by tests for simple private access. TODO: replace that test call, with call to delete

:summary "Retract the concept with the given ID."
@@ -314,6 +311,25 @@
{:status 200 :body (types/map->nsmap {:time timestamp :concept new-concept}) }
{:status 409 :body (types/map->nsmap {:error "Can't create new concept since it is in conflict with existing concept."}) })))}}]

:summary "Assert a new relation."
:parameters {:query {(ds/opt :relation) (taxonomy/par #{"broader" "narrower" "related" "substitutability-to" "substitutability-from" } "Relation type"),
(ds/opt :definition) (taxonomy/par string? "Description"),
(ds/opt :concept-1) (taxonomy/par string? "ID of source concept"),
(ds/opt :concept-2) (taxonomy/par string? "ID of target concept"),
(ds/opt :substitutability-to) (taxonomy/par int? "substitutability")
:post {:responses {200 {:body types/msg-spec}
409 {:body types/error-spec}
500 {:body types/error-spec}}
:handler (fn [{{{:keys [relation definition concept-1 concept-2 substitutability-to]} :query} :parameters}]
(log/info "POST /relation")
(let [[result new-relation] (concepts/assert-relation concept-1 concept-2 relation definition substitutability-to)]
(if result
{:status 200 :body (types/map->nsmap {:message "Created relation."}) }
{:status 409 :body (types/map->nsmap {:error "Can't create new relation since it is in conflict with existing relation."}) })))}}]

:summary "Replace old concept with a new concept."
@@ -42,6 +42,8 @@
(sp/def ::related (st/spec int?))
(sp/def ::substitutability-to (st/spec int?))
(sp/def ::substitutability-from (st/spec int?))
(sp/def ::concept-1 (st/spec string?))
(sp/def ::concept-2 (st/spec string?))

(sp/def ::relations
@@ -474,6 +476,10 @@
:spec {::message (st/spec string?)}}))
(def ok-spec ::ok)

(sp/def ::msg (ds/spec {:name "msg"
:spec {::message (st/spec string?)}}))
(def msg-spec ::msg)

(sp/def ::ok-concept (ds/spec {:name "ok"
:spec {::time inst?
::concept ::concept }}))

0 comments on commit da233b7

Please sign in to comment.
You can’t perform that action at this time.