Skip to content

Commit

Permalink
fix pictures in seeder & add carousel home page & add api to get even…
Browse files Browse the repository at this point in the history
…t for a user
  • Loading branch information
MaximeDan committed Jun 25, 2024
1 parent aa601a2 commit 0c301c9
Show file tree
Hide file tree
Showing 14 changed files with 610 additions and 77 deletions.
26 changes: 26 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"date-fns": "^3.6.0",
"embla-carousel-react": "^8.1.5",
"framer-motion": "^11.2.11",
"lucide-react": "^0.396.0",
"next": "14.2.4",
Expand Down
146 changes: 73 additions & 73 deletions prisma/seed.ts

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions public/img/marker.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 12 additions & 1 deletion src/app/(app)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
import TopBar from "@/components/TopBar";
import UserEventsFeed from "@/components/UserEventsFeed";

export default function Home() {
return <main className=""></main>;
return (
<>
<TopBar />
<div className="mt-8">
<h1 className="text-center text-3xl font-bold">Mes événements</h1>
<UserEventsFeed />
</div>
</>
);
}
29 changes: 29 additions & 0 deletions src/app/api/userEvent/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { handleException } from "@/app/utils/errorHandlerUtils";
import { getEventsByUserId } from "@/services/userService";
import { NextRequest, NextResponse } from "next/server";

/**
* @param req
* @returns NextResponse
* @description Handles GET request to retrieve all events for a specific user.
*/
export async function GET(
request: NextRequest,
{ params }: { params: { id: string } },
) {
try {
const userId = Number(params.id);

if (!userId) {
return NextResponse.json(
{ error: "User ID is required" },
{ status: 400 },
);
}

const result = await getEventsByUserId(userId);
return NextResponse.json({ data: result }, { status: 200 });
} catch (error) {
return handleException(error);
}
}
1 change: 1 addition & 0 deletions src/app/apiClient/registerUser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const registerUserApi = async (data: {
email: string;
password: string;
confirmPassword: string;
username: string;
name: string;
lastName: string;
Expand Down
48 changes: 48 additions & 0 deletions src/components/EventUserCarousel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"use client";
import {
Carousel,
CarouselContent,
CarouselItem,
CarouselNext,
CarouselPrevious,
} from "./ui/carousel";
import { Card, CardHeader, CardTitle } from "@/components/ui/card";
import { Event } from "@prisma/client";
import Image from "next/image";

type EventUserCarouselProps = {
events: Event[];
};

const EventUserCarousel: React.FC<EventUserCarouselProps> = ({ events }) => {
return (
<Carousel className="w-full max-w-sm">
<CarouselContent className="-ml-1 flex">
{events.map((event) => (
<CarouselItem key={event.id} className="flex-none basis-1/3 pl-1">
<div className="p-1">
<Card>
{event.image && (
<Image
src={event.image}
alt={event.title}
className="h-32 w-full rounded-t-lg object-cover"
width={320}
height={180}
/>
)}
<CardHeader>
<CardTitle>{event.title}</CardTitle>
</CardHeader>
</Card>
</div>
</CarouselItem>
))}
</CarouselContent>
<CarouselPrevious />
<CarouselNext />
</Carousel>
);
};

export default EventUserCarousel;
25 changes: 25 additions & 0 deletions src/components/UserEventsFeed.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { getEventsByUserId } from "@/services/userService";
import EventUserCarousel from "./EventUserCarousel";
import { Event } from "@prisma/client";

async function fetchUserEvents(userId: number): Promise<Event[]> {
try {
const events = await getEventsByUserId(userId);
return events;
} catch (error) {
console.error("Error fetching user events:", error);
throw error;
}
}

const UserEventsFeed = async () => {
const events = await fetchUserEvents(7);
console.log(events);
return (
<div className="mt-4 flex flex-col items-center justify-center">
<EventUserCarousel events={events} />
</div>
);
};

export default UserEventsFeed;
2 changes: 1 addition & 1 deletion src/components/map/LocationMarker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const LocationMarker = ({
});

const myIcon = L.icon({
iconUrl: "/img/pin.png",
iconUrl: "/img/marker.svg",
iconSize: [30, 30],
iconAnchor: [15, 30],
});
Expand Down
82 changes: 82 additions & 0 deletions src/components/ui/card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { cn } from "@/lib/tailwindUtils";
import * as React from "react";

const Card = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("rounded-lg border bg-white text-black shadow-sm", className)}
{...props}
/>
));
Card.displayName = "Card";

const CardHeader = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex flex-col space-y-1.5 p-6", className)}
{...props}
/>
));
CardHeader.displayName = "CardHeader";

const CardTitle = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLHeadingElement>
>(({ className, ...props }, ref) => (
<h3
ref={ref}
className={cn(
"text-2xl font-semibold leading-none tracking-tight",
className,
)}
{...props}
/>
));
CardTitle.displayName = "CardTitle";

const CardDescription = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLParagraphElement>
>(({ className, ...props }, ref) => (
<p
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
));
CardDescription.displayName = "CardDescription";

const CardContent = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
));
CardContent.displayName = "CardContent";

const CardFooter = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex items-center p-6 pt-0", className)}
{...props}
/>
));
CardFooter.displayName = "CardFooter";

export {
Card,
CardHeader,
CardFooter,
CardTitle,
CardDescription,
CardContent,
};
Loading

0 comments on commit 0c301c9

Please sign in to comment.