Skip to content

Commit 7563635

Browse files
committed
Initial cafe frontend page with backend integration
1 parent 3ee0d14 commit 7563635

File tree

27 files changed

+1083
-123
lines changed

27 files changed

+1083
-123
lines changed

README.md

Lines changed: 53 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,41 @@
1-
<p align="center">
2-
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
3-
</p>
4-
5-
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
6-
[circleci-url]: https://circleci.com/gh/nestjs/nest
7-
8-
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
9-
<p align="center">
10-
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
11-
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
12-
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
13-
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
14-
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
15-
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
16-
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
17-
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
18-
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
19-
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
20-
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
21-
</p>
22-
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
23-
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->
24-
25-
## Description
26-
27-
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
1+
2+
# Frontend+Backend Docker Demo
3+
4+
5+
286

297
## Installation
308

9+
10+
11+
### Run and Deploy Instantly
3112
```bash
32-
$ pnpm install
13+
$ docker-compose up
3314
```
3415

35-
## Running the app
16+
### Run Individually
17+
18+
#### 1) Backend (default url http://localhost:8888)
19+
20+
```bash
21+
$ cd backend
22+
$ pnpm install
23+
$ docker-compose up
24+
````
25+
26+
27+
#### 2) Frontend (default url http://localhost:3000)
28+
```bash
29+
$ cd frontend
30+
$ pnpm install
31+
$ pnpm run start
32+
````
33+
34+
35+
36+
## Other useful scripts
3637
38+
### Backend
3739
```bash
3840
# development
3941
$ pnpm run start
@@ -43,11 +45,7 @@ $ pnpm run start:dev
4345

4446
# production mode
4547
$ pnpm run start:prod
46-
```
47-
48-
## Test
4948

50-
```bash
5149
# unit tests
5250
$ pnpm run test
5351

@@ -57,21 +55,33 @@ $ pnpm run test:e2e
5755
# test coverage
5856
$ pnpm run test:cov
5957
```
60-
61-
##
62-
Use Prisma CLI to apply migrations and generate the Prisma client:
58+
---
59+
> NOTE: Remember any db schema change you need to run migrate
60+
```bash
61+
$ npx prisma migrate dev
62+
$ npx prisma generate
63+
```
6364

6465
```bash
65-
npx prisma migrate dev
66-
npx prisma generate
66+
# Docker commands
67+
$ docker ps -a
68+
$ docker system prune -a
69+
$ docker ps -a
70+
$ docker rm <id>
6771

6872

69-
# Docker commands
70-
docker system prune -a
73+
# db only
7174
docker-compose up db
7275

73-
```
76+
# frontend only
77+
docker-compose up frontend
78+
79+
# backend only
80+
docker-compose up backend
7481

75-
## License
82+
```
7683

77-
Nest is [MIT licensed](LICENSE).
84+
----
85+
### Frontend
86+
###
87+
To know check out the guideline [Read more](./frontend/README.md)

backend/.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
55
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
66

7-
DATABASE_URL=mysql://root:password@localhost:3306/cedb
7+
#DATABASE_URL=mysql://root:password@localhost:3306/cedb
8+
DATABASE_URL=mysql://root:password@127.0.0.1:3306/cedb
89

910
NODE_LOCAL_PORT=8888
1011
NODE_DOCKER_PORT=8888

backend/README.md

Lines changed: 79 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,3 @@
1-
<p align="center">
2-
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
3-
</p>
4-
5-
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
6-
[circleci-url]: https://circleci.com/gh/nestjs/nest
7-
8-
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
9-
<p align="center">
10-
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
11-
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
12-
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
13-
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
14-
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
15-
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
16-
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
17-
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
18-
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
19-
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
20-
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
21-
</p>
22-
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
23-
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->
24-
25-
## Description
261

272
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
283

@@ -57,17 +32,94 @@ $ pnpm run test:e2e
5732
# test coverage
5833
$ pnpm run test:cov
5934
```
60-
35+
6136
##
6237
Use Prisma CLI to apply migrations and generate the Prisma client:
6338

6439
```bash
6540
npx prisma migrate dev
6641
npx prisma generate
6742

68-
docker system prune -a
6943
```
7044

45+
## API
46+
47+
Default service api url
48+
http://location:8888
49+
50+
> CRUD Operations:
51+
### Employees
52+
53+
* READ: /employees (GET)
54+
* READ: /employees/:id (GET)
55+
* CREATE: /employees (POST)
56+
* UPDATE: /employees/:id (PATCH)
57+
* DELETE: /employees/:id (DELETE)
58+
59+
### Cafes
60+
61+
* READ: /cafes (GET)
62+
* READ: /cafes/:id (GET)
63+
* CREATE: /cafes (POST)
64+
* UPDATE: /cafes/:id (PATCH)
65+
* DELETE: /cafes/:id (DELETE)
66+
67+
### Sample
68+
69+
**Create Cafes**
70+
<img src="screenshots/cafe.png" />
71+
Request:
72+
```json
73+
{
74+
"name": "Cafe2",
75+
"description": "Some desc",
76+
"employees": 2,
77+
"logo": "somelogo.png",
78+
"location": "sg"
79+
}
80+
81+
```
82+
83+
Response
84+
```json
85+
{
86+
"id": 3,
87+
"name": "Cafe2",
88+
"description": "Some desc",
89+
"employees": 2,
90+
"logo": "somelogo.png",
91+
"location": "sg"
92+
}
93+
```
94+
----
95+
**Create Employees**
96+
<img src="screenshots/employee.png" />
97+
98+
Request:
99+
```json
100+
{
101+
"name": "Employee1",
102+
"email_address": "test@test.com",
103+
"phone_number": "+658888888",
104+
"days_worked": 1,
105+
"cafe": "Cafe1"
106+
}
107+
108+
```
109+
110+
Response
111+
```json
112+
{
113+
"id": 1,
114+
"name": "Employee1",
115+
"email_address": "test@test.com",
116+
"phone_number": "+658888888",
117+
"days_worked": 1,
118+
"cafe": "Cafe1"
119+
}
120+
```
121+
122+
71123
## License
72124

73125
Nest is [MIT licensed](LICENSE).

backend/prisma/schema.prisma

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
generator client {
22
provider = "prisma-client-js"
33
binaryTargets = ["native", "debian-openssl-3.0.x"]
4-
// binaryTargets = ["native", "darwin", "debian-openssl-1.1.x"]
5-
// binaryTargets = ["native", "linux-musl-openssl-3.0.0"]
64
}
75

86
datasource db {
@@ -14,9 +12,9 @@ model Cafes {
1412
id Int @id @default(autoincrement())
1513
name String @unique
1614
description String
17-
employees Int
1815
logo String
1916
location String
17+
employees Int
2018
}
2119

2220
model Employees {

backend/screenshots/cafe.png

99 KB
Loading

backend/screenshots/employee.png

100 KB
Loading

backend/src/app.module.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,11 @@ import { Module } from '@nestjs/common';
22
import { AppController } from './app.controller';
33
import { AppService } from './app.service';
44
import { DatabaseModule } from './database/database.module';
5-
import { ProductsModule } from './products/products.module';
6-
import { ReviewsModule } from './reviews/reviews.module';
75
import { CafesModule } from './cafes/cafes.module';
86
import { EmployeesModule } from './employees/employees.module';
97

108
@Module({
11-
imports: [
12-
DatabaseModule,
13-
ProductsModule,
14-
ReviewsModule,
15-
CafesModule,
16-
EmployeesModule,
17-
],
9+
imports: [DatabaseModule, CafesModule, EmployeesModule],
1810
controllers: [AppController],
1911
providers: [AppService],
2012
})

backend/src/main.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ import { AppModule } from './app.module';
44
async function bootstrap() {
55
const app = await NestFactory.create(AppModule);
66
const port = process.env.NODE_DOCKER_PORT;
7-
await app.listen(port);
7+
const options = {
8+
origin: '*',
9+
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',
10+
preflightContinue: false,
11+
optionsSuccessStatus: 204,
12+
credentials: true,
13+
};
14+
15+
app.enableCors(options);
16+
await app.listen(8888);
817
}
918
bootstrap();

frontend/README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,75 @@
22

33
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
44

5+
6+
### Features
7+
8+
-[React.js](https://react.dev/)
9+
-[Material-UI](https://mui.com/)
10+
- 🔥 Type checking [TypeScript](https://www.typescriptlang.org)
11+
- 💎 Integrate with [Tailwind CSS](https://tailwindcss.com)
12+
- ✅ Strict Mode for TypeScript and React 18
13+
- 📏 Linter with [ESLint](https://eslint.org) (default NextJS, NextJS Core Web Vitals, Tailwind CSS and Airbnb configuration)
14+
- 💖 Code Formatter with [Prettier](https://prettier.io)
15+
- 🦊 Husky for Git Hooks
16+
- 🚫 Lint-staged for running linters on Git staged files
17+
- 🗂 VSCode configuration: Debug, Settings, Tasks and extension for PostCSS, ESLint, Prettier, TypeScript, Jest
18+
19+
### Requirements
20+
21+
- Node.js 16+ and pnpm
22+
23+
### Getting started
24+
25+
Run the following command on your local environment:
26+
27+
```shell
28+
git clone --depth=1 https://github.com/sonht113/react-boilerplate-for-starter.git
29+
cd my-project-name
30+
pnpm install
31+
```
32+
33+
Then, you can run locally in development mode with live reload:
34+
35+
```shell
36+
pnpm run dev
37+
```
38+
39+
Open http://localhost:5173 with your favorite browser to see your project.
40+
41+
```shell
42+
.
43+
├── README.md # README file
44+
├── .github # GitHub folder
45+
├── .husky # Husky configuration
46+
├── public # Public assets folder
47+
├── src
48+
│ ├── apis # Common apis folder
49+
│ ├── components # Component folder
50+
│ ├── configs # Config and constants
51+
│ └── api # api and services hooks
52+
│ ├── hooks # Hooks customs folder
53+
│ ├── layouts # Layout Pages
54+
│ └── pages # React JS Pages
55+
│ ├── providers # Provider folder
56+
│ └── routes # Routes folder
57+
│ ├── helpers # Shared types and utils functions
58+
│ ├── @types # typescript defintions
59+
├── tailwind.config.js # Tailwind CSS configuration
60+
└── tsconfig.json # TypeScript configuration
61+
```
62+
63+
### Customization
64+
65+
- `src/index.css`: your CSS file using Tailwind CSS
66+
- `src/main.tsx`: default theme
67+
68+
You have access to the whole code source if you need further customization. The provided code is only example for you to start your project. The sky is the limit 🚀.
69+
70+
71+
---
72+
73+
574
Currently, two official plugins are available:
675

776
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
-265 KB
Binary file not shown.

0 commit comments

Comments
 (0)