-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsubject.py
More file actions
64 lines (54 loc) · 2.99 KB
/
subject.py
File metadata and controls
64 lines (54 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""
CodeCraft PMS Backend Project
파일명 : subject.py
생성자 : 김창환
생성일 : 2025/02/14
업데이트 : 2025/03/08
설명 : 교과목 관련 엔드포인트 정의
"""
from fastapi import APIRouter, HTTPException
from pydantic import BaseModel
from logger import logger
import sys, os
sys.path.append(os.path.abspath('/data/Database Project'))
import subject_DB
router = APIRouter()
class SubjectPayload(BaseModel):
dno: int = None
univ_id: int = None
@router.post("/subject/load_all")
async def api_subject_load_all():
"""등록된 모든 과목을 조회"""
try:
result = subject_DB.fetch_subject_list()
if isinstance(result, Exception):
raise Exception(f"Database error: {str(result)}")
logger.info(f"Successfully loaded {len(result)} subjects.")
return {"RESULT_CODE": 200, "RESULT_MSG": "Load Successful.", "PAYLOAD": {"Result": result}}
except Exception as e:
logger.error(f"Error while loading all subjects: {str(e)}", exc_info=True)
raise HTTPException(status_code=500, detail=f"Unexpected error in Load all subjects: {str(e)}")
@router.post("/subject/load_dept")
async def api_subject_load_by_dept(payload: SubjectPayload):
"""특정 학과의 모든 과목을 조회"""
try:
result = subject_DB.fetch_subject_list_of_dept(payload.dno)
if isinstance(result, Exception):
raise Exception(f"Database error: {str(result)}")
logger.info(f"Successfully loaded {len(result)} subjects for department {payload.dno}.")
return {"RESULT_CODE": 200, "RESULT_MSG": "Load Successful.", "PAYLOAD": {"Result": result}}
except Exception as e:
logger.error(f"Error while loading subjects for department {payload.dno}: {str(e)}", exc_info=True)
raise HTTPException(status_code=500, detail=f"Unexpected error in Load subjects for department: {str(e)}")
@router.post("/subject/load_student")
async def api_subject_load_by_student(payload: SubjectPayload):
"""특정 학생이 속한 학과의 모든 과목을 조회"""
try:
result = subject_DB.fetch_subject_list_of_student(payload.univ_id)
if isinstance(result, Exception):
raise Exception(f"Database error: {str(result)}")
logger.info(f"Successfully loaded {len(result)} subjects for student {payload.univ_id}.")
return {"RESULT_CODE": 200, "RESULT_MSG": "Load Successful.", "PAYLOAD": {"Result": result}}
except Exception as e:
logger.error(f"Error while loading subjects for student {payload.univ_id}: {str(e)}", exc_info=True)
raise HTTPException(status_code=500, detail=f"Unexpected error in Load subjects for student: {str(e)}")