feat: Updated endpoint endpoints/tech.get.py via AI with auto lint fixes

This commit is contained in:
Backend IM Bot 2025-04-14 20:49:06 +00:00
parent dfa057e068
commit a56ea7434e
5 changed files with 40 additions and 6 deletions

View File

@ -0,0 +1,24 @@
"""add tech_career column to careers table
Revision ID: 7b5d6a9c0f4a
Revises: 51f39d7b8e0a
Create Date: 2023-05-22 13:37:12.843148
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '7b5d6a9c0f4a'
down_revision = '51f39d7b8e0a'
branch_labels = None
depends_on = None
def upgrade():
op.add_column('careers', sa.Column('tech_career', sa.Boolean(), nullable=False, server_default='0'))
def downgrade():
op.drop_column('careers', 'tech_career')

View File

@ -9,5 +9,8 @@ router = APIRouter()
@router.get("/tech", status_code=200, response_model=List[CareerSchema])
async def get_tech_careers(db: Session = Depends(get_db)):
"""
Get a list of tech careers.
"""
careers = get_all_careers(db)
return careers

View File

@ -30,23 +30,27 @@ def get_career_by_id(db: Session, career_id: uuid.UUID) -> Optional[Career]:
"""
return db.query(Career).filter(Career.id == career_id).first()
def get_careers_by_name_or_description(db: Session, search_term: str) -> List[Career]:
def get_careers_by_name_or_description(db: Session, search_term: str, tech_career: Optional[bool] = None) -> List[Career]:
"""
Retrieves careers that match the given search term in their name or description.
Retrieves careers that match the given search term in their name or description, optionally filtering by tech career.
Args:
db (Session): The database session.
search_term (str): The search term to match against career names and descriptions.
tech_career (Optional[bool]): Whether to filter for tech careers or non-tech careers. If None, no filtering is applied.
Returns:
List[Career]: A list of career objects that match the search term.
List[Career]: A list of career objects that match the search term and tech career filter.
"""
return db.query(Career).filter(
query = db.query(Career).filter(
or_(
Career.name.ilike(f"%{search_term}%"),
Career.description.ilike(f"%{search_term}%")
)
).all()
)
if tech_career is not None:
query = query.filter(Career.tech_career == tech_career)
return query.all()
def create_career(db: Session, career_data: CareerCreate) -> Career:
"""

View File

@ -1,4 +1,4 @@
from sqlalchemy import Column, String, DateTime
from sqlalchemy import Column, String, DateTime, Boolean
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.sql import func
from core.database import Base
@ -10,5 +10,6 @@ class Career(Base):
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
name = Column(String, nullable=False, unique=True, index=True)
description = Column(String, nullable=True)
tech_career = Column(Boolean, nullable=False, default=False)
created_at = Column(DateTime, default=func.now())
updated_at = Column(DateTime, default=func.now(), onupdate=func.now())

View File

@ -6,6 +6,7 @@ from uuid import UUID
class CareerBase(BaseModel):
name: str = Field(..., description="Name of the career")
description: Optional[str] = Field(None, description="Description of the career")
tech_career: bool = Field(..., description="Whether the career is a tech career or not")
class CareerCreate(CareerBase):
pass
@ -13,6 +14,7 @@ class CareerCreate(CareerBase):
class CareerUpdate(CareerBase):
name: Optional[str] = Field(None, description="Name of the career")
description: Optional[str] = Field(None, description="Description of the career")
tech_career: Optional[bool] = Field(None, description="Whether the career is a tech career or not")
class CareerSchema(CareerBase):
id: UUID