Skip to content
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: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
- uses: isort/isort-action@master
with:
requirementsFiles: "requirements.txt requirements.dev.txt"
- uses: psf/black@stable
- uses: psf/black@23.11.0
- name: Comment if linting failed
if: ${{ failure() }}
uses: thollander/actions-comment-pull-request@v2
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/review_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,6 @@ def create_review_with_comments(file_comments, commit_id):

valid_review_comments = []
for comment in review_comments:

if "path" not in comment or "position" not in comment or comment["position"] is None:
print(
f"Пропускаем невалидный комментарий к файлу {comment.get('path', 'неизвестный')}: отсутствует позиция"
Expand Down
1 change: 0 additions & 1 deletion rating_api/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def update(cls, id: int | str, *, session: Session, **kwargs) -> BaseDbModel:
# Проверка на изменение полей
changed_fields = False
for field, new_value in kwargs.items():

old_value = getattr(obj, field)
if old_value != new_value and not field in technical_fields:
changed_fields = True
Expand Down
20 changes: 10 additions & 10 deletions rating_api/routes/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ async def get_comment(uuid: UUID, user=Depends(UnionAuth(auto_error=False, allow
raise ObjectNotFound(Comment, uuid)
base_data = CommentGet.model_validate(comment)
if user:
base_data.is_liked=comment.has_reaction(user.get("id"), Reaction.LIKE)
base_data.is_disliked=comment.has_reaction(user.get("id"), Reaction.DISLIKE)
base_data.is_liked = comment.has_reaction(user.get("id"), Reaction.LIKE)
base_data.is_disliked = comment.has_reaction(user.get("id"), Reaction.DISLIKE)
return base_data


Expand Down Expand Up @@ -267,8 +267,8 @@ async def get_comments(
base_data = comment_validator.model_validate(comment)
if current_user_id:
reaction = user_reactions.get(comment.uuid)
base_data.is_liked = (reaction == Reaction.LIKE)
base_data.is_disliked = (reaction == Reaction.DISLIKE)
base_data.is_liked = reaction == Reaction.LIKE
base_data.is_disliked = reaction == Reaction.DISLIKE
comments_with_like.append(base_data)

result.comments = comments_with_like
Expand Down Expand Up @@ -320,8 +320,8 @@ async def update_comment(uuid: UUID, comment_update: CommentUpdate, user=Depends
)

updated_comment = CommentGet.model_validate(updated_comment)
updated_comment.is_liked=comment.has_reaction(user.get("id"), Reaction.LIKE)
updated_comment.is_disliked=comment.has_reaction(user.get("id"), Reaction.DISLIKE)
updated_comment.is_liked = comment.has_reaction(user.get("id"), Reaction.LIKE)
updated_comment.is_disliked = comment.has_reaction(user.get("id"), Reaction.DISLIKE)
return updated_comment


Expand Down Expand Up @@ -387,9 +387,9 @@ async def like_comment(
)
.first()
)
comment = CommentGet.model_validate(comment)
comment.is_liked = (reaction == Reaction.LIKE)
comment.is_disliked = (reaction == Reaction.DISLIKE)

comment.is_liked = reaction == Reaction.LIKE
comment.is_disliked = reaction == Reaction.DISLIKE

if existing_reaction and existing_reaction.reaction != reaction:
new_reaction = CommentReaction.update(session=db.session, id=existing_reaction.uuid, reaction=reaction)
Expand All @@ -399,4 +399,4 @@ async def like_comment(
comment.is_disliked = False
comment.is_liked = False
CommentReaction.delete(session=db.session, id=existing_reaction.uuid)
return comment
return CommentGet.model_validate(comment)
1 change: 1 addition & 0 deletions rating_api/routes/lecturer.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ async def update_lecturer_rating(

return response_validated


@lecturer.get("/timetable-id/{timetable_id}", response_model=LecturerGet)
async def get_lecturer_by_timetable_id(timetable_id: int) -> LecturerGet:
"""
Expand Down
2 changes: 1 addition & 1 deletion requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
autoflake
black
black==23.11.0
httpx
isort
pytest
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def _create_reaction(user_id: int, react: Reaction):
dbsession.add(reaction)
dbsession.commit()
created_reactions.append(reaction)

yield _create_reaction

for reaction in created_reactions:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_routes/test_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ def test_create_comment(client, dbsession, lecturers, body, lecturer_n, response
(None, None, None), # anonymous
],
)
def test_get_comment_with_reaction(client, comment, reaction_data, expected_reaction, comment_user_id, comment_reaction):
def test_get_comment_with_reaction(
client, comment, reaction_data, expected_reaction, comment_user_id, comment_reaction
):
comment.user_id = comment_user_id

if reaction_data:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_routes/test_lecturer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def test_create_lecturer(client, dbsession, response_status):
lecturer = dbsession.query(Lecturer).filter(Lecturer.timetable_id == 0).one_or_none()
assert lecturer is None


@pytest.mark.parametrize(
'lecturer_n, response_status',
[
Expand Down Expand Up @@ -377,7 +378,6 @@ def test_lecturer_rating_update(client, dbsession, body, response_status):
response = client.patch('/lecturer/import_rating', json=[body])

if response_status == status.HTTP_200_OK:

response_dict = response.json()
assert isinstance(response_dict, dict)

Expand Down
Loading