Api - РАБОТАЕТ!!!!!!!!!!

This commit is contained in:
Lev 2025-12-07 21:27:49 +03:00
parent 662b2d9a3a
commit 48ea009cab
3 changed files with 24 additions and 9 deletions

View file

@ -3,7 +3,7 @@ from pydantic import BaseModel, EmailStr
import utils
app = FastAPI()
methods = utils.API("")
args = ["", "", "", "", 0, "", ""]
class RegisterBody(BaseModel) :
email : EmailStr
@ -20,7 +20,9 @@ class UrlsBody(BaseModel) :
@app.post("/registration", status_code=status.HTTP_201_CREATED)
def registration(body: RegisterBody) :
methods = utils.API(*args)
result = methods.registration(body.email, body.password)
methods.close()
if result["code"] == 1:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
@ -30,7 +32,9 @@ def registration(body: RegisterBody) :
@app.post("/login", status_code=status.HTTP_200_OK)
def login(body: LoginBody) :
methods = utils.API(*args)
answer = methods.login(body.email, body.password)
methods.close()
if answer["code"] == 1 :
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
@ -41,7 +45,9 @@ def login(body: LoginBody) :
@app.post("/add_url", status_code=status.HTTP_200_OK)
def add_url(body: UrlsBody) :
methods = utils.API(*args)
answer = methods.add_url(body.email, body.password, body.urls_name)
methods.close()
if answer["code"] == 1 :
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
@ -57,7 +63,9 @@ def add_url(body: UrlsBody) :
@app.get("/get_url", status_code=status.HTTP_200_OK)
def get_url(email: EmailStr = Query(...), password: str = Query(...), urls_name: str = Query(...)) :
methods = utils.API(*args)
answer = methods.get_url(email, password, urls_name)
methods.close()
if answer["code"] == 1 :
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
@ -73,7 +81,9 @@ def get_url(email: EmailStr = Query(...), password: str = Query(...), urls_name:
@app.delete("/del_url", status_code=status.HTTP_200_OK)
def del_url(email: EmailStr = Query(...), password: str = Query(...), urls_name: str = Query(...)) :
methods = utils.API(*args)
answer = methods.del_url(email, password, urls_name)
methods.close()
if answer["code"] == 1 :
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,