From b905b744c78a607e887216af7734c3132a471f72 Mon Sep 17 00:00:00 2001 From: Lucas Sousa Date: Thu, 10 Aug 2023 11:51:27 +0200 Subject: [PATCH] Add file handler fn to create files [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. --- backend/src/gpml/handler/file.clj | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/backend/src/gpml/handler/file.clj b/backend/src/gpml/handler/file.clj index 6feb47947..f91967fb1 100644 --- a/backend/src/gpml/handler/file.clj +++ b/backend/src/gpml/handler/file.clj @@ -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)