Fix tenant register
This commit is contained in:
@@ -12,7 +12,7 @@ from app.core.config import settings
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@router.post("/")
|
@router.post("/register")
|
||||||
async def create_tenant(request: Request):
|
async def create_tenant(request: Request):
|
||||||
"""Proxy tenant creation to tenant service"""
|
"""Proxy tenant creation to tenant service"""
|
||||||
try:
|
try:
|
||||||
@@ -21,7 +21,7 @@ async def create_tenant(request: Request):
|
|||||||
|
|
||||||
async with httpx.AsyncClient(timeout=10.0) as client:
|
async with httpx.AsyncClient(timeout=10.0) as client:
|
||||||
response = await client.post(
|
response = await client.post(
|
||||||
f"{settings.TENANT_SERVICE_URL}/tenants",
|
f"{settings.TENANT_SERVICE_URL}/api/v1/tenants/register",
|
||||||
content=body,
|
content=body,
|
||||||
headers={
|
headers={
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|||||||
@@ -119,37 +119,6 @@ fi
|
|||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
|
|
||||||
# ================================================================
|
|
||||||
# STEP 5: TENANT REGISTRATION (OPTIONAL)
|
|
||||||
# ================================================================
|
|
||||||
|
|
||||||
log_step "Step 5: Registering a bakery/tenant"
|
|
||||||
|
|
||||||
BAKERY_RESPONSE=$(curl -s -X POST "$API_BASE/api/v1/tenants/bakeries" \
|
|
||||||
-H "Authorization: Bearer $ACCESS_TOKEN" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "{
|
|
||||||
\"name\": \"Test Bakery $(date +%H%M)\",
|
|
||||||
\"business_type\": \"bakery\",
|
|
||||||
\"address\": \"Calle Test 123\",
|
|
||||||
\"city\": \"Madrid\",
|
|
||||||
\"postal_code\": \"28001\",
|
|
||||||
\"phone\": \"+34600123456\"
|
|
||||||
}")
|
|
||||||
|
|
||||||
echo "Bakery Registration Response:"
|
|
||||||
echo "$BAKERY_RESPONSE" | jq '.'
|
|
||||||
|
|
||||||
if echo "$BAKERY_RESPONSE" | jq -e '.id' > /dev/null; then
|
|
||||||
TENANT_ID=$(echo "$BAKERY_RESPONSE" | jq -r '.id')
|
|
||||||
log_success "Bakery registration successful! Tenant ID: $TENANT_ID"
|
|
||||||
else
|
|
||||||
log_warning "Bakery registration endpoint may not be fully implemented"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
# ================================================================
|
# ================================================================
|
||||||
# STEP 2: USER LOGIN
|
# STEP 2: USER LOGIN
|
||||||
# ================================================================
|
# ================================================================
|
||||||
@@ -179,30 +148,6 @@ fi
|
|||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# ================================================================
|
|
||||||
# STEP 3: TOKEN VERIFICATION
|
|
||||||
# ================================================================
|
|
||||||
|
|
||||||
log_step "Step 3: Verifying access token"
|
|
||||||
|
|
||||||
VERIFY_RESPONSE=$(curl -s -X POST "$AUTH_BASE/verify" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "{
|
|
||||||
\"token\": \"$ACCESS_TOKEN\"
|
|
||||||
}")
|
|
||||||
|
|
||||||
echo "Token Verification Response:"
|
|
||||||
echo "$VERIFY_RESPONSE" | jq '.'
|
|
||||||
|
|
||||||
if echo "$VERIFY_RESPONSE" | jq -e '.valid' > /dev/null; then
|
|
||||||
log_success "Token verification successful!"
|
|
||||||
else
|
|
||||||
log_error "Token verification failed!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
# ================================================================
|
# ================================================================
|
||||||
# STEP 4: ACCESSING PROTECTED ENDPOINTS
|
# STEP 4: ACCESSING PROTECTED ENDPOINTS
|
||||||
# ================================================================
|
# ================================================================
|
||||||
@@ -268,6 +213,36 @@ fi
|
|||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
|
# ================================================================
|
||||||
|
# STEP 5: TENANT REGISTRATION (OPTIONAL)
|
||||||
|
# ================================================================
|
||||||
|
|
||||||
|
log_step "Step 5: Registering a bakery/tenant"
|
||||||
|
|
||||||
|
BAKERY_RESPONSE=$(curl -s -X POST "$API_BASE/api/v1/tenants/register" \
|
||||||
|
-H "Authorization: Bearer $ACCESS_TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "{
|
||||||
|
\"name\": \"Test Bakery $(date +%H%M)\",
|
||||||
|
\"business_type\": \"bakery\",
|
||||||
|
\"address\": \"Calle Test 123\",
|
||||||
|
\"city\": \"Madrid\",
|
||||||
|
\"postal_code\": \"28001\",
|
||||||
|
\"phone\": \"+34600123456\"
|
||||||
|
}")
|
||||||
|
|
||||||
|
echo "Bakery Registration Response:"
|
||||||
|
echo "$BAKERY_RESPONSE" | jq '.'
|
||||||
|
|
||||||
|
if echo "$BAKERY_RESPONSE" | jq -e '.id' > /dev/null; then
|
||||||
|
TENANT_ID=$(echo "$BAKERY_RESPONSE" | jq -r '.id')
|
||||||
|
log_success "Bakery registration successful! Tenant ID: $TENANT_ID"
|
||||||
|
else
|
||||||
|
log_warning "Bakery registration endpoint may not be fully implemented"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
|
||||||
# ================================================================
|
# ================================================================
|
||||||
# STEP 6: TOKEN REFRESH
|
# STEP 6: TOKEN REFRESH
|
||||||
# ================================================================
|
# ================================================================
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ services:
|
|||||||
- DATABASE_URL=postgresql+asyncpg://auth_user:auth_pass123@auth-db:5432/auth_db
|
- DATABASE_URL=postgresql+asyncpg://auth_user:auth_pass123@auth-db:5432/auth_db
|
||||||
- REDIS_URL=redis://redis:6379/0
|
- REDIS_URL=redis://redis:6379/0
|
||||||
- RABBITMQ_URL=amqp://bakery:forecast123@rabbitmq:5672/
|
- RABBITMQ_URL=amqp://bakery:forecast123@rabbitmq:5672/
|
||||||
- JWT_SECRET_KEY=your-super-secret-jwt-key-change-in-production
|
|
||||||
- DEBUG=true
|
- DEBUG=true
|
||||||
- LOG_LEVEL=INFO
|
- LOG_LEVEL=INFO
|
||||||
ports:
|
ports:
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ from shared.auth.decorators import require_authentication, get_current_user, get
|
|||||||
logger = structlog.get_logger()
|
logger = structlog.get_logger()
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@router.post("/bakeries", response_model=TenantResponse)
|
@router.post("/tenants/register", response_model=TenantResponse)
|
||||||
@require_authentication
|
@require_authentication
|
||||||
async def register_bakery(
|
async def register_bakery(
|
||||||
bakery_data: BakeryRegistration,
|
bakery_data: BakeryRegistration,
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class BaseServiceSettings(BaseSettings):
|
|||||||
# ================================================================
|
# ================================================================
|
||||||
|
|
||||||
# JWT Configuration
|
# JWT Configuration
|
||||||
JWT_SECRET_KEY: str = os.getenv("JWT_SECRET_KEY", "change-this-in-production")
|
JWT_SECRET_KEY: str = os.getenv("JWT_SECRET_KEY", "your-super-secret-jwt-key-change-in-production-min-32-characters-long")
|
||||||
JWT_ALGORITHM: str = os.getenv("JWT_ALGORITHM", "HS256")
|
JWT_ALGORITHM: str = os.getenv("JWT_ALGORITHM", "HS256")
|
||||||
JWT_ACCESS_TOKEN_EXPIRE_MINUTES: int = int(os.getenv("JWT_ACCESS_TOKEN_EXPIRE_MINUTES", "30"))
|
JWT_ACCESS_TOKEN_EXPIRE_MINUTES: int = int(os.getenv("JWT_ACCESS_TOKEN_EXPIRE_MINUTES", "30"))
|
||||||
JWT_REFRESH_TOKEN_EXPIRE_DAYS: int = int(os.getenv("JWT_REFRESH_TOKEN_EXPIRE_DAYS", "7"))
|
JWT_REFRESH_TOKEN_EXPIRE_DAYS: int = int(os.getenv("JWT_REFRESH_TOKEN_EXPIRE_DAYS", "7"))
|
||||||
|
|||||||
Reference in New Issue
Block a user