Skip to content

Commit

Permalink
bug: fix reorder folders
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignacio López-Amor committed Sep 24, 2024
1 parent 8e7af9d commit 62f79b5
Show file tree
Hide file tree
Showing 130 changed files with 16,311 additions and 5,262 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.expo
node_modules
28 changes: 28 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// https://docs.expo.dev/guides/using-eslint/
module.exports = {
extends: ["expo", "prettier"],
plugins: ["prettier", "import"],
rules: {
"prettier/prettier": "error",
"import/order": [
"error",
{
groups: [
"builtin",
"external",
"internal",
"parent",
"sibling",
"index",
"object",
"type",
],
"newlines-between": "always",
alphabetize: {
order: "asc",
caseInsensitive: true,
},
},
],
},
};
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ npm-debug.*
*.mobileprovision
*.orig.*
web-build/
coverage/

# macOS
.DS_Store

# @generated expo-cli sync-2b81b286409207a5da26e14c78851eb30d8ccbdb
# The following patterns were generated by expo-cli

expo-env.d.ts
# @end expo-cli

# env
.env
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["prettier-plugin-tailwindcss"]
}
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"cSpell.words": ["Lngs"]
}
3 changes: 3 additions & 0 deletions .watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// {
// "ignore_dirs": ["node_modules", ".git", ".expo"]
// }
50 changes: 0 additions & 50 deletions README.md

This file was deleted.

22 changes: 15 additions & 7 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"expo": {
"name": "car-service",
"slug": "car-service",
"name": "ridenext",
"slug": "ridenext",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/images/icon.png",
Expand All @@ -10,7 +10,7 @@
"splash": {
"image": "./assets/images/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
"backgroundColor": "#2F80ED"
},
"ios": {
"supportsTablet": true
Expand All @@ -19,18 +19,26 @@
"adaptiveIcon": {
"foregroundImage": "./assets/images/adaptive-icon.png",
"backgroundColor": "#ffffff"
}
},
"package": "com.ignacio68.ridenext"
},
"web": {
"bundler": "metro",
"output": "static",
"output": "server",
"favicon": "./assets/images/favicon.png"
},
"plugins": [
"expo-router"
[
"expo-router",
{
"origin": "https://uber.com/"
}
],
"expo-localization"
],
"experiments": {
"typedRoutes": true
}
},
"jsEngine": "hermes"
}
}
54 changes: 54 additions & 0 deletions app/(api)/(stripe)/create+api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Stripe } from "stripe";

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);

export async function POST(request: Request) {
const body = await request.json();
const { name, email, amount } = body;

if (!name || !email || !amount) {
return new Response(JSON.stringify({ error: "Missing required fields" }), {
status: 400,
});
}

let customer;

const existingCustomer = await stripe.customers.list({
email,
});

if (existingCustomer.data.length > 0) {
customer = existingCustomer.data[0];
} else {
const newCustomer = await stripe.customers.create({
name,
email,
});

customer = newCustomer;
}

const ephemeralKey = await stripe.ephemeralKeys.create(
{ customer: customer.id },
{ apiVersion: "2024-06-20" },
);

const paymentIntent = await stripe.paymentIntents.create({
amount: parseInt(amount) * 100,
currency: "eur",
customer: customer.id,
automatic_payment_methods: {
enabled: true,
allow_redirects: "never",
},
});

return new Response(
JSON.stringify({
paymentIntent: paymentIntent,
ephemeralKey: ephemeralKey,
customer: customer.id,
}),
);
}
51 changes: 51 additions & 0 deletions app/(api)/(stripe)/pay+api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Stripe } from "stripe";

const apiKey = process.env.STRIPE_SECRET_KEY as string;

const stripe = new Stripe(apiKey);

export async function POST(request: Request) {
try {
const body = await request.json();
const { payment_method_id, payment_intent_id, customer_id } = body;

if (!payment_method_id || !payment_intent_id || !customer_id) {
return new Response(
JSON.stringify({ error: "Missing required payment information" }),
{
status: 400,
},
);
}

const paymentMethod = await stripe.paymentMethods.attach(
payment_method_id,
{
customer: customer_id,
},
);

const result = await stripe.paymentIntents.confirm(payment_intent_id, {
payment_method: paymentMethod.id,
});

return new Response(
JSON.stringify({
success: true,
message: "Payment confirmed successfully",
result,
}),
);
} catch (error) {
console.log(error);

return new Response(
JSON.stringify({
success: false,
message: "Payment failed",
status: 500,
error,
}),
);
}
}
14 changes: 14 additions & 0 deletions app/(api)/driver+api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { neon } from "@neondatabase/serverless";

export async function GET() {
try {
const sql = neon(`${process.env.DATABASE_URL}`);

const response = await sql`SELECT * FROM drivers`;

return Response.json({ data: response }, { status: 201 });
} catch (error) {
console.log(error);
return Response.json({ error }, { status: 500 });
}
}
46 changes: 46 additions & 0 deletions app/(api)/ride/[id]+api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { neon } from "@neondatabase/serverless";

export async function GET(request: Request, { id }: { id: string }) {
if (!id)
return Response.json({ error: "Missing required fields" }, { status: 400 });

try {
const sql = neon(`${process.env.DATABASE_URL}`);
const response = await sql`
SELECT
rides.ride_id,
rides.origin_address,
rides.destination_address,
rides.origin_latitude,
rides.origin_longitude,
rides.destination_latitude,
rides.destination_longitude,
rides.ride_time,
rides.fare_price,
rides.payment_status,
rides.created_at,
'driver', json_build_object(
'driver_id', drivers.id,
'first_name', drivers.first_name,
'last_name', drivers.last_name,
'profile_image_url', drivers.profile_image_url,
'car_image_url', drivers.car_image_url,
'car_seats', drivers.car_seats,
'rating', drivers.rating
) AS driver
FROM
rides
INNER JOIN
drivers ON rides.driver_id = drivers.id
WHERE
rides.user_id = ${id}
ORDER BY
rides.created_at DESC;
`;

return Response.json({ data: response });
} catch (error) {
console.error("Error fetching recent rides:", error);
return Response.json({ error: "Internal Server Error" }, { status: 500 });
}
}
Loading

0 comments on commit 62f79b5

Please sign in to comment.