-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #52 created missing repositories
- update also endpoints - change api welcome message
- Loading branch information
Showing
17 changed files
with
484 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# app/api/endpoints/activity.py | ||
|
||
from fastapi import ( | ||
APIRouter, | ||
Depends, | ||
HTTPException, | ||
) | ||
from sqlalchemy.orm import Session | ||
from app.database.session import get_db | ||
from app.schemas.activity import ( | ||
ActivityCreate, | ||
ActivityUpdate, | ||
ActivityInDBBase, | ||
) | ||
from app.repositories.activity_repository import ( | ||
create_activity, | ||
get_activity, | ||
get_activities, | ||
update_activity, | ||
delete_activity, | ||
) | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.post("/activities/", response_model=ActivityInDBBase) | ||
def create_activity_endpoint( | ||
activity: ActivityCreate, db: Session = Depends(get_db) | ||
) -> ActivityInDBBase: | ||
return create_activity(db, activity) | ||
|
||
|
||
@router.get("/activities/{activity_id}", response_model=ActivityInDBBase) | ||
def read_activity(activity_id: int, db: Session = Depends(get_db)) -> ActivityInDBBase: | ||
activity = get_activity(db, activity_id) | ||
if activity is None: | ||
raise HTTPException(status_code=404, detail="Activity not found") | ||
return activity | ||
|
||
|
||
@router.get("/activities/", response_model=list[ActivityInDBBase]) | ||
def read_activities( | ||
skip: int = 0, limit: int = 10, db: Session = Depends(get_db) | ||
) -> list[ActivityInDBBase]: | ||
return get_activities(db, skip, limit) | ||
|
||
|
||
@router.put("/activities/{activity_id}", response_model=ActivityInDBBase) | ||
def update_activity_endpoint( | ||
activity_id: int, activity: ActivityUpdate, db: Session = Depends(get_db) | ||
) -> ActivityInDBBase: | ||
db_activity = get_activity(db, activity_id) | ||
if db_activity is None: | ||
raise HTTPException(status_code=404, detail="Activity not found") | ||
return update_activity(db, activity_id, activity.model_dump()) | ||
|
||
|
||
@router.delete("/activities/{activity_id}", response_model=ActivityInDBBase) | ||
def delete_activity_endpoint( | ||
activity_id: int, db: Session = Depends(get_db) | ||
) -> ActivityInDBBase: | ||
activity = delete_activity(db, activity_id) | ||
if activity is None: | ||
raise HTTPException(status_code=404, detail="Activity not found") | ||
return activity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# app/api/endpoints/answer.py | ||
|
||
from fastapi import ( | ||
APIRouter, | ||
Depends, | ||
HTTPException, | ||
) | ||
from sqlalchemy.orm import Session | ||
from app.database.session import get_db | ||
from app.schemas.answer import ( | ||
AnswerCreate, | ||
AnswerUpdate, | ||
AnswerInDBBase, | ||
) | ||
from app.repositories.answer_repository import ( | ||
create_answer, | ||
get_answer, | ||
get_answers, | ||
update_answer, | ||
delete_answer, | ||
) | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.post("/answers/", response_model=AnswerInDBBase) | ||
def create_answer_endpoint( | ||
answer: AnswerCreate, db: Session = Depends(get_db) | ||
) -> AnswerInDBBase: | ||
return create_answer(db, answer) | ||
|
||
|
||
@router.get("/answers/{answer_id}", response_model=AnswerInDBBase) | ||
def read_answer(answer_id: int, db: Session = Depends(get_db)) -> AnswerInDBBase: | ||
answer = get_answer(db, answer_id) | ||
if answer is None: | ||
raise HTTPException(status_code=404, detail="Answer not found") | ||
return answer | ||
|
||
|
||
@router.get("/answers/", response_model=list[AnswerInDBBase]) | ||
def read_answers( | ||
skip: int = 0, limit: int = 10, db: Session = Depends(get_db) | ||
) -> list[AnswerInDBBase]: | ||
return get_answers(db, skip, limit) | ||
|
||
|
||
@router.put("/answers/{answer_id}", response_model=AnswerInDBBase) | ||
def update_answer_endpoint( | ||
answer_id: int, answer: AnswerUpdate, db: Session = Depends(get_db) | ||
) -> AnswerInDBBase: | ||
db_answer = get_answer(db, answer_id) | ||
if db_answer is None: | ||
raise HTTPException(status_code=404, detail="Answer not found") | ||
return update_answer(db, answer_id, answer.model_dump()) | ||
|
||
|
||
@router.delete("/answers/{answer_id}", response_model=AnswerInDBBase) | ||
def delete_answer_endpoint( | ||
answer_id: int, db: Session = Depends(get_db) | ||
) -> AnswerInDBBase: | ||
answer = delete_answer(db, answer_id) | ||
if answer is None: | ||
raise HTTPException(status_code=404, detail="Answer not found") | ||
return answer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# app/api/endpoints/question.py | ||
|
||
from fastapi import ( | ||
APIRouter, | ||
Depends, | ||
HTTPException, | ||
) | ||
from sqlalchemy.orm import Session | ||
from app.database.session import get_db | ||
from app.schemas.question import ( | ||
QuestionCreate, | ||
QuestionUpdate, | ||
QuestionInDBBase, | ||
) | ||
from app.repositories.question_repository import ( | ||
create_question, | ||
get_question, | ||
get_questions, | ||
update_question, | ||
delete_question, | ||
) | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.post("/questions/", response_model=QuestionInDBBase) | ||
def create_question_endpoint( | ||
question: QuestionCreate, db: Session = Depends(get_db) | ||
) -> QuestionInDBBase: | ||
return create_question(db, question) | ||
|
||
|
||
@router.get("/questions/{question_id}", response_model=QuestionInDBBase) | ||
def read_question(question_id: int, db: Session = Depends(get_db)) -> QuestionInDBBase: | ||
question = get_question(db, question_id) | ||
if question is None: | ||
raise HTTPException(status_code=404, detail="Question not found") | ||
return question | ||
|
||
|
||
@router.get("/questions/", response_model=list[QuestionInDBBase]) | ||
def read_questions( | ||
skip: int = 0, limit: int = 10, db: Session = Depends(get_db) | ||
) -> list[QuestionInDBBase]: | ||
return get_questions(db, skip, limit) | ||
|
||
|
||
@router.put("/questions/{question_id}", response_model=QuestionInDBBase) | ||
def update_question_endpoint( | ||
question_id: int, question: QuestionUpdate, db: Session = Depends(get_db) | ||
) -> QuestionInDBBase: | ||
db_question = get_question(db, question_id) | ||
if db_question is None: | ||
raise HTTPException(status_code=404, detail="Question not found") | ||
return update_question(db, question_id, question.model_dump()) | ||
|
||
|
||
@router.delete("/questions/{question_id}", response_model=QuestionInDBBase) | ||
def delete_question_endpoint( | ||
question_id: int, db: Session = Depends(get_db) | ||
) -> QuestionInDBBase: | ||
question = delete_question(db, question_id) | ||
if question is None: | ||
raise HTTPException(status_code=404, detail="Question not found") | ||
return question |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# app/api/endpoints/study_session.py | ||
|
||
from fastapi import ( | ||
APIRouter, | ||
Depends, | ||
HTTPException, | ||
) | ||
from sqlalchemy.orm import Session | ||
from app.database.session import get_db | ||
from app.schemas.study_session import ( | ||
StudySessionCreate, | ||
StudySessionUpdate, | ||
StudySessionInDBBase, | ||
) | ||
from app.repositories.study_session_repository import ( | ||
create_study_session, | ||
get_study_session, | ||
get_study_sessions, | ||
update_study_session, | ||
delete_study_session, | ||
) | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.post("/study_sessions/", response_model=StudySessionInDBBase) | ||
def create_study_session_endpoint( | ||
study_session: StudySessionCreate, db: Session = Depends(get_db) | ||
) -> StudySessionInDBBase: | ||
return create_study_session(db, study_session) | ||
|
||
|
||
@router.get("/study_sessions/{study_session_id}", response_model=StudySessionInDBBase) | ||
def read_study_session( | ||
study_session_id: int, db: Session = Depends(get_db) | ||
) -> StudySessionInDBBase: | ||
study_session = get_study_session(db, study_session_id) | ||
if study_session is None: | ||
raise HTTPException(status_code=404, detail="StudySession not found") | ||
return study_session | ||
|
||
|
||
@router.get("/study_sessions/", response_model=list[StudySessionInDBBase]) | ||
def read_study_sessions( | ||
skip: int = 0, limit: int = 10, db: Session = Depends(get_db) | ||
) -> list[StudySessionInDBBase]: | ||
return get_study_sessions(db, skip, limit) | ||
|
||
|
||
@router.put("/study_sessions/{study_session_id}", response_model=StudySessionInDBBase) | ||
def update_study_session_endpoint( | ||
study_session_id: int, | ||
study_session: StudySessionUpdate, | ||
db: Session = Depends(get_db), | ||
) -> StudySessionInDBBase: | ||
db_study_session = get_study_session(db, study_session_id) | ||
if db_study_session is None: | ||
raise HTTPException(status_code=404, detail="StudySession not found") | ||
return update_study_session(db, study_session_id, study_session.model_dump()) | ||
|
||
|
||
@router.delete( | ||
"/study_sessions/{study_session_id}", response_model=StudySessionInDBBase | ||
) | ||
def delete_study_session_endpoint( | ||
study_session_id: int, db: Session = Depends(get_db) | ||
) -> StudySessionInDBBase: | ||
study_session = delete_study_session(db, study_session_id) | ||
if study_session is None: | ||
raise HTTPException(status_code=404, detail="StudySession not found") | ||
return study_session |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.