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
IUserRepositoryinterfaceUserRepositoryPrisma 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
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 userGET /api/users/:id- Egy userPOST /api/users- User létrehozásaPUT /api/users/:id- User frissítéseDELETE /api/users/:id- User törlése
Példa Használat
# 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
- Prisma ORM: Modern ORM használata Node.js-ben
- SQLite: Egyszerű file-based adatbázis
- CQRS: Command/Query szétválasztás
- Layered Architecture: Rétegezett architektúra
- Domain Model: Üzleti logika a domain rétegben
- Repository Pattern: Adatelérés absztrakciója