Skip to content

Commit

Permalink
Add file handler fn to create files
Browse files Browse the repository at this point in the history
[Re #1543]

* To be used at the API level since due to historic reasons the API
handler's run inside a transaction and to signal failure and abort the
transaction we have to throw an exception. This should be changed in
the future and use a more ideal approach like we do in the
gpml.service.file namespace.
  • Loading branch information
lucassousaf committed Aug 10, 2023
1 parent 3e2bcd7 commit b905b74
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions backend/src/gpml/handler/file.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
(ns gpml.handler.file
(:require [gpml.db.stakeholder :as db.stakeholder]
[gpml.domain.file :as dom.file]
[gpml.service.file :as srv.file]
[integrant.core :as ig]
[ring.util.response :as resp])
(:import java.io.ByteArrayInputStream
java.util.Base64))

(defn create-file
[config conn file-payload entity-key file-key visibility-key]
(let [file (dom.file/base64->file file-payload entity-key file-key visibility-key)
result (srv.file/create-file config conn file)]
(if (:success? result)
(get-in result [:file :id])
(throw (ex-info "Failed to create file" {})))))

(defmethod ig/init-key :gpml.handler.file/profile-cv [_ {:keys [db]}]
(fn [{{{:keys [id]} :path} :parameters :as req}]
(tap> id)
Expand Down

0 comments on commit b905b74

Please sign in to comment.