From 5df7ada483a86108931bdf1c3c5839a96aa7fee9 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Wed, 19 Mar 2025 22:32:51 +0000 Subject: [PATCH] Update code in endpoints/login.post.py --- endpoints/login.post.py | 48 +++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/endpoints/login.post.py b/endpoints/login.post.py index df5aa08..7fd90ae 100644 --- a/endpoints/login.post.py +++ b/endpoints/login.post.py @@ -1,25 +1,41 @@ from fastapi import APIRouter, Depends, HTTPException -from core.auth import get_current_user_dummy from core.database import fake_users_db +import uuid router = APIRouter() -@router.post("/login") -async def login_demo( - username: str = "demo", - password: str = "password" +@router.post("/books") +async def create_book( + title: str, + author: str, + isbn: str = None, + description: str = None ): - """Demo login endpoint""" - user = fake_users_db.get(username) - if not user or user["password"] != password: - raise HTTPException(status_code=400, detail="Invalid credentials") + """Create a new book entry""" + book_id = str(uuid.uuid4()) + + if isbn in [book.get('isbn') for book in fake_users_db.get('books', [])]: + raise HTTPException(status_code=400, detail="Book with this ISBN already exists") + + new_book = { + "id": book_id, + "title": title, + "author": author, + "isbn": isbn, + "description": description + } + + if 'books' not in fake_users_db: + fake_users_db['books'] = [] + + fake_users_db['books'].append(new_book) return { - "message": "Login successful (demo)", - "user": username, - "token": "dummy_jwt_token_123", - "features": { - "rate_limit": 100, - "expires_in": 3600 + "message": "Book created successfully", + "book_id": book_id, + "data": new_book, + "metadata": { + "timestamp": "demo_timestamp", + "version": "1.0" } - } + } \ No newline at end of file