feat: add parapharmacy API with MongoDB and N8N setup
- Create parapharmacy-api microservice with Express + Swagger + MongoDB - Add product model with full-text search and deduplication - Add CRUD endpoints and bulk upsert for scrapers - Update docker-compose.yml with MongoDB, N8N, and parapharmacy-api services - Add proxy endpoints in FarmaFinder backend for parapharmacy - Update frontend services to use parapharmacy API - Add Swagger documentation at /api/docs
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
# FarmaFinder Parapharmacy API
|
||||
|
||||
Microservicio para productos de parafarmacia de múltiples tiendas españolas.
|
||||
|
||||
## Arquitectura
|
||||
|
||||
```
|
||||
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
|
||||
│ N8N Workflows │────▶│ Parapharmacy │────▶│ MongoDB │
|
||||
│ (Scraper) │ │ API (Express) │ │ │
|
||||
└─────────────────┘ └────────┬─────────┘ └─────────────────┘
|
||||
│
|
||||
▼
|
||||
┌─────────────────┐
|
||||
│ FarmaFinder │
|
||||
│ Backend │
|
||||
└─────────────────┘
|
||||
```
|
||||
|
||||
## Endpoints
|
||||
|
||||
| Método | Ruta | Descripción |
|
||||
|--------|------|-------------|
|
||||
| GET | `/api/products/search?q=term` | Buscar productos |
|
||||
| GET | `/api/products/:id` | Detalle de producto |
|
||||
| GET | `/api/products` | Listar productos |
|
||||
| POST | `/api/products` | Crear producto |
|
||||
| POST | `/api/products/bulk` | Crear/actualizar múltiples |
|
||||
| PUT | `/api/products/:id` | Actualizar producto |
|
||||
| DELETE | `/api/products/:id` | Eliminar producto |
|
||||
| GET | `/api/products/categories` | Listar categorías |
|
||||
| GET | `/api/products/brands` | Listar marcas |
|
||||
| GET | `/api/sources` | Fuentes configuradas |
|
||||
| GET | `/api/health` | Health check |
|
||||
| GET | `/api/docs` | Swagger UI |
|
||||
|
||||
## Desarrollo
|
||||
|
||||
### Requisitos
|
||||
|
||||
- Node.js 20+
|
||||
- MongoDB 7+
|
||||
|
||||
### Instalación
|
||||
|
||||
```bash
|
||||
cd apps/parapharmacy-api
|
||||
npm install
|
||||
```
|
||||
|
||||
### Ejecutar
|
||||
|
||||
```bash
|
||||
# Desarrollo
|
||||
npm run dev
|
||||
|
||||
# Producción
|
||||
npm start
|
||||
```
|
||||
|
||||
### Variables de Entorno
|
||||
|
||||
```bash
|
||||
PORT=3002
|
||||
MONGODB_URI=mongodb://localhost:27017/parapharmacy
|
||||
CORS_ORIGIN=http://localhost:3000
|
||||
```
|
||||
|
||||
## Docker
|
||||
|
||||
```bash
|
||||
# Construir imagen
|
||||
docker build -t farmafinder-parapharmacy-api .
|
||||
|
||||
# Ejecutar
|
||||
docker run -p 3002:3002 -e MONGODB_URI=mongodb://host:27017/parapharmacy farmafinder-parapharmacy-api
|
||||
```
|
||||
|
||||
## Fuentes de Scraping
|
||||
|
||||
| Fuente | URL | Estado |
|
||||
|--------|-----|--------|
|
||||
| Promofarma | promofarma.com | ✅ |
|
||||
| Pharmarket | pharmarket.es | 🔄 Pendiente |
|
||||
| DocMorris | docmorris.es | 🔄 Pendiente |
|
||||
| 1001Farma | 1001farma.net | 🔄 Pendiente |
|
||||
| Primor | primor.eu | 🔄 Pendiente |
|
||||
| MiFarma | mifarma.es | 🔄 Pendiente |
|
||||
|
||||
## Schema MongoDB
|
||||
|
||||
```javascript
|
||||
{
|
||||
name: String, // Nombre del producto
|
||||
brand: String, // Marca
|
||||
category: String, // Categoría
|
||||
subcategory: String, // Subcategoría
|
||||
description: String, // Descripción
|
||||
image_url: String, // URL imagen
|
||||
source_url: String, // URL tienda original
|
||||
price: Number, // Precio actual
|
||||
original_price: Number, // Precio anterior
|
||||
source: String, // Fuente
|
||||
source_product_id: String,
|
||||
available: Boolean,
|
||||
rating: Number,
|
||||
review_count: Number,
|
||||
scraped_at: Date
|
||||
}
|
||||
```
|
||||
|
||||
## Tests
|
||||
|
||||
```bash
|
||||
npm test
|
||||
```
|
||||
|
||||
## Swagger
|
||||
|
||||
Documentación disponible en: `http://localhost:3002/api/docs`
|
||||
Reference in New Issue
Block a user