Skip to content

Commit

Permalink
Merge pull request #264 from alwinsimon/v1
Browse files Browse the repository at this point in the history
V1
  • Loading branch information
alwinsimon authored Oct 29, 2023
2 parents e444225 + f278aed commit 631012f
Show file tree
Hide file tree
Showing 41 changed files with 628 additions and 43 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/CD - Deploy - Auth Service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# ========================================= CD - Deploy - Auth Service =========================================

name: CD - Deploy - Auth Service

on:
push:
branches:
- production
paths:
- "auth/**"

jobs:
Auth-Service-CD-Pipeline:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- run: cd auth && docker build -t alwinsimon/bookmyseat-auth .
- run: docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
- run: docker push alwinsimon/bookmyseat-auth
- uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- run: doctl kubernetes cluster kubeconfig save bookmyseat-k8s
- run: kubectl rollout restart deployment auth-depl
22 changes: 22 additions & 0 deletions .github/workflows/CD - Deploy - Manifests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# ========================================= CD - Deploy - Manifests =========================================

name: CD - Deploy - Manifests

on:
push:
branches:
- production
paths:
- "infra/**"

jobs:
Deploy-Manifests-CD-Pipeline:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- run: doctl kubernetes cluster kubeconfig save bookmyseat-k8s
- run: kubectl apply -f infra/k8s
16 changes: 16 additions & 0 deletions .github/workflows/CI - Tests - Auth Service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# ========================================= CI - Tests - Auth Service =========================================

name: CI - Tests - Auth Service

on:
pull_request:
paths:
- "auth/**"

jobs:
Auth-Service-Pre-Integration-Tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- run: cd auth && npm install && npm run test:ci
16 changes: 16 additions & 0 deletions .github/workflows/CI - Tests - Orders Service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# ========================================= CI - Tests - Orders Service =========================================

name: CI - Tests - Orders Service

on:
pull_request:
paths:
- "orders/**"

jobs:
Orders-Service-Pre-Integration-Tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- run: cd orders && npm install && npm run test:ci
16 changes: 16 additions & 0 deletions .github/workflows/CI - Tests - Payments Service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# ========================================= CI - Tests - Payments Service =========================================

name: CI - Tests - Payments Service

on:
pull_request:
paths:
- "payments/**"

jobs:
Payments-Service-Pre-Integration-Tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- run: cd payments && npm install && npm run test:ci
16 changes: 16 additions & 0 deletions .github/workflows/CI - Tests - Tickets Service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# ========================================= CI - Tests - Tickets Service =========================================

name: CI - Tests - Tickets Service

on:
pull_request:
paths:
- "tickets/**"

jobs:
Tickets-Service-Pre-Integration-Tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- run: cd tickets && 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
1 change: 0 additions & 1 deletion auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import mongoose from "mongoose";
import { app } from "./app";

const startServer = async () => {

const PORT = 3000;
const SERVICE_NAME = "AUTH";

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;
Loading

0 comments on commit 631012f

Please sign in to comment.