diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index adbafe2..233ac3c 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -10,6 +10,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + - name: Init daemon.json + run: sudo touch /etc/docker/daemon.json - name: Set up docker uses: docker-practice/actions-setup-docker@master - name: Run postgres diff --git a/rating_api/routes/comment.py b/rating_api/routes/comment.py index 3afbc74..ee58be5 100644 --- a/rating_api/routes/comment.py +++ b/rating_api/routes/comment.py @@ -2,6 +2,7 @@ from typing import Literal from uuid import UUID +import aiohttp from auth_lib.fastapi import UnionAuth from fastapi import APIRouter, Depends, Query from fastapi_sqlalchemy import db @@ -94,6 +95,29 @@ async def create_comment(lecturer_id: int, comment_info: CommentPost, user=Depen user_id=user_id, review_status=ReviewStatus.PENDING, ) + + # Выдача аччивки юзеру за первый комментарий + async with aiohttp.ClientSession() as session: + give_achievement = True + async with session.get( + settings.API_URL + f"achievement/user/{user.get('id'):}", + headers={"Accept": "application/json"}, + ) as response: + if response.status == 200: + user_achievements = await response.json() + for achievement in user_achievements.get("achievement", []): + if achievement.get("id") == settings.FIRST_COMMENT_ACHIEVEMENT_ID: + give_achievement = False + break + else: + give_achievement = False + if give_achievement: + session.post( + settings.API_URL + + f"achievement/achievement/{settings.FIRST_COMMENT_ACHIEVEMENT_ID}/reciever/{user.get('id'):}", + headers={"Accept": "application/json", "Authorization": settings.ACHIEVEMENT_GIVE_TOKEN}, + ) + return CommentGet.model_validate(new_comment) diff --git a/rating_api/routes/lecturer.py b/rating_api/routes/lecturer.py index c81e165..e7c0e4d 100644 --- a/rating_api/routes/lecturer.py +++ b/rating_api/routes/lecturer.py @@ -135,7 +135,9 @@ async def get_lecturers( if comment.review_status is ReviewStatus.APPROVED ] if "comments" in info and approved_comments: - lecturer_to_result.comments = sorted(approved_comments, key=lambda comment: comment.create_ts, reverse=True) + lecturer_to_result.comments = sorted( + approved_comments, key=lambda comment: comment.create_ts, reverse=True + ) if "mark" in info and approved_comments: lecturer_to_result.mark_freebie = sum([comment.mark_freebie for comment in approved_comments]) / len( approved_comments diff --git a/rating_api/settings.py b/rating_api/settings.py index 1f7612c..89eade2 100644 --- a/rating_api/settings.py +++ b/rating_api/settings.py @@ -19,6 +19,12 @@ class Settings(BaseSettings): CORS_ALLOW_METHODS: list[str] = ['*'] CORS_ALLOW_HEADERS: list[str] = ['*'] + '''Temp settings''' + + API_URL: str = "https://api.test.profcomff.com/" + FIRST_COMMENT_ACHIEVEMENT_ID: int = 12 + ACHIEVEMENT_GIVE_TOKEN: str = "" + model_config = ConfigDict(case_sensitive=True, env_file=".env", extra="ignore") diff --git a/requirements.txt b/requirements.txt index 1b6d4e1..ed9f291 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ alembic auth-lib-profcomff[fastapi] +aiohttp fastapi fastapi-sqlalchemy gunicorn