diff --git a/alembic/versions/20250415_082522_32ff0133_update_laptopbrand.py b/alembic/versions/20250415_082522_32ff0133_update_laptopbrand.py new file mode 100644 index 0000000..35c639e --- /dev/null +++ b/alembic/versions/20250415_082522_32ff0133_update_laptopbrand.py @@ -0,0 +1,32 @@ +"""create table for laptop_brands + +Revision ID: 8d5c6b9d2b94 +Revises: f4c2e3a1c7b4 +Create Date: 2023-05-30 12:00:00 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.sql import func +import uuid + +# revision identifiers, used by Alembic. +revision = '8d5c6b9d2b94' +down_revision = 'f4c2e3a1c7b4' +branch_labels = None +depends_on = None + +def upgrade(): + table_name = "laptop_brands" + + op.create_table( + table_name, + sa.Column('id', sa.String(36), primary_key=True, default=lambda: str(uuid.uuid4())), + sa.Column('name', sa.String(), nullable=False, unique=True), + sa.Column('created_at', sa.DateTime(), server_default=func.now()), + sa.Column('updated_at', sa.DateTime(), server_default=func.now(), onupdate=func.now()) + ) + +def downgrade(): + table_name = "laptop_brands" + op.drop_table(table_name) \ No newline at end of file diff --git a/endpoints/laptops.get.py b/endpoints/laptops.get.py index e69de29..2fc2b85 100644 --- a/endpoints/laptops.get.py +++ b/endpoints/laptops.get.py @@ -0,0 +1,11 @@ +from fastapi import APIRouter, status +from typing import List + +from helpers.laptopbrand_helpers import get_laptop_brands + +router = APIRouter() + +@router.get("/laptops", status_code=status.HTTP_200_OK, response_model=List[str]) +async def get_laptop_brands_route(): + laptop_brands = get_laptop_brands() + return laptop_brands \ No newline at end of file diff --git a/helpers/laptopbrand_helpers.py b/helpers/laptopbrand_helpers.py new file mode 100644 index 0000000..68a06e8 --- /dev/null +++ b/helpers/laptopbrand_helpers.py @@ -0,0 +1,12 @@ +from typing import List + +LAPTOP_BRANDS = ['Dell', 'HP', 'Lenovo', 'Acer', 'Asus', 'Apple', 'Microsoft', 'Toshiba', 'Samsung', 'Sony'] + +def get_laptop_brands() -> List[str]: + """ + Retrieves a list of laptop brand names. + + Returns: + List[str]: A list of laptop brand names. + """ + return LAPTOP_BRANDS \ No newline at end of file diff --git a/models/laptopbrand.py b/models/laptopbrand.py new file mode 100644 index 0000000..31939ce --- /dev/null +++ b/models/laptopbrand.py @@ -0,0 +1,13 @@ +from sqlalchemy import Column, String +from sqlalchemy.dialects.postgresql import UUID +from sqlalchemy.sql import func +from core.database import Base +import uuid + +class LaptopBrand(Base): + __tablename__ = "laptop_brands" + + id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) + name = Column(String, unique=True, nullable=False) + created_at = Column(func.now()) + updated_at = Column(func.now(), onupdate=func.now()) \ No newline at end of file diff --git a/schemas/laptopbrand.py b/schemas/laptopbrand.py new file mode 100644 index 0000000..5ac443b --- /dev/null +++ b/schemas/laptopbrand.py @@ -0,0 +1,21 @@ +from pydantic import BaseModel, Field +from typing import Optional +from datetime import datetime +from uuid import UUID + +class LaptopBrandBase(BaseModel): + name: str = Field(..., description="Laptop brand name") + +class LaptopBrandCreate(LaptopBrandBase): + pass + +class LaptopBrandUpdate(LaptopBrandBase): + name: Optional[str] = Field(None, description="Laptop brand name") + +class LaptopBrandSchema(LaptopBrandBase): + id: UUID + created_at: datetime + updated_at: datetime + + class Config: + orm_mode = True \ No newline at end of file