-
Lorem ipsum ametre
-
-
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi in
- sodales mauris.
-
+
{journey.title}
+
+
{journey.description}
-
Normandie
+
{journey.steps[0].city}
diff --git a/src/components/JourneysFeed.tsx b/src/components/JourneysFeed.tsx
new file mode 100644
index 0000000..27fe778
--- /dev/null
+++ b/src/components/JourneysFeed.tsx
@@ -0,0 +1,27 @@
+import { getAllJourneys } from "@/services/journeyService";
+import { handleException } from "@/app/utils/errorHandlerUtils";
+import JourneyCard from "./JourneyCard";
+
+async function getData() {
+ try {
+ const result = await getAllJourneys();
+ return result;
+ } catch (error: any) {
+ console.log(error, "error");
+ handleException(error);
+ }
+}
+
+const JourneysFeed = async () => {
+ const journeys = await getData();
+ if (!journeys) return;
+ return (
+ <>
+ {journeys.map((journey, i) => (
+
+ ))}
+ >
+ );
+};
+
+export default JourneysFeed;
diff --git a/src/repositories/journeyRepository.ts b/src/repositories/journeyRepository.ts
index e345ab7..7fe03f2 100644
--- a/src/repositories/journeyRepository.ts
+++ b/src/repositories/journeyRepository.ts
@@ -3,6 +3,7 @@ import {
JourneyWithoutDates,
JourneyWithComments,
JourneyWithSteps,
+ JourneyWithStepsAndComments,
} from "@/types/journey";
import { StepWithoutDates } from "@/types/step";
import { Journey } from "@prisma/client";
@@ -113,11 +114,26 @@ export const readJourneyWithComments = async (
};
/**
- * @returns Journey[]
+ * @returns JourneyWithStepsAndComments[]
* @description Retrieves all journeys.
*/
-export const readJourneys = async (): Promise
=> {
- return await prisma.journey.findMany();
+export const readJourneys = async (): Promise<
+ JourneyWithStepsAndComments[]
+> => {
+ return await prisma.journey.findMany({
+ include: {
+ steps: {
+ orderBy: {
+ stepNumber: "asc",
+ },
+ },
+ comments: {
+ orderBy: {
+ createdAt: "asc",
+ },
+ },
+ },
+ });
};
/**
diff --git a/src/services/journeyService.ts b/src/services/journeyService.ts
index cc1a4ca..7937d3a 100644
--- a/src/services/journeyService.ts
+++ b/src/services/journeyService.ts
@@ -17,6 +17,7 @@ import {
JourneyWithoutDates,
JourneyWithComments,
JourneyWithSteps,
+ JourneyWithStepsAndComments,
} from "@/types/journey";
import { StepWithoutDates } from "@/types/step";
@@ -66,11 +67,13 @@ export const getJourneyByIdWithComments = async (
};
/**
- * @returns Journey[]
+ * @returns JourneyWithStepsAndComments[]
* @throws NotFoundException
* @description Retrieves all journeys without steps.
*/
-export const getAllJourneys = async (): Promise => {
+export const getAllJourneys = async (): Promise<
+ JourneyWithStepsAndComments[]
+> => {
const journeys = await readJourneys();
if (!journeys || journeys.length === 0)
diff --git a/src/types/journey.ts b/src/types/journey.ts
index 37d7d33..78ac145 100644
--- a/src/types/journey.ts
+++ b/src/types/journey.ts
@@ -8,6 +8,10 @@ export type JourneyWithSteps = Prisma.JourneyGetPayload<{
include: { steps: true };
}>;
+export type JourneyWithStepsAndComments = Prisma.JourneyGetPayload<{
+ include: { steps: true; comments: true };
+}>;
+
export type JourneyWithoutDates = {
id?: number;
authorId: number;