Skip to content

Commit

Permalink
added support version 2 pydantic
Browse files Browse the repository at this point in the history
  • Loading branch information
darixsamani committed Oct 2, 2023
1 parent fbab3ca commit 87ea9c4
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 28 deletions.
7 changes: 1 addition & 6 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,4 @@ async def read_root():


app.include_router(AdminRouter, tags=["Administrator"], prefix="/admin")
app.include_router(
StudentRouter,
tags=["Students"],
prefix="/student",
dependencies=[Depends(token_listener)],
)
app.include_router(StudentRouter,tags=["Students"],prefix="/student",dependencies=[Depends(token_listener)],)
3 changes: 1 addition & 2 deletions config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

from beanie import init_beanie
from motor.motor_asyncio import AsyncIOMotorClient
from pydantic import BaseSettings

from pydantic_settings import BaseSettings
import models as models


Expand Down
6 changes: 3 additions & 3 deletions models/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Admin(Document):
password: str

class Config:
schema_extra = {
json_schema_extra = {
"example": {
"fullname": "Abdulazeez Abdulazeez Adeshina",
"email": "[email protected]",
Expand All @@ -23,7 +23,7 @@ class Settings:

class AdminSignIn(HTTPBasicCredentials):
class Config:
schema_extra = {
json_schema_extra = {
"example": {"username": "[email protected]", "password": "3xt3m#"}
}

Expand All @@ -33,7 +33,7 @@ class AdminData(BaseModel):
email: EmailStr

class Config:
schema_extra = {
json_schema_extra = {
"example": {
"fullname": "Abdulazeez Abdulazeez Adeshina",
"email": "[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion models/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Student(Document):
gpa: float

class Config:
schema_extra = {
json_schema_extra = {
"example": {
"fullname": "Abdulazeez Abdulazeez Adeshina",
"email": "[email protected]",
Expand Down
49 changes: 35 additions & 14 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
motor #3.1.1
PyJWT
bcrypt # 4.0.1
uvicorn # 0.21.1
pymongo # 4.3.3
fastapi # 0.95.0
pydantic[email,dotenv] #1.10.7
passlib # 1.7.4

beanie # 1.18.0
pytest # 7.3.1
httpx # 0.24.0
mongomock_motor # 0.0.19
pytest-mock # 3.10.0
annotated-types==0.5.0
anyio==3.7.1
bcrypt==4.0.1
beanie==1.22.6
certifi==2023.7.22
click==8.1.7
dnspython==2.4.2
email-validator==2.0.0.post2
exceptiongroup==1.1.3
fastapi==0.103.2
h11==0.14.0
httpcore==0.18.0
httpx==0.25.0
idna==3.4
iniconfig==2.0.0
lazy-model==0.2.0
mongomock==4.1.2
mongomock-motor==0.0.21
motor==3.3.1
packaging==23.2
passlib==1.7.4
pluggy==1.3.0
pydantic==2.4.2
pydantic_core==2.10.1
PyJWT==2.8.0
pymongo==4.5.0
pytest==7.4.2
pytest-mock==3.11.1
sentinels==1.0.0
sniffio==1.3.0
starlette==0.27.0
toml==0.10.2
tomli==2.0.1
typing_extensions==4.8.0
uvicorn==0.23.2
5 changes: 3 additions & 2 deletions routes/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

from auth.jwt_handler import sign_jwt
from database.database import add_admin
from models.admin import Admin, AdminData, AdminSignIn
from models.admin import Admin
from schemas.admin import AdminData, AdminSignIn

router = APIRouter()

Expand All @@ -23,7 +24,7 @@ async def admin_login(admin_credentials: AdminSignIn = Body(...)):
raise HTTPException(status_code=403, detail="Incorrect email or password")


@router.post("/new", response_model=AdminData)
@router.post("", response_model=AdminData)
async def admin_signup(admin: Admin = Body(...)):
admin_exists = await Admin.find_one(Admin.email == admin.email)
if admin_exists:
Expand Down
22 changes: 22 additions & 0 deletions schemas/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from pydantic import BaseModel
from fastapi.security import HTTPBasicCredentials
from pydantic import EmailStr

class AdminSignIn(HTTPBasicCredentials):
class Config:
schema_extra = {
"example": {"username": "[email protected]", "password": "3xt3m#"}
}


class AdminData(BaseModel):
fullname: str
email: EmailStr

class Config:
schema_extra = {
"example": {
"fullname": "Abdulazeez Abdulazeez Adeshina",
"email": "[email protected]",
}
}

0 comments on commit 87ea9c4

Please sign in to comment.