Skip to content
Snippets Groups Projects
Commit 68b78896 authored by Adrian Block's avatar Adrian Block
Browse files

added 404 with example for specific course get

parent 29df8f05
No related branches found
No related tags found
No related merge requests found
Pipeline #
from typing import List
from fastapi import APIRouter, Depends, Query, Path
from fastapi import APIRouter, Depends, Query, Path, HTTPException
from app import schemas
from app.data.brokers import Broker
......@@ -19,11 +19,14 @@ def list_and_search_courses_by_name(semester: str = Query(..., example="Sommer 2
return broker.find_courses_by_name(semester, title)
@router.get("/{courseId}", response_model=schemas.Course)
@router.get("/{courseId}", response_model=schemas.Course, responses={404: {"model": schemas.DetailMessage}})
def retrieve_information_of_a_course(semester: str = Query(..., example="Sommer 2022"),
courseId: str = Path(..., example="L.079.05401"),
broker: Broker = Depends(get_database_broker)):
"""
Querries course by id with all small groups and appointments.
"""
return broker.find_course_by_id(semester, courseId)
course = broker.find_course_by_id(semester, courseId)
if not course:
raise HTTPException(status_code=404, detail="Course not found")
return course
from .course import Course, Appointment, SmallGroup, CourseList, CourseWithoutAppointments, Semester, SemesterList, \
SemesterWithoutCourses
from .message import DetailMessage
from pydantic import BaseModel
class DetailMessage(BaseModel):
detail: str
class Config:
schema_extra = {
"example": {
"detail": "something with XY"
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment