feat: Generated endpoint endpoints/laptops.get.py via AI for Laptopbrand with auto lint fixes

This commit is contained in:
Backend IM Bot 2025-04-15 08:25:36 +00:00
parent 23b4e17267
commit fd09b27862
5 changed files with 89 additions and 0 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

13
models/laptopbrand.py Normal file
View File

@ -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())

21
schemas/laptopbrand.py Normal file
View File

@ -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