-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgrade.py
More file actions
166 lines (148 loc) · 8.43 KB
/
grade.py
File metadata and controls
166 lines (148 loc) · 8.43 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
"""
CodeCraft PMS Backend Project
파일명 : grade.py
생성자 : 김창환
생성일 : 2024/11/24
업데이트 : 2025/03/08
설명 : 프로젝트를 평가와 관련 된 엔드포인트 정의
"""
from fastapi import APIRouter, HTTPException
from fastapi.responses import JSONResponse
from pydantic import BaseModel
from logger import logger
import sys, os
sys.path.append(os.path.abspath('/data/Database Project')) # Database Project와 연동하기 위해 사용
import grade_DB
router = APIRouter()
class GradePayload(BaseModel):
univ_id: int = None
pid: int = None
comment: str = None
class AssignPayload(BaseModel):
pid: int
plan: int
require: int
design: int
progress: int
scm: int
cooperation: int
quality: int
tech: int
presentation: int
completion: int
@router.post("/grade/comment_add")
async def api_grade_add_comment(payload: GradePayload):
"""특정 학생에게 코멘트를 추가 및 수정"""
try:
result = grade_DB.add_comment(payload.pid, payload.univ_id, payload.comment)
if isinstance(result, Exception):
raise Exception(f"Database error: {str(result)}")
logger.info(f"Comment successfully added/updated for student {payload.univ_id} in project {payload.pid}")
return {"RESULT_CODE": 200, "RESULT_MSG": "Add Successful.", "PAYLOAD": {"Result": result}}
except Exception as e:
logger.error(f"Error while adding/updating comment: {str(e)}", exc_info=True)
raise HTTPException(status_code=500, detail=f"Unexpected error in add comment operation: {str(e)}")
@router.post("/grade/comment_del")
async def api_grade_del_comment(payload: GradePayload):
"""특정 학생의 코멘트를 삭제"""
try:
result = grade_DB.delete_comment(payload.pid, payload.univ_id)
if isinstance(result, Exception):
raise Exception(f"Database error: {str(result)}")
logger.info(f"Comment successfully deleted for student {payload.univ_id} in project {payload.pid}")
return {"RESULT_CODE": 200, "RESULT_MSG": "Delete Successful.", "PAYLOAD": {"Result": result}}
except Exception as e:
logger.error(f"Error while deleting comment: {str(e)}", exc_info=True)
raise HTTPException(status_code=500, detail=f"Unexpected error in delete comment operation: {str(e)}")
@router.post("/grade/comment_load_student")
async def api_grade_load_comment_one(payload: GradePayload):
"""특정 학생의 모든 코멘트를 조회"""
try:
result = grade_DB.fetch_comment_by_student(payload.univ_id)
if isinstance(result, Exception):
raise Exception(f"Database error: {str(result)}")
logger.info(f"Successfully loaded {len(result)} comments 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 comments: {str(e)}", exc_info=True)
raise HTTPException(status_code=500, detail=f"Unexpected error in load comment operation: {str(e)}")
@router.post("/grade/comment_load_project_student")
async def api_grade_load_comment_one_project(payload: GradePayload):
"""특정 프로젝트에 속한 학생의 코멘트를 조회"""
try:
result = grade_DB.fetch_one_comment(payload.pid, payload.univ_id)
if isinstance(result, Exception):
raise Exception(f"Database error: {str(result)}")
logger.info(f"Successfully loaded comment for student {payload.univ_id} in project {payload.pid}")
return {"RESULT_CODE": 200, "RESULT_MSG": "Load Successful.", "PAYLOAD": {"Result": result}}
except Exception as e:
logger.error(f"Error while loading comment: {str(e)}", exc_info=True)
raise HTTPException(status_code=500, detail=f"Unexpected error in load comment operation: {str(e)}")
@router.post("/grade/comment_load_project")
async def api_grade_load_comment_project(payload: GradePayload):
"""특정 프로젝트의 모든 코멘트를 조회"""
try:
result = grade_DB.fetch_comment_by_project(payload.pid)
if isinstance(result, Exception):
raise Exception(f"Database error: {str(result)}")
logger.info(f"Successfully loaded {len(result)} comments for project {payload.pid}")
return {"RESULT_CODE": 200, "RESULT_MSG": "Load Successful.", "PAYLOAD": {"Result": result}}
except Exception as e:
logger.error(f"Error while loading comments for project {payload.pid}: {str(e)}", exc_info=True)
raise HTTPException(status_code=500, detail=f"Unexpected error in load comment operation: {str(e)}")
@router.post("/grade/assign")
async def api_grade_assign(payload: AssignPayload):
"""교수가 프로젝트의 평가를 등록"""
try:
result = grade_DB.assign_grade(
payload.pid, payload.plan, payload.require, payload.design,
payload.progress, payload.scm, payload.cooperation, payload.quality,
payload.tech, payload.presentation, payload.completion
)
if isinstance(result, Exception):
raise Exception(f"Database error: {str(result)}")
logger.info(f"Grades successfully assigned for project {payload.pid}")
return {"RESULT_CODE": 200, "RESULT_MSG": "Assign Successful.", "PAYLOAD": {"Result": result}}
except Exception as e:
logger.error(f"Error while assigning grades for project {payload.pid}: {str(e)}", exc_info=True)
raise HTTPException(status_code=500, detail=f"Unexpected error in assign grade operation: {str(e)}")
@router.post("/grade/edit")
async def api_grade_edit(payload: AssignPayload):
"""교수가 프로젝트의 평가를 수정"""
try:
result = grade_DB.edit_grade(
payload.pid, payload.plan, payload.require, payload.design,
payload.progress, payload.scm, payload.cooperation, payload.quality,
payload.tech, payload.presentation, payload.completion
)
if isinstance(result, Exception):
raise Exception(f"Database error: {str(result)}")
logger.info(f"Grades successfully updated for project {payload.pid}")
return {"RESULT_CODE": 200, "RESULT_MSG": "Edit Successful.", "PAYLOAD": {"Result": result}}
except Exception as e:
logger.error(f"Error while editing grades for project {payload.pid}: {str(e)}", exc_info=True)
raise HTTPException(status_code=500, detail=f"Unexpected error in edit grade operation: {str(e)}")
@router.post("/grade/delete")
async def api_grade_delete(payload: GradePayload):
"""교수가 프로젝트의 평가를 삭제"""
try:
result = grade_DB.delete_grade(payload.pid)
if isinstance(result, Exception) or result is False: # result가 False라면 해당 프로젝트에 평가가 존재하지 않다는 것을 의미
raise Exception(f"Database error: {str(result)} or no grade found to delete")
logger.info(f"Grades successfully deleted for project {payload.pid}")
return {"RESULT_CODE": 200, "RESULT_MSG": "Delete Successful.", "PAYLOAD": {"Result": result}}
except Exception as e:
logger.error(f"Error while deleting grades for project {payload.pid}: {str(e)}", exc_info=True)
raise HTTPException(status_code=500, detail=f"Unexpected error in delete grade operation: {str(e)}")
@router.post("/grade/load")
async def api_grade_load(payload: GradePayload):
"""특정 프로젝트의 평가를 조회"""
try:
result = grade_DB.fetch_grade(payload.pid)
if isinstance(result, Exception):
raise Exception(f"Database error: {str(result)}")
logger.info(f"Successfully loaded grades for project {payload.pid}")
return {"RESULT_CODE": 200, "RESULT_MSG": "Load Successful.", "PAYLOAD": {"Result": result}}
except Exception as e:
logger.error(f"Error while loading grades for project {payload.pid}: {str(e)}", exc_info=True)
raise HTTPException(status_code=500, detail=f"Unexpected error in load grade operation: {str(e)}")