Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give achievement for first comment #87

Merged
merged 6 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading