23 lines
1.8 KiB
Python
23 lines
1.8 KiB
Python
from fastapi import APIRouter, Depends, HTTPException, status
|
|
from sqlalchemy.orm import Session
|
|
import json
|
|
from ...shared.config.database import get_db
|
|
from ...shared.config.logging_config import get_logger
|
|
from ..models.page_content import PageContent, PageType
|
|
logger = get_logger(__name__)
|
|
router = APIRouter(prefix='/contact-content', tags=['contact-content'])
|
|
|
|
def serialize_page_content(content: PageContent) -> dict:
|
|
return {'id': content.id, 'page_type': content.page_type.value, 'title': content.title, 'subtitle': content.subtitle, 'description': content.description, 'content': content.content, 'meta_title': content.meta_title, 'meta_description': content.meta_description, 'meta_keywords': content.meta_keywords, 'og_title': content.og_title, 'og_description': content.og_description, 'og_image': content.og_image, 'canonical_url': content.canonical_url, 'contact_info': json.loads(content.contact_info) if content.contact_info else None, 'map_url': content.map_url, 'is_active': content.is_active, 'created_at': content.created_at.isoformat() if content.created_at else None, 'updated_at': content.updated_at.isoformat() if content.updated_at else None}
|
|
|
|
@router.get('/')
|
|
async def get_contact_content(db: Session=Depends(get_db)):
|
|
try:
|
|
content = db.query(PageContent).filter(PageContent.page_type == PageType.CONTACT).first()
|
|
if not content:
|
|
return {'status': 'success', 'data': {'page_content': None}}
|
|
content_dict = serialize_page_content(content)
|
|
return {'status': 'success', 'data': {'page_content': content_dict}}
|
|
except Exception as e:
|
|
logger.error(f'Error fetching contact content: {str(e)}', exc_info=True)
|
|
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f'Error fetching contact content: {str(e)}') |