feat: add places route with user place insertion and fetching functionality
This commit is contained in:
parent
b3213045ce
commit
b754ee35cc
14
src/lib/server/places.ts
Normal file
14
src/lib/server/places.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { createServerFn } from "@tanstack/react-start"
|
||||
import { eq } from "drizzle-orm"
|
||||
import { db } from "@/integrations/drizzle"
|
||||
import { places } from "@/integrations/drizzle/db/schema"
|
||||
|
||||
export const insertUserPlace = createServerFn({
|
||||
method: "POST"
|
||||
}).handler(async ({ data }) => {
|
||||
await db.insert(places).values(data).returning()
|
||||
})
|
||||
|
||||
export const getUserPlaces = createServerFn().handler(async () => {
|
||||
return await db.select().from(places).where(eq(places.id_user, "e6472b9d-01a9-4e2e-8bdc-0ddaa9baf5d8")) // No haría falta el where puedo filtrar mediante RSL que solo pueda ver sus places solo los datos que el ha insertado
|
||||
})
|
||||
@ -10,6 +10,7 @@
|
||||
|
||||
import { Route as rootRouteImport } from './routes/__root'
|
||||
import { Route as SignupRouteImport } from './routes/signup'
|
||||
import { Route as PlacesRouteImport } from './routes/places'
|
||||
import { Route as LogoutRouteImport } from './routes/logout'
|
||||
import { Route as LoginRouteImport } from './routes/login'
|
||||
import { Route as AuthedRouteImport } from './routes/_authed'
|
||||
@ -21,6 +22,11 @@ const SignupRoute = SignupRouteImport.update({
|
||||
path: '/signup',
|
||||
getParentRoute: () => rootRouteImport,
|
||||
} as any)
|
||||
const PlacesRoute = PlacesRouteImport.update({
|
||||
id: '/places',
|
||||
path: '/places',
|
||||
getParentRoute: () => rootRouteImport,
|
||||
} as any)
|
||||
const LogoutRoute = LogoutRouteImport.update({
|
||||
id: '/logout',
|
||||
path: '/logout',
|
||||
@ -50,6 +56,7 @@ export interface FileRoutesByFullPath {
|
||||
'/': typeof IndexRoute
|
||||
'/login': typeof LoginRoute
|
||||
'/logout': typeof LogoutRoute
|
||||
'/places': typeof PlacesRoute
|
||||
'/signup': typeof SignupRoute
|
||||
'/dashboard': typeof AuthedDashboardRoute
|
||||
}
|
||||
@ -57,6 +64,7 @@ export interface FileRoutesByTo {
|
||||
'/': typeof IndexRoute
|
||||
'/login': typeof LoginRoute
|
||||
'/logout': typeof LogoutRoute
|
||||
'/places': typeof PlacesRoute
|
||||
'/signup': typeof SignupRoute
|
||||
'/dashboard': typeof AuthedDashboardRoute
|
||||
}
|
||||
@ -66,20 +74,22 @@ export interface FileRoutesById {
|
||||
'/_authed': typeof AuthedRouteWithChildren
|
||||
'/login': typeof LoginRoute
|
||||
'/logout': typeof LogoutRoute
|
||||
'/places': typeof PlacesRoute
|
||||
'/signup': typeof SignupRoute
|
||||
'/_authed/dashboard': typeof AuthedDashboardRoute
|
||||
}
|
||||
export interface FileRouteTypes {
|
||||
fileRoutesByFullPath: FileRoutesByFullPath
|
||||
fullPaths: '/' | '/login' | '/logout' | '/signup' | '/dashboard'
|
||||
fullPaths: '/' | '/login' | '/logout' | '/places' | '/signup' | '/dashboard'
|
||||
fileRoutesByTo: FileRoutesByTo
|
||||
to: '/' | '/login' | '/logout' | '/signup' | '/dashboard'
|
||||
to: '/' | '/login' | '/logout' | '/places' | '/signup' | '/dashboard'
|
||||
id:
|
||||
| '__root__'
|
||||
| '/'
|
||||
| '/_authed'
|
||||
| '/login'
|
||||
| '/logout'
|
||||
| '/places'
|
||||
| '/signup'
|
||||
| '/_authed/dashboard'
|
||||
fileRoutesById: FileRoutesById
|
||||
@ -89,6 +99,7 @@ export interface RootRouteChildren {
|
||||
AuthedRoute: typeof AuthedRouteWithChildren
|
||||
LoginRoute: typeof LoginRoute
|
||||
LogoutRoute: typeof LogoutRoute
|
||||
PlacesRoute: typeof PlacesRoute
|
||||
SignupRoute: typeof SignupRoute
|
||||
}
|
||||
|
||||
@ -101,6 +112,13 @@ declare module '@tanstack/react-router' {
|
||||
preLoaderRoute: typeof SignupRouteImport
|
||||
parentRoute: typeof rootRouteImport
|
||||
}
|
||||
'/places': {
|
||||
id: '/places'
|
||||
path: '/places'
|
||||
fullPath: '/places'
|
||||
preLoaderRoute: typeof PlacesRouteImport
|
||||
parentRoute: typeof rootRouteImport
|
||||
}
|
||||
'/logout': {
|
||||
id: '/logout'
|
||||
path: '/logout'
|
||||
@ -155,6 +173,7 @@ const rootRouteChildren: RootRouteChildren = {
|
||||
AuthedRoute: AuthedRouteWithChildren,
|
||||
LoginRoute: LoginRoute,
|
||||
LogoutRoute: LogoutRoute,
|
||||
PlacesRoute: PlacesRoute,
|
||||
SignupRoute: SignupRoute,
|
||||
}
|
||||
export const routeTree = rootRouteImport
|
||||
|
||||
@ -80,7 +80,6 @@ function RouteComponent() {
|
||||
<p className="text-default-500 text-sm">Ver más</p>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
|
||||
{/* === Tarjeta 3: Ofertas de vuelo === */}
|
||||
<Card
|
||||
shadow="none"
|
||||
@ -90,11 +89,9 @@ function RouteComponent() {
|
||||
<CardHeader className="flex justify-between items-center gap-2">
|
||||
<div className="flex flex-col gap-1 justify-start items-start">
|
||||
<h2 className="text-start font-semibold text-lg">
|
||||
Ofertas de vuelo
|
||||
Certificados
|
||||
</h2>
|
||||
<p className="text-default-500 text-sm text-start">
|
||||
Explora y gestiona tus ofertas de vuelo activas.
|
||||
</p>
|
||||
<p className="text-default-500 text-sm text-start"></p>
|
||||
</div>
|
||||
<Avatar
|
||||
src="/profile.png"
|
||||
|
||||
34
src/routes/places.tsx
Normal file
34
src/routes/places.tsx
Normal file
@ -0,0 +1,34 @@
|
||||
import { Button } from "@heroui/react"
|
||||
import { createFileRoute } from "@tanstack/react-router"
|
||||
import { getUserPlaces, insertUserPlace } from "@/lib/server/places"
|
||||
|
||||
export const Route = createFileRoute("/places")({
|
||||
component: RouteComponent
|
||||
})
|
||||
|
||||
function RouteComponent() {
|
||||
|
||||
const submitUser = async () => {
|
||||
await insertUserPlace({
|
||||
data: {
|
||||
name: "Place 1",
|
||||
description: "A nice place",
|
||||
coord_x: "40.7128",
|
||||
coord_y: "-74.0060",
|
||||
id_user: "e6472b9d-01a9-4e2e-8bdc-0ddaa9baf5d8", // Replace with actual user ID
|
||||
hidden_place: false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const fetchPlaces = async () => {
|
||||
const places = await getUserPlaces();
|
||||
console.log(places);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Button onPress={fetchPlaces}>Click</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user