diff --git a/etp-core/etp-backend/src/main/clj/solita/etp/api/energiatodistus.clj b/etp-core/etp-backend/src/main/clj/solita/etp/api/energiatodistus.clj index 4434c1a72..30f65e897 100644 --- a/etp-core/etp-backend/src/main/clj/solita/etp/api/energiatodistus.clj +++ b/etp-core/etp-backend/src/main/clj/solita/etp/api/energiatodistus.clj @@ -19,10 +19,12 @@ [solita.etp.schema.viesti :as viesti-schema] [solita.etp.security :as security] [solita.etp.service.energiatodistus :as energiatodistus-service] + [solita.etp.service.energiatodistus-destruction :as energiatodistus-destruction-service] [solita.etp.service.energiatodistus-csv :as energiatodistus-csv-service] [solita.etp.service.energiatodistus-pdf :as energiatodistus-pdf-service] [solita.etp.service.energiatodistus-search :as energiatodistus-search-service] [solita.etp.service.energiatodistus-xlsx :as energiatodistus-xlsx-service] + [solita.etp.service.kayttaja :as kayttaja-service] [solita.etp.service.json :as json] [solita.etp.service.rooli :as rooli-service] [solita.etp.service.viesti :as viesti-service]) @@ -257,3 +259,15 @@ ["/legacy" ["/2013" (xml-api/post 2013)] ["/2018" (xml-api/post 2018)]]]]) + +(def internal-routes + [["/energiatodistukset" + ["/anonymize-and-delete-expired" + {:post {:summary "Anonymisoi vanhentuneet energiatodistukset ja poistaa niihin linkittyvät dokumentit." + :middleware [[security/wrap-db-application-name + (kayttaja-service/system-kayttaja :expiration)] + [security/wrap-whoami-for-internal-expiration-api]] + :responses {200 {:body nil}} + :handler (fn [{:keys [db aws-s3-client]}] + (r/response (energiatodistus-destruction-service/destroy-expired-energiatodistukset! + db aws-s3-client)))}}]]]) diff --git a/etp-core/etp-backend/src/main/clj/solita/etp/handler.clj b/etp-core/etp-backend/src/main/clj/solita/etp/handler.clj index a9b02623c..54ac03706 100644 --- a/etp-core/etp-backend/src/main/clj/solita/etp/handler.clj +++ b/etp-core/etp-backend/src/main/clj/solita/etp/handler.clj @@ -168,6 +168,7 @@ ["/internal" (concat (tag "Laskutus API" laskutus-api/routes) (tag "Laatija Internal API" laatija-api/internal-routes) + (tag "Energiatodistus Internal API" energiatodistus-api/internal-routes) (tag "Aineisto Internal API" aineisto-api/internal-routes))]] (when config/allow-palveluvayla-api ["/palveluvayla" ["/openapi.json" {:get {:no-doc true :openapi {:info {:title "Energiatodistuspalvelu API" :description "Hae energiatodistuksia pdf tai json muodoissa"} diff --git a/etp-core/etp-backend/src/main/clj/solita/etp/service/energiatodistus_destruction.clj b/etp-core/etp-backend/src/main/clj/solita/etp/service/energiatodistus_destruction.clj index 92bff9477..247fe0f74 100644 --- a/etp-core/etp-backend/src/main/clj/solita/etp/service/energiatodistus_destruction.clj +++ b/etp-core/etp-backend/src/main/clj/solita/etp/service/energiatodistus_destruction.clj @@ -13,6 +13,11 @@ (->> (energiatodistus-destruction-db/select-expired-energiatodistus-ids db) (map :id))) +(defn destroy-expired-energiatodistukset! [db aws-s3-client] + (log/info (str "Destruction of expired energiatodistukset initiated.")) + (let [expired-todistukset (get-currently-expired-todistus-ids db)] + ;; TODO: + nil)) (defn- hard-delete-energiatodistus! "Hard deletes energiatodistus." diff --git a/etp-core/etp-backend/src/test/clj/solita/etp/api/energiatodistus_destruction_test.clj b/etp-core/etp-backend/src/test/clj/solita/etp/api/energiatodistus_destruction_test.clj new file mode 100644 index 000000000..6aa6bdab3 --- /dev/null +++ b/etp-core/etp-backend/src/test/clj/solita/etp/api/energiatodistus_destruction_test.clj @@ -0,0 +1,13 @@ +(ns solita.etp.api.energiatodistus-destruction-test + (:require + [clojure.test :as t] + [ring.mock.request :as mock] + [solita.etp.test-system :as ts])) + +(t/use-fixtures :each ts/fixture) + +(t/deftest can-call-energiatodistus-expiration-endpoint + (t/testing "Can call energiatodistus expiration endpoint" + (let [response (ts/handler (-> (mock/request :post "/api/internal/energiatodistukset/anonymize-and-delete-expired") + (mock/header "Accept" "application/json")))] + (t/is (= (:status response) 200)))))