Update code in endpoints/login.post.py
This commit is contained in:
parent
0dda885b28
commit
5df7ada483
@ -1,25 +1,41 @@
|
|||||||
from fastapi import APIRouter, Depends, HTTPException
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
from core.auth import get_current_user_dummy
|
|
||||||
from core.database import fake_users_db
|
from core.database import fake_users_db
|
||||||
|
import uuid
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@router.post("/login")
|
@router.post("/books")
|
||||||
async def login_demo(
|
async def create_book(
|
||||||
username: str = "demo",
|
title: str,
|
||||||
password: str = "password"
|
author: str,
|
||||||
|
isbn: str = None,
|
||||||
|
description: str = None
|
||||||
):
|
):
|
||||||
"""Demo login endpoint"""
|
"""Create a new book entry"""
|
||||||
user = fake_users_db.get(username)
|
book_id = str(uuid.uuid4())
|
||||||
if not user or user["password"] != password:
|
|
||||||
raise HTTPException(status_code=400, detail="Invalid credentials")
|
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 {
|
return {
|
||||||
"message": "Login successful (demo)",
|
"message": "Book created successfully",
|
||||||
"user": username,
|
"book_id": book_id,
|
||||||
"token": "dummy_jwt_token_123",
|
"data": new_book,
|
||||||
"features": {
|
"metadata": {
|
||||||
"rate_limit": 100,
|
"timestamp": "demo_timestamp",
|
||||||
"expires_in": 3600
|
"version": "1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user