Skip to content

Commit

Permalink
Merge pull request #87 from profcomff/Add-hard-coded-achievement
Browse files Browse the repository at this point in the history
  • Loading branch information
Temmmmmo authored Feb 8, 2025
2 parents 42ed81e + 6d81f2d commit ee579f0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions rating_api/routes/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)


Expand Down
4 changes: 3 additions & 1 deletion rating_api/routes/lecturer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions rating_api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
alembic
auth-lib-profcomff[fastapi]
aiohttp
fastapi
fastapi-sqlalchemy
gunicorn
Expand Down

0 comments on commit ee579f0

Please sign in to comment.