Skip to content

Commit

Permalink
Fix member and course post API
Browse files Browse the repository at this point in the history
  • Loading branch information
ankith26 committed Jan 3, 2025
1 parent 55d707f commit ebb70ef
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
13 changes: 11 additions & 2 deletions backend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def convert_naive_to_aware(cls, values):

class Member(BaseModel):
"""
Base class for representing a Member, can be a Student or Prof
Base class for representing a Member, can be a Student or Prof.
This is how Prof instances are stored in the db.
"""

name: str = Field(..., min_length=1)
Expand All @@ -118,7 +119,7 @@ class Student(Member):

class Prof(Member):
"""
Class for storing a Prof
Class for the frontend representation of a Prof, holds extra metadata.
"""

reviews_metadata: ReviewsMetadata
Expand All @@ -128,12 +129,20 @@ class Course(BaseModel):
"""
Represents a Course.
The code-sem combination is the ID for every course.
This is how the course structure is stored in the db.
"""

code: CourseCode
sem: Sem
name: str = Field(..., min_length=1)
profs: list[EmailStr] # list of prof emails


class CourseFrontend(Course):
"""
The frontend representation of a Course instance, holds extra metadata.
"""

reviews_metadata: ReviewsMetadata


Expand Down
3 changes: 2 additions & 1 deletion backend/routes/courses.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from utils import get_auth_id, get_auth_id_admin, hash_decrypt, hash_encrypt
from models import (
Course,
CourseFrontend,
Review,
ReviewBackend,
ReviewFrontend,
Expand All @@ -28,7 +29,7 @@ async def course_list():
This does not return the reviews attribute, that must be queried individually.
"""
return [
Course(**course).model_dump()
CourseFrontend(**course).model_dump()
async for course in get_list_with_metadata(course_collection)
]

Expand Down
12 changes: 10 additions & 2 deletions backend/routes/members.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@
from routes.routes_helpers import get_list_with_metadata
from config import db
from utils import get_auth_id, get_auth_id_admin, hash_decrypt, hash_encrypt
from models import Prof, Review, ReviewBackend, ReviewFrontend, Student, VoteAndReviewID
from models import (
Member,
Prof,
Review,
ReviewBackend,
ReviewFrontend,
Student,
VoteAndReviewID,
)

# The get_auth_id Dependency validates authentication of the caller
router = APIRouter(dependencies=[Depends(get_auth_id)])
Expand Down Expand Up @@ -37,7 +45,7 @@ async def prof_exists(email: EmailStr):


@router.post("/", dependencies=[Depends(get_auth_id_admin)])
async def prof_post(profs: list[Prof]):
async def prof_post(profs: list[Member]):
"""
Helper method to update a list of Profs in the records. This is an admin
endpoint and can't be used by regular users.
Expand Down

0 comments on commit ebb70ef

Please sign in to comment.