31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
from typing import List, Optional
|
|
from uuid import UUID
|
|
from sqlalchemy.orm import Session
|
|
from models.contact_form import ContactForm
|
|
from schemas.contact_form import ContactFormSchema
|
|
|
|
def get_contact_form_by_id(db: Session, contact_form_id: UUID) -> Optional[ContactForm]:
|
|
"""
|
|
Retrieves a single contact form by its ID.
|
|
|
|
Args:
|
|
db (Session): The database session.
|
|
contact_form_id (UUID): The ID of the contact form to retrieve.
|
|
|
|
Returns:
|
|
Optional[ContactForm]: The contact form object if found, otherwise None.
|
|
"""
|
|
return db.query(ContactForm).filter(ContactForm.id == contact_form_id).first()
|
|
|
|
def get_all_contact_forms(db: Session) -> List[ContactFormSchema]:
|
|
"""
|
|
Retrieves all contact forms from the database.
|
|
|
|
Args:
|
|
db (Session): The database session.
|
|
|
|
Returns:
|
|
List[ContactFormSchema]: A list of all contact form objects.
|
|
"""
|
|
contact_forms = db.query(ContactForm).all()
|
|
return [ContactFormSchema.from_orm(contact_form) for contact_form in contact_forms] |