Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,5 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

/venv-podman
42 changes: 34 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# node-mentoring-shop
https://d17btkcdsmqrmh.cloudfront.net/node-gmp/docs/express-layered-architecture/task
[https://d17btkcdsmqrmh.cloudfront.net/node-gmp/docs/nosql/homework](https://d17btkcdsmqrmh.cloudfront.net/node-gmp/docs/nosql/homework)

We are going to create an Express application for online shop which sells different types of products (like e.g Amazon).

In this task we are going to implement functionality for managing carts, creating orders and products.
In this task we will modify the application we created in [Express and Layered Architecture](https://github.com/kandalova/node-mentoring-shop/pull/1) module by moving data storage to NoSQL database.

The application has 4 primary entities:

Expand All @@ -27,15 +27,41 @@ One <code>User</code> can have multiple <code>Order</code>. Each <code>Order</co
**Implementation criteria:**

- TypeScript is used.
- Application is implemented following Three Layered Architecture. Layers are separated by file names. For example <code>xxx.repository.ts</code> contains functions to retrieve data (data access layer), <code>xxx.service.ts</code> contains services that implement business logic, <code>xxx.controller.ts</code> contains functions that manage status codes/responses returned (presentation layer).
- Data is stored either in memory or on file system.
- joi is used to validate data in PUT /api/profile/cart.
- Simple authentication middleware is added to check if user with such id exists. User id is passed in x-user-id header.
- Order entity has copy of products. If you have only product id in order, it may lead to inconsistency. For example, if user creates an order and after that price is changed, the order price shouldn't be changed.
- For ```DELETE``` ```/api/profile/cart``` soft-delete approach is be used. Make sure that client of your API will not know that soft-delete approach is used.
- Data is stored in `MongoDB` database.
- `Docker` image is used for local development (check Running [MongoDB as a Docker Container](https://www.baeldung.com/linux/mongodb-as-docker-container#2-building-container-using-a-compose-file) for an example of docker-compose file).
- `Mongoose` is used as ODM for querying.
- `Data Access Layer` is rewritten to query `MongoDB`.
- Models are created based on entity schemas used in Express and Layered Architecture module.
- Models have proper relations between each other based on information specified above.

**API endpoints**

[swagger](https://github.com/kandalova/node-mentoring-shop/blob/task_6_shop_express.js/swagger.md)

<img width="729" alt="image" src="https://github.com/kandalova/node-mentoring-shop/assets/26093763/f1e36899-e171-436e-83c4-72dcb20264e2">

**Setup for startring (once)**

In the project root folder

- Install [podman](https://podman.io/docs/installation)
- Install [podman-compose](https://github.com/containers/podman-compose#installation)
- Init podman machine `podman machine init`
- Install [MongoDB server](https://www.mongodb.com/try/download/community)
- Install MongoDB tools to connect to MongoDB: [Shell](https://www.mongodb.com/try/download/shell) or [Compass Gui](https://www.mongodb.com/try/download/compass)

**To start(every time)**
- `podman machine start` - start virtual machine
- `podman-compose up -d` - starts container from `docker-compose.yaml`
- `podman ps` - check running containers
- Connect to Mongo via Compass or shell `mongosh --port 27017`

[Running MongoDB as a Docker Container](https://www.baeldung.com/linux/mongodb-as-docker-container#2-building-container-using-a-compose-file)

**First time starting**
- Create your first database in MongoDB. Then, create your first collection (Example - User).

**Results**

![image](https://github.com/kandalova/node-mentoring-shop/assets/26093763/9e525a2f-c86b-4ecd-9f4e-5f8fe95a6904)

14 changes: 14 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3'
services:
mongo:
ports:
- '27017:27017'
container_name: mongo
restart: always
logging:
options:
max-size: 1g
environment:
- MONGO_INITDB_ROOT_USERNAME=mongoadmin
- MONGO_INITDB_ROOT_PASSWORD=123admin
image: mongo
Loading