Skip to content

Commit

Permalink
Oma endpoint yhteystietojen hakemiseen
Browse files Browse the repository at this point in the history
  • Loading branch information
hajoa committed Dec 4, 2024
1 parent 80d1e7e commit 23ec7b6
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
14 changes: 9 additions & 5 deletions src/clj/maksut/maksut/maksut_service.clj
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
(defn- contact-email [lasku]
(case (or (get-in lasku [:metadata :order-id-prefix])
(:origin lasku))
"kkhakemusmaksu" "hakemusmaksut@oph.fi"
"kkhakemusmaksu" "applicationfee@oph.fi"
"OTR" "[email protected]"
"AKR" "[email protected]"
"[email protected]"))
Expand Down Expand Up @@ -158,10 +158,14 @@
(if all-passed?
(do
(log/warn (str "Kaikki laskut vanhentuneet, laskut: " laskut))
{:laskut []
:contact (contact-email (first laskut))})
{:laskut (map Lasku->json laskut)}))
[])
(map Lasku->json laskut)))
(do (log/error (str "Linkki on väärä tai vanhentunut: " secret))
(maksut-error :invoice-notfound-secret (str "Linkki on väärä tai vanhentunut: " secret) {:status-code 404})))))
(maksut-error :invoice-notfound-secret (str "Linkki on väärä tai vanhentunut: " secret) {:status-code 404}))))

(get-lasku-contact [_ _ secret]
(if-let [laskut (seq (maksut-queries/get-laskut-by-secret db secret))]
{:contact (contact-email (first laskut))}
(maksut-error :invoice-notfound-secret (str "Linkki on väärä tai vanhentunut: " secret) {:status-code 404}))))


1 change: 1 addition & 0 deletions src/clj/maksut/maksut/maksut_service_protocol.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
(list-laskut [this session input])
(check-status [this session input])
(get-lasku [this session order-id])
(get-lasku-contact [this session secret])
(get-laskut-by-secret [this session secret]))
12 changes: 11 additions & 1 deletion src/clj/maksut/routes.clj
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,21 @@
{:get {;No authentication for this service, accessed from /maksut/ Web-page
:tags ["Laskut"]
:summary "Palauttaa laskut salaisuuden perusteella"
:responses {200 {:body schema/LaskutResponse}}
:responses {200 {:body schema/Laskut}}
:parameters {:query {:secret s/Str}}
:handler (fn [{session :session {secret :query} :parameters}]
(response/ok (maksut-protocol/get-laskut-by-secret maksut-service session (:secret secret))))}}]]

["/lasku-contact"
[""
{:get {;No authentication for this service, accessed from /maksut/ Web-page
:tags ["Laskut"]
:summary "Palauttaa laskun yhteystiedot salaisuuden perusteella"
:responses {200 {:body {:contact s/Str}}}
:parameters {:query {:secret s/Str}}
:handler (fn [{session :session {secret :query} :parameters}]
(response/ok (maksut-protocol/get-lasku-contact maksut-service session (:secret secret))))}}]]

["/kuitti/:file-key"
[""
{:get {:middleware auth
Expand Down
5 changes: 3 additions & 2 deletions src/maksut-ui/app/[locale]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fetchLaskutBySecret } from '@/app/lib/data';
import { fetchLaskuContact, fetchLaskutBySecret } from '@/app/lib/data';
import MaksutPanel from '@/app/components/MaksutPanel';
import { notFound, redirect } from 'next/navigation';
import Header from '@/app/components/Header';
Expand All @@ -22,10 +22,11 @@ export default async function Page({
if (!secret) {
notFound();
}
const { laskut, contact } = await fetchLaskutBySecret(secret);
const laskut = await fetchLaskutBySecret(secret);
const activeLasku = laskut.find((lasku) => lasku.secret === secret);

if (!laskut.length || !activeLasku) {
const { contact } = await fetchLaskuContact(secret);
return <ExpiredPanel contact={contact} />;
}

Expand Down
22 changes: 21 additions & 1 deletion src/maksut-ui/app/lib/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { notFound } from 'next/navigation';

export const fetchLaskutBySecret = async (
secret: string | undefined,
): Promise<{ laskut: Lasku[]; contact?: string }> => {
): Promise<Lasku[]> => {
if (!secret) {
notFound();
}
const response = await fetch(
`${backendUrl}/laskut-by-secret?secret=${secret}`,
{ cache: 'no-cache' },
Expand All @@ -16,3 +19,20 @@ export const fetchLaskutBySecret = async (
}
throw Error(response.statusText);
};

export const fetchLaskuContact = async (
secret: string | undefined,
): Promise<{ contact: string }> => {
if (!secret) {
notFound();
}
const response = await fetch(`${backendUrl}/lasku-contact?secret=${secret}`, {
cache: 'no-cache',
});
if (response.ok) {
return await response.json();
} else if (response.status === 404) {
notFound();
}
throw Error(response.statusText);
};

0 comments on commit 23ec7b6

Please sign in to comment.