88 lines
1.4 KiB
Markdown
88 lines
1.4 KiB
Markdown
# Webstore Backend (Laxer + CQRS + Prisma)
|
|
|
|
Educational Node.js backend for frontend students.
|
|
|
|
## Structure
|
|
|
|
```
|
|
backend/
|
|
prisma/
|
|
schema.prisma
|
|
seed.js
|
|
public/
|
|
images/
|
|
scripts/
|
|
extract-images-from-build.bat
|
|
src/
|
|
Api/
|
|
Controller/
|
|
Router/
|
|
Middleware/
|
|
app.js
|
|
server.js
|
|
Application/
|
|
User/
|
|
Command/
|
|
command.js
|
|
commandhandler.js
|
|
Querry/
|
|
query.js
|
|
queryhandler.js
|
|
Services/
|
|
DTO/
|
|
Domain/
|
|
IRepository/
|
|
Models/
|
|
Infrastructure/
|
|
Repository/
|
|
config/
|
|
env.js
|
|
prisma.js
|
|
```
|
|
|
|
## Run with Docker Compose
|
|
|
|
```bash
|
|
docker compose up --build
|
|
```
|
|
|
|
This starts PostgreSQL and API, runs Prisma generate/db push/seed automatically.
|
|
|
|
## Auth (JWT in Cookie)
|
|
|
|
- `POST /api/users/register`
|
|
- `POST /api/users/login`
|
|
- `GET /api/users/me` (requires cookie)
|
|
- `POST /api/users/logout` (requires cookie)
|
|
|
|
Cookie is HTTP-only and set with `sameSite=lax`.
|
|
|
|
## Shop endpoints
|
|
|
|
- `GET /api/health`
|
|
- `GET /api/shop/categories`
|
|
- `GET /api/shop/products`
|
|
- `POST /api/shop/orders`
|
|
|
|
Order payload:
|
|
|
|
```json
|
|
{
|
|
"customer_name": "Jane Doe",
|
|
"customer_email": "jane@example.com",
|
|
"items": [
|
|
{ "product_id": 1, "quantity": 2 }
|
|
]
|
|
}
|
|
```
|
|
|
|
## Image extraction batch
|
|
|
|
```bat
|
|
scripts\extract-images-from-build.bat "..\build" ".\public\images"
|
|
```
|
|
|
|
Defaults (if arguments omitted):
|
|
|
|
- Source: `..\build`
|
|
- Target: `.\public\images` |