From d72126ec6abec3e3d68c08a9ad291abba712158f Mon Sep 17 00:00:00 2001 From: VladislavV Date: Thu, 4 Sep 2025 13:55:43 +0300 Subject: [PATCH 1/2] fix-response-model --- rating_api/routes/lecturer.py | 10 +++++++--- rating_api/schemas/models.py | 7 +++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/rating_api/routes/lecturer.py b/rating_api/routes/lecturer.py index c650020..8603910 100644 --- a/rating_api/routes/lecturer.py +++ b/rating_api/routes/lecturer.py @@ -19,6 +19,7 @@ LecturerPost, LecturersFilter, LecturerWithRank, + LecturerUpdateRatingPatch, ) from rating_api.utils.mark import calc_weighted_mark @@ -46,12 +47,14 @@ async def create_lecturer( raise AlreadyExists(Lecturer, lecturer_info.timetable_id) -@lecturer.patch("/import_rating", response_model=dict) +@lecturer.patch("/import_rating", response_model=LecturerUpdateRatingPatch) async def update_lecturer_rating( lecturer_rank_info: list[LecturerWithRank], _=Depends(UnionAuth(scopes=["rating.lecturer.update_rating"], allow_none=False, auto_error=True)), -) -> dict: +) -> LecturerUpdateRatingPatch: """ + Scopes: `["rating.lecturer.impor_rating"]` + Обновляет рейтинг преподавателя в базе данных RatingAPI """ updated_lecturers = [] @@ -84,8 +87,9 @@ async def update_lecturer_rating( else: response["failed"] += 1 response["failed_id"].append(lecturer_id) + response_validated = LecturerUpdateRatingPatch.model_validate(**response) - return response + return response_validated @lecturer.get("/{id}", response_model=LecturerGet) diff --git a/rating_api/schemas/models.py b/rating_api/schemas/models.py index caf1586..dfced18 100644 --- a/rating_api/schemas/models.py +++ b/rating_api/schemas/models.py @@ -194,3 +194,10 @@ def sort(self, query: Query) -> Query: class Constants(Filter.Constants): model = Lecturer + + +class LecturerUpdateRatingPatch(Base): + updated: int + failed: int + updated_id: list[int] + failed_id: list[int] From 68afe3919315e3bed71b0fb5e24514d762466e6a Mon Sep 17 00:00:00 2001 From: VladislavV Date: Thu, 4 Sep 2025 13:57:02 +0300 Subject: [PATCH 2/2] lint-fix --- rating_api/routes/lecturer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rating_api/routes/lecturer.py b/rating_api/routes/lecturer.py index 8603910..d420400 100644 --- a/rating_api/routes/lecturer.py +++ b/rating_api/routes/lecturer.py @@ -18,8 +18,8 @@ LecturerPatch, LecturerPost, LecturersFilter, - LecturerWithRank, LecturerUpdateRatingPatch, + LecturerWithRank, ) from rating_api.utils.mark import calc_weighted_mark