81 lines
2.0 KiB
Markdown
81 lines
2.0 KiB
Markdown
# Második Gyakorlat - MINTA Megoldás
|
|
|
|
Ez a mappa tartalmazza a második gyakorlat **teljes, működő megoldását**.
|
|
|
|
## Amit implementáltunk:
|
|
|
|
### 1. **Prisma ORM + SQLite**
|
|
- Prisma schema definiálása
|
|
- User model adatbázis szinten
|
|
- Migrációk kezelése
|
|
|
|
### 2. **CQRS Pattern + Layered Architecture**
|
|
- **API Layer**: Controllers, Routes
|
|
- **Application Layer**: Commands, Queries, Handlers
|
|
- **Domain Layer**: Models, Interfaces
|
|
- **Infrastructure Layer**: Prisma, Repositories
|
|
|
|
### 3. **Repository Pattern**
|
|
- `IUserRepository` interface
|
|
- `UserRepository` Prisma implementáció
|
|
- Minden adatbázis művelet a repository-n keresztül
|
|
|
|
### 4. **Domain Model**
|
|
- User osztály üzleti logikával
|
|
- Validációk
|
|
- Helper metódusok (isAdmin, canEdit, validate)
|
|
|
|
## Indítás
|
|
|
|
```bash
|
|
npm install
|
|
npx prisma generate
|
|
npx prisma migrate dev --name init
|
|
npm run dev
|
|
```
|
|
|
|
A szerver elindul a `http://localhost:3000` címen.
|
|
|
|
## API Endpoints
|
|
|
|
- `GET /api/users` - Összes user
|
|
- `GET /api/users/:id` - Egy user
|
|
- `POST /api/users` - User létrehozása
|
|
- `PUT /api/users/:id` - User frissítése
|
|
- `DELETE /api/users/:id` - User törlése
|
|
|
|
## Példa Használat
|
|
|
|
```bash
|
|
# User létrehozása
|
|
curl -X POST http://localhost:3000/api/users \
|
|
-H "Content-Type: application/json" \
|
|
-d '{
|
|
"email": "test@test.com",
|
|
"name": "Test User",
|
|
"password": "password123"
|
|
}'
|
|
|
|
# Összes user lekérése
|
|
curl http://localhost:3000/api/users
|
|
|
|
# User frissítése
|
|
curl -X PUT http://localhost:3000/api/users/1 \
|
|
-H "Content-Type: application/json" \
|
|
-d '{
|
|
"name": "Updated Name"
|
|
}'
|
|
|
|
# User törlése
|
|
curl -X DELETE http://localhost:3000/api/users/1
|
|
```
|
|
|
|
## Tanulási Pontok
|
|
|
|
1. **Prisma ORM**: Modern ORM használata Node.js-ben
|
|
2. **SQLite**: Egyszerű file-based adatbázis
|
|
3. **CQRS**: Command/Query szétválasztás
|
|
4. **Layered Architecture**: Rétegezett architektúra
|
|
5. **Domain Model**: Üzleti logika a domain rétegben
|
|
6. **Repository Pattern**: Adatelérés absztrakciója
|