Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Student API #12

Merged
merged 11 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from router import auth,session, group
from router import auth,session, group, student
from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from fastapi_jwt_auth.exceptions import AuthJWTException
Expand All @@ -14,4 +14,5 @@ def authjwt_exception_handler(request: Request, exc: AuthJWTException):

app.include_router(auth.router)
app.include_router(session.router)
app.include_router(group.router)
app.include_router(group.router)
app.include_router(student.router)
31 changes: 31 additions & 0 deletions router/student.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from fastapi import APIRouter, HTTPException
import requests
from settings import settings

router = APIRouter(prefix="/student", tags=["Student"])
student_db_url = settings.db_url + "student/"

@router.post("/student-id-exists")
sudheshna-donthineni marked this conversation as resolved.
Show resolved Hide resolved
def student_id_exists(student_id: str):
"""
API to check if a student ID exists
"""
query_params = {'student_id':student_id}
response = requests.get(student_db_url, params=query_params)
if response.status_code == 200:
return response.json()
return HTTPException(status_code=response.status_code, detail=response.errors)

@router.post("/birthdate-matches")
sudheshna-donthineni marked this conversation as resolved.
Show resolved Hide resolved
def birthdate_matches(student_id:str, birth_date:str):
sudheshna-donthineni marked this conversation as resolved.
Show resolved Hide resolved
"""
API to check if the given birthdate matches to the student ID
sudheshna-donthineni marked this conversation as resolved.
Show resolved Hide resolved
"""
student_id_exists = student_id_exists(student_id)
if student_id_exists:
query_params = {'student_id':student_id, 'date_of_birth': birth_date}
response = requests.get(student_db_url, params=query_params)
if response.status_code == 200:
return response.json()
return HTTPException(status_code=response.status_code, detail=response.errors)
return HTTPException(status_code=404, detail="Student ID does not exist!")