Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1 #241

Merged
merged 82 commits into from
Oct 28, 2023
Merged

V1 #241

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
050e463
Merge pull request #13 from alwinsimon/v1
alwinsimon Oct 4, 2023
918b253
Merge pull request #15 from alwinsimon/v1
alwinsimon Oct 5, 2023
f8503f3
Merge pull request #17 from alwinsimon/v1
alwinsimon Oct 5, 2023
1c0fa7c
Merge pull request #19 from alwinsimon/v1
alwinsimon Oct 6, 2023
12cabc1
Merge pull request #24 from alwinsimon/v1
alwinsimon Oct 6, 2023
23235c4
Merge pull request #26 from alwinsimon/v1
alwinsimon Oct 8, 2023
4b9dab3
Merge pull request #28 from alwinsimon/v1
alwinsimon Oct 8, 2023
5fb017c
Merge pull request #30 from alwinsimon/v1
alwinsimon Oct 9, 2023
0b700d8
Merge pull request #32 from alwinsimon/v1
alwinsimon Oct 9, 2023
48ea346
Merge pull request #35 from alwinsimon/v1
alwinsimon Oct 9, 2023
58f7970
Merge pull request #37 from alwinsimon/v1
alwinsimon Oct 10, 2023
21ddb83
Merge pull request #50 from alwinsimon/v1
alwinsimon Oct 11, 2023
1ebaba2
Merge pull request #52 from alwinsimon/v1
alwinsimon Oct 11, 2023
0b4cd94
Merge pull request #56 from alwinsimon/v1
alwinsimon Oct 13, 2023
7223af3
Merge pull request #69 from alwinsimon/v1
alwinsimon Oct 14, 2023
ffdbef4
Merge pull request #82 from alwinsimon/v1
alwinsimon Oct 15, 2023
4c14238
Merge pull request #94 from alwinsimon/v1
alwinsimon Oct 16, 2023
7b47a19
Merge pull request #103 from alwinsimon/v1
alwinsimon Oct 17, 2023
4e83a8d
Merge pull request #112 from alwinsimon/v1
alwinsimon Oct 17, 2023
afa8ff3
Merge pull request #114 from alwinsimon/v1
alwinsimon Oct 18, 2023
b74837c
Merge pull request #126 from alwinsimon/v1
alwinsimon Oct 19, 2023
e4d8e5d
Merge pull request #140 from alwinsimon/v1
alwinsimon Oct 20, 2023
05a4da9
Merge pull request #161 from alwinsimon/v1
alwinsimon Oct 21, 2023
274bfcf
Merge pull request #167 from alwinsimon/v1
alwinsimon Oct 21, 2023
26169c7
Merge pull request #181 from alwinsimon/v1
alwinsimon Oct 23, 2023
a8fcc4d
Merge pull request #196 from alwinsimon/v1
alwinsimon Oct 24, 2023
32c64ae
Merge pull request #220 from alwinsimon/v1
alwinsimon Oct 25, 2023
c1b497e
Merge pull request #221 from alwinsimon/v1
alwinsimon Oct 25, 2023
117ce5c
Updated common module.
alwinsimon Oct 25, 2023
146fd8e
Updated common module.
alwinsimon Oct 25, 2023
3ee8d1e
Merge pull request #222 from alwinsimon/v1-tickets
alwinsimon Oct 25, 2023
6fe4f58
Merge pull request #223 from alwinsimon/v1-orders
alwinsimon Oct 25, 2023
8b36d33
Merge pull request #224 from alwinsimon/v1-payments
alwinsimon Oct 25, 2023
84f185f
Merge pull request #225 from alwinsimon/v1-payments
alwinsimon Oct 25, 2023
27023b9
Merge pull request #226 from alwinsimon/v1
alwinsimon Oct 25, 2023
2bc0764
Created a payment created listener.
alwinsimon Oct 26, 2023
e54a178
Configured payment created listener in index file.
alwinsimon Oct 26, 2023
7776dff
Configured Event Expired Listener to prevent cancellation of complete…
alwinsimon Oct 26, 2023
ae9b4de
Merge pull request #227 from alwinsimon/v1-orders
alwinsimon Oct 26, 2023
28c099e
Merge pull request #228 from alwinsimon/v1
alwinsimon Oct 26, 2023
2d888db
Merge pull request #229 from alwinsimon/v1
alwinsimon Oct 26, 2023
308f92b
Added a additional props to pass down current user to all child compo…
alwinsimon Oct 27, 2023
8ee9d22
Modified to remove fetching current user.
alwinsimon Oct 27, 2023
57f8af3
Added two new arguments to child components getInitial props function…
alwinsimon Oct 27, 2023
15a7fea
Modified to receive client and current user.
alwinsimon Oct 27, 2023
aadad87
Created a container div to align the component contents.
alwinsimon Oct 27, 2023
6566659
Added a Ticket Creation Form.
alwinsimon Oct 27, 2023
6d2d2ed
Added api call for form submission.
alwinsimon Oct 27, 2023
d19b4a9
Adder re-routing after ticket creation.
alwinsimon Oct 27, 2023
796aea5
Fixed a reassignment bug.
alwinsimon Oct 27, 2023
61e76fc
Configured Landing page to display created tickets.
alwinsimon Oct 27, 2023
1513bd8
Added a single ticket details page.
alwinsimon Oct 27, 2023
0705ed7
Modified to provide wild-card route to show single ticket information.
alwinsimon Oct 27, 2023
6e8c168
Added purchase button.
alwinsimon Oct 27, 2023
44bea0c
Added a single order page.
alwinsimon Oct 27, 2023
0ca3376
Configured routing to orders page from tickets page.
alwinsimon Oct 27, 2023
9a61a40
Added order expiration Timer.
alwinsimon Oct 27, 2023
9a95553
Added Timer expiration logic.
alwinsimon Oct 27, 2023
940757c
Installed react-stripe-checkout in clients service.
alwinsimon Oct 27, 2023
7d5372b
Installed prop-types for Stripe module support.
alwinsimon Oct 27, 2023
23a902c
Configured card checkout with Stripe module.
alwinsimon Oct 27, 2023
931a5d0
Modified useRequest hook to send additional data into request body if…
alwinsimon Oct 27, 2023
04c6566
Configured to make api call to complete payment with received token f…
alwinsimon Oct 27, 2023
2facf05
Merge pull request #230 from alwinsimon/v1-client
alwinsimon Oct 27, 2023
078bf54
Merge pull request #231 from alwinsimon/v1
alwinsimon Oct 27, 2023
c004a94
Modified API response to return tickets that are available to book (u…
alwinsimon Oct 27, 2023
a19f4af
Merge pull request #232 from alwinsimon/v1-tickets
alwinsimon Oct 27, 2023
3b7ed90
Merge pull request #233 from alwinsimon/v1
alwinsimon Oct 27, 2023
91cbbee
Added two new options in the Header.
alwinsimon Oct 27, 2023
c56758f
Added orders listing page to list order history of user.
alwinsimon Oct 27, 2023
1cfecd5
Modified the redirection - redirection configured to show orders page…
alwinsimon Oct 27, 2023
ddd4772
Merge pull request #234 from alwinsimon/v1-client
alwinsimon Oct 27, 2023
c90d63b
Merge pull request #235 from alwinsimon/v1
alwinsimon Oct 27, 2023
9f30b4c
Create CI - Tests - Auth Service.yml
alwinsimon Oct 28, 2023
da4fc7b
Configured CI Workflow for auth service tests.
alwinsimon Oct 28, 2023
a1c3b3c
Merge pull request #236 from alwinsimon/main
alwinsimon Oct 28, 2023
175b905
Merge pull request #237 from alwinsimon/v1
alwinsimon Oct 28, 2023
9f78a3a
Added Test Script for CI Testing.
alwinsimon Oct 28, 2023
44fac41
Merge pull request #238 from alwinsimon/v1-auth
alwinsimon Oct 28, 2023
18dadae
Merge pull request #239 from alwinsimon/v1
alwinsimon Oct 28, 2023
105be2b
Added script for CI Testing.
alwinsimon Oct 28, 2023
f100ce1
Merge pull request #240 from alwinsimon/v1-orders
alwinsimon Oct 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/CI - Tests - Auth Service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# ========================================= Main Branch ::: CI - Tests - Auth Service =========================================

name: CI - Tests - Auth Service

on: pull_request

jobs:
Production-Branch-Pre-Integration-Tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- run: cd auth && npm install && npm run test:ci
3 changes: 2 additions & 1 deletion auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "index.js",
"scripts": {
"start": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/index.ts",
"test": "jest --watchAll --no-cache"
"test": "jest --watchAll --no-cache",
"test:ci": "jest"
},
"jest": {
"preset": "ts-jest",
Expand Down
8 changes: 5 additions & 3 deletions client/components/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import Link from "next/link";

export default ({ currentUser }) => {
const Links = [
!currentUser && { label: "Sign Up", href: "auth/signup" },
!currentUser && { label: "Sign In", href: "auth/signin" },
currentUser && { label: "Sign Out", href: "auth/signout" },
!currentUser && { label: "Sign Up", href: "/auth/signup" },
!currentUser && { label: "Sign In", href: "/auth/signin" },
currentUser && { label: "Sell Tickets", href: "/tickets/new" },
currentUser && { label: "My Orders", href: "/orders" },
currentUser && { label: "Sign Out", href: "/auth/signout" },
]
.filter((validLinks) => validLinks)
.map(({ label, href }) => {
Expand Down
4 changes: 2 additions & 2 deletions client/hooks/use-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import axios from "axios";
export default ({ url, method, body, onSuccess }) => {
const [errors, setErrors] = useState(null);

const makeRequest = async () => {
const makeRequest = async (props={}) => {
try {
setErrors(null); // Setting error to null initially to prevent errors from being displayed always.

const response = await axios[method](url, body);
const response = await axios[method](url, {...body, ...props});

// If the call back exist, then return the call back with response data.
if (onSuccess) {
Expand Down
32 changes: 31 additions & 1 deletion client/package-lock.json

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

4 changes: 3 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"axios": "^1.5.1",
"bootstrap": "^5.3.2",
"next": "^13.5.4",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
"react-dom": "^18.2.0",
"react-stripe-checkout": "^2.6.3"
}
}
10 changes: 8 additions & 2 deletions client/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const AppComponent = ({ Component, pageProps, currentUser }) => {
return (
<div>
<Header currentUser={currentUser} />
<Component {...pageProps} />
<div className="container">
<Component currentUser={currentUser} {...pageProps} />
</div>
</div>
);
};
Expand All @@ -20,7 +22,11 @@ AppComponent.getInitialProps = async (appContext) => {
// If the child component has getInitialProps method, then execute it manually from here.
let pageProps = {};
if (appContext.Component.getInitialProps) {
pageProps = await appContext.Component.getInitialProps(appContext.ctx);
pageProps = await appContext.Component.getInitialProps(
appContext.ctx,
client,
response.data.currentUser
);
}

return { pageProps, currentUser: response.data.currentUser };
Expand Down
50 changes: 36 additions & 14 deletions client/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,56 @@
import buildClient from "../api/build-client";
import Link from 'next/link';

const IndexPage = ({ currentUser }) => {
const IndexPage = ({ currentUser, tickets }) => {
if (!currentUser) {
return (
<>
<h1>Landing Page</h1>
<br/>
<br />
<h5>Signed Out</h5>
</>
);
}

let ticketList;
if (currentUser) {
ticketList = tickets.map((ticket) => {
return (
<tr key={ticket.id}>
<td>{ticket.title}</td>
<td>{ticket.price}</td>
<td>
<Link href="/tickets/[ticketId]" as={`/tickets/${ticket.id}`}>
View
</Link>
</td>
</tr>
);
});
}

return (
<>
<h1>Landing Page</h1>
<br />
<h5>Welcome {currentUser.email}</h5>

<h1>Tickets</h1>
<table className="table table-striped">
<thead>
<tr>
<th>Title</th>
<th>Price</th>
<th>Action</th>
</tr>
</thead>

<tbody>{currentUser && ticketList}</tbody>
</table>
</>
);
};

IndexPage.getInitialProps = async (context) => {
try {
const client = buildClient(context);
const response = await client.get("/api/users/currentuser");
return response.data;
} catch (err) {
console.error("Error in making request to get current user:", err.message);
return { currentUser: null };
}
IndexPage.getInitialProps = async (context, client, currentUser) => {
const { data } = await client.get("/api/tickets");
return { tickets: data };
};

export default IndexPage;
66 changes: 66 additions & 0 deletions client/pages/orders/[orderId].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { useEffect, useState } from "react";
import Router from "next/router";
import StripeCheckout from "react-stripe-checkout";
import useRequest from "../../hooks/use-request";

const OrderShow = ({ order, currentUser }) => {
const [timeLeft, setTimeLeft] = useState(0);
const [makeRequest, errors] = useRequest({
url: "/api/payments",
method: "post",
body: {
orderId: order.id,
},
onSuccess: (payment) => {
Router.push("/orders");
},
});

useEffect(() => {
const findTimeLeft = () => {
const milliSecondsLeft = new Date(order.expiresAt) - new Date();
const secondsLeft = Math.round(milliSecondsLeft / 1000);

setTimeLeft(secondsLeft);
};

findTimeLeft();
const timer = setInterval(findTimeLeft, 1000);

return () => {
clearInterval(timer);
};
}, [order]);

if (timeLeft < 0) {
return (
<div>
<h3 className="text text-danger">Order Expired !!!</h3>
</div>
);
}

return (
<div>
Time left to complete payment: {timeLeft} seconds.
<StripeCheckout
token={(token) => {
makeRequest({ token: token.id });
}}
stripeKey="pk_test_51O53zRSJtuYafghXhYNZzaJqYAh6afqRduQ3UAMs6Wm4vkv30ayq09gBPgU3jYkQPXrofQa9aRbIlb4uuCp3FC6O000J86xaKc"
amount={order.ticket.price * 100}
email={currentUser.email}
/>
{errors}
</div>
);
};

OrderShow.getInitialProps = async (context, client) => {
const { orderId } = context.query;
const { data } = await client.get(`/api/orders/${orderId}`);

return { order: data };
};

export default OrderShow;
23 changes: 23 additions & 0 deletions client/pages/orders/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const OrderIndex = ({ orders }) => {
return (
<>
<ul>
{orders.map((order) => {
return (
<li key={orders.id}>
{order.ticket.title} - {order.status}
</li>
);
})}
</ul>
</>
);
};

OrderIndex.getInitialProps = async (context, client) => {
const response = await client.get("/api/orders");

return { orders: response.data };
};

export default OrderIndex;
40 changes: 40 additions & 0 deletions client/pages/tickets/[ticketId].js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import Router from "next/router";
import useRequest from "../../hooks/use-request";

const TicketShow = ({ ticket }) => {
const [makeRequest, errors] = useRequest({
url: "/api/orders",
method: "post",
body: {
ticketId: ticket.id,
},
onSuccess: (orderData) => {
Router.push("/orders/[orderId]", `/orders/${orderData.id}`);
},
});

const handleClick = async () => {
makeRequest();
};

return (
<div>
<h1>{ticket.title}</h1>
<h4>Price: {ticket.price} INR</h4>
{errors}
<button className="btn btn-primary" onClick={handleClick}>
Purchase
</button>
</div>
);
};

TicketShow.getInitialProps = async (context, client) => {
const { ticketId } = context.query;

const { data } = await client.get(`/api/tickets/${ticketId}`);

return { ticket: data };
};

export default TicketShow;
Loading