Skip to content

Commit

Permalink
fix reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim2121512 committed Dec 18, 2024
1 parent a393b1d commit 2e37fe3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
5 changes: 2 additions & 3 deletions backend/src/core/entities/review/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,14 @@ class ReviewSummary(BaseModel):
min_length=4,
max_length=300
)

class ReviewPaginated(ReviewSummary):
tool_name: str = Field(
...,
description="Tool name"
)


class PaginatedReviewsResponse(BaseModel):
reviews: List[ReviewPaginated] = Field(
reviews: List[ReviewSummary] = Field(
...
)
totalNumber: int = Field(
Expand Down
8 changes: 5 additions & 3 deletions backend/src/core/services/review_service/review_service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from src.core.entities.review.review import ReviewCreate, ReviewCreated, ReviewSummary, Review, ReviewPaginated, PaginatedReviewsResponse
from src.core.entities.review.review import ReviewCreate, ReviewCreated, ReviewSummary, Review, PaginatedReviewsResponse
from typing import List, Optional
from src.core.exceptions.client_error import ResourceNotFoundError, ResourceAlreadyExistsError, PaymentStateError
from src.core.repositories.order_repos.iorder_repository import IOrderRepository
Expand Down Expand Up @@ -54,13 +54,15 @@ async def get_tool_reviews(self, tool_id: str) -> List[ReviewSummary]:

for review in reviews:
client_full_name = await self.client_repo.get_full_name(objectId_to_str(review.reviewerId))
tool_name = await self.tool_repo.get_name_by_id(objectId_to_str(review.toolId))

review_summary = ReviewSummary(
reviewer_name=client_full_name.name,
reviewer_surname=client_full_name.surname,
rating=review.rating,
date=review.date,
text=review.text
text=review.text,
tool_name=tool_name
)
review_summaries.append(review_summary)

Expand Down Expand Up @@ -110,7 +112,7 @@ async def get_paginated_reviews(
for review in reviews:
tool_name = await self.tool_repo.get_name_by_id(objectId_to_str(review.toolId))
full_name = await self.client_repo.get_full_name(objectId_to_str(review.reviewerId))
result.append(ReviewPaginated(
result.append(ReviewSummary(
reviewer_name=full_name.name,
reviewer_surname=full_name.surname,
rating=review.rating,
Expand Down
4 changes: 2 additions & 2 deletions backend/src/infrastructure/api/review_controller.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from fastapi import APIRouter, Depends, Query
from typing import List, Optional
from fastapi.security import OAuth2PasswordBearer
from src.core.entities.review.review import ReviewCreated, ReviewCreate, ReviewPaginated, PaginatedReviewsResponse
from src.core.entities.review.review import ReviewCreated, ReviewCreate, PaginatedReviewsResponse, ReviewSummary
from src.core.services.review_service.review_service import ReviewService
from src.infrastructure.api.security.role_required import is_self, is_worker
from src.infrastructure.services_instances import get_review_service
Expand Down Expand Up @@ -58,7 +58,7 @@ async def get_reviews_paginated(
@review_router.get(
path="/{tool_id}",
status_code=200,
response_model=List[ReviewPaginated]
response_model=List[ReviewSummary]
)
async def get_tool_reviews(
tool_id: str,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from unittest import skipIf

from src.core.entities.review.review import ReviewCreate, Review, ReviewPaginated
from src.core.entities.review.review import ReviewCreate, Review
from src.core.repositories.review_repos.ireview_repository import IReviewRepository
from motor.motor_asyncio import AsyncIOMotorDatabase
from src.core.exceptions.server_error import DatabaseError
Expand Down

0 comments on commit 2e37fe3

Please sign in to comment.