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 rootRouteImport } from './routes/__root'
|
||||||
import { Route as SignupRouteImport } from './routes/signup'
|
import { Route as SignupRouteImport } from './routes/signup'
|
||||||
|
import { Route as PlacesRouteImport } from './routes/places'
|
||||||
import { Route as LogoutRouteImport } from './routes/logout'
|
import { Route as LogoutRouteImport } from './routes/logout'
|
||||||
import { Route as LoginRouteImport } from './routes/login'
|
import { Route as LoginRouteImport } from './routes/login'
|
||||||
import { Route as AuthedRouteImport } from './routes/_authed'
|
import { Route as AuthedRouteImport } from './routes/_authed'
|
||||||
@ -21,6 +22,11 @@ const SignupRoute = SignupRouteImport.update({
|
|||||||
path: '/signup',
|
path: '/signup',
|
||||||
getParentRoute: () => rootRouteImport,
|
getParentRoute: () => rootRouteImport,
|
||||||
} as any)
|
} as any)
|
||||||
|
const PlacesRoute = PlacesRouteImport.update({
|
||||||
|
id: '/places',
|
||||||
|
path: '/places',
|
||||||
|
getParentRoute: () => rootRouteImport,
|
||||||
|
} as any)
|
||||||
const LogoutRoute = LogoutRouteImport.update({
|
const LogoutRoute = LogoutRouteImport.update({
|
||||||
id: '/logout',
|
id: '/logout',
|
||||||
path: '/logout',
|
path: '/logout',
|
||||||
@ -50,6 +56,7 @@ export interface FileRoutesByFullPath {
|
|||||||
'/': typeof IndexRoute
|
'/': typeof IndexRoute
|
||||||
'/login': typeof LoginRoute
|
'/login': typeof LoginRoute
|
||||||
'/logout': typeof LogoutRoute
|
'/logout': typeof LogoutRoute
|
||||||
|
'/places': typeof PlacesRoute
|
||||||
'/signup': typeof SignupRoute
|
'/signup': typeof SignupRoute
|
||||||
'/dashboard': typeof AuthedDashboardRoute
|
'/dashboard': typeof AuthedDashboardRoute
|
||||||
}
|
}
|
||||||
@ -57,6 +64,7 @@ export interface FileRoutesByTo {
|
|||||||
'/': typeof IndexRoute
|
'/': typeof IndexRoute
|
||||||
'/login': typeof LoginRoute
|
'/login': typeof LoginRoute
|
||||||
'/logout': typeof LogoutRoute
|
'/logout': typeof LogoutRoute
|
||||||
|
'/places': typeof PlacesRoute
|
||||||
'/signup': typeof SignupRoute
|
'/signup': typeof SignupRoute
|
||||||
'/dashboard': typeof AuthedDashboardRoute
|
'/dashboard': typeof AuthedDashboardRoute
|
||||||
}
|
}
|
||||||
@ -66,20 +74,22 @@ export interface FileRoutesById {
|
|||||||
'/_authed': typeof AuthedRouteWithChildren
|
'/_authed': typeof AuthedRouteWithChildren
|
||||||
'/login': typeof LoginRoute
|
'/login': typeof LoginRoute
|
||||||
'/logout': typeof LogoutRoute
|
'/logout': typeof LogoutRoute
|
||||||
|
'/places': typeof PlacesRoute
|
||||||
'/signup': typeof SignupRoute
|
'/signup': typeof SignupRoute
|
||||||
'/_authed/dashboard': typeof AuthedDashboardRoute
|
'/_authed/dashboard': typeof AuthedDashboardRoute
|
||||||
}
|
}
|
||||||
export interface FileRouteTypes {
|
export interface FileRouteTypes {
|
||||||
fileRoutesByFullPath: FileRoutesByFullPath
|
fileRoutesByFullPath: FileRoutesByFullPath
|
||||||
fullPaths: '/' | '/login' | '/logout' | '/signup' | '/dashboard'
|
fullPaths: '/' | '/login' | '/logout' | '/places' | '/signup' | '/dashboard'
|
||||||
fileRoutesByTo: FileRoutesByTo
|
fileRoutesByTo: FileRoutesByTo
|
||||||
to: '/' | '/login' | '/logout' | '/signup' | '/dashboard'
|
to: '/' | '/login' | '/logout' | '/places' | '/signup' | '/dashboard'
|
||||||
id:
|
id:
|
||||||
| '__root__'
|
| '__root__'
|
||||||
| '/'
|
| '/'
|
||||||
| '/_authed'
|
| '/_authed'
|
||||||
| '/login'
|
| '/login'
|
||||||
| '/logout'
|
| '/logout'
|
||||||
|
| '/places'
|
||||||
| '/signup'
|
| '/signup'
|
||||||
| '/_authed/dashboard'
|
| '/_authed/dashboard'
|
||||||
fileRoutesById: FileRoutesById
|
fileRoutesById: FileRoutesById
|
||||||
@ -89,6 +99,7 @@ export interface RootRouteChildren {
|
|||||||
AuthedRoute: typeof AuthedRouteWithChildren
|
AuthedRoute: typeof AuthedRouteWithChildren
|
||||||
LoginRoute: typeof LoginRoute
|
LoginRoute: typeof LoginRoute
|
||||||
LogoutRoute: typeof LogoutRoute
|
LogoutRoute: typeof LogoutRoute
|
||||||
|
PlacesRoute: typeof PlacesRoute
|
||||||
SignupRoute: typeof SignupRoute
|
SignupRoute: typeof SignupRoute
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,6 +112,13 @@ declare module '@tanstack/react-router' {
|
|||||||
preLoaderRoute: typeof SignupRouteImport
|
preLoaderRoute: typeof SignupRouteImport
|
||||||
parentRoute: typeof rootRouteImport
|
parentRoute: typeof rootRouteImport
|
||||||
}
|
}
|
||||||
|
'/places': {
|
||||||
|
id: '/places'
|
||||||
|
path: '/places'
|
||||||
|
fullPath: '/places'
|
||||||
|
preLoaderRoute: typeof PlacesRouteImport
|
||||||
|
parentRoute: typeof rootRouteImport
|
||||||
|
}
|
||||||
'/logout': {
|
'/logout': {
|
||||||
id: '/logout'
|
id: '/logout'
|
||||||
path: '/logout'
|
path: '/logout'
|
||||||
@ -155,6 +173,7 @@ const rootRouteChildren: RootRouteChildren = {
|
|||||||
AuthedRoute: AuthedRouteWithChildren,
|
AuthedRoute: AuthedRouteWithChildren,
|
||||||
LoginRoute: LoginRoute,
|
LoginRoute: LoginRoute,
|
||||||
LogoutRoute: LogoutRoute,
|
LogoutRoute: LogoutRoute,
|
||||||
|
PlacesRoute: PlacesRoute,
|
||||||
SignupRoute: SignupRoute,
|
SignupRoute: SignupRoute,
|
||||||
}
|
}
|
||||||
export const routeTree = rootRouteImport
|
export const routeTree = rootRouteImport
|
||||||
|
|||||||
@ -80,7 +80,6 @@ function RouteComponent() {
|
|||||||
<p className="text-default-500 text-sm">Ver más</p>
|
<p className="text-default-500 text-sm">Ver más</p>
|
||||||
</CardFooter>
|
</CardFooter>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
{/* === Tarjeta 3: Ofertas de vuelo === */}
|
{/* === Tarjeta 3: Ofertas de vuelo === */}
|
||||||
<Card
|
<Card
|
||||||
shadow="none"
|
shadow="none"
|
||||||
@ -90,11 +89,9 @@ function RouteComponent() {
|
|||||||
<CardHeader className="flex justify-between items-center gap-2">
|
<CardHeader className="flex justify-between items-center gap-2">
|
||||||
<div className="flex flex-col gap-1 justify-start items-start">
|
<div className="flex flex-col gap-1 justify-start items-start">
|
||||||
<h2 className="text-start font-semibold text-lg">
|
<h2 className="text-start font-semibold text-lg">
|
||||||
Ofertas de vuelo
|
Certificados
|
||||||
</h2>
|
</h2>
|
||||||
<p className="text-default-500 text-sm text-start">
|
<p className="text-default-500 text-sm text-start"></p>
|
||||||
Explora y gestiona tus ofertas de vuelo activas.
|
|
||||||
</p>
|
|
||||||
</div>
|
</div>
|
||||||
<Avatar
|
<Avatar
|
||||||
src="/profile.png"
|
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