From 2e37fe32414afb501c71942af2427caa9c56494a Mon Sep 17 00:00:00 2001 From: Maxim Date: Thu, 19 Dec 2024 00:50:31 +0300 Subject: [PATCH] fix reviews --- backend/src/core/entities/review/review.py | 5 ++--- .../src/core/services/review_service/review_service.py | 8 +++++--- backend/src/infrastructure/api/review_controller.py | 4 ++-- .../review_repos/mongo_review_repository.py | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/backend/src/core/entities/review/review.py b/backend/src/core/entities/review/review.py index ba5681e..205b3be 100644 --- a/backend/src/core/entities/review/review.py +++ b/backend/src/core/entities/review/review.py @@ -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( diff --git a/backend/src/core/services/review_service/review_service.py b/backend/src/core/services/review_service/review_service.py index edf6130..a36c4a2 100644 --- a/backend/src/core/services/review_service/review_service.py +++ b/backend/src/core/services/review_service/review_service.py @@ -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 @@ -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) @@ -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, diff --git a/backend/src/infrastructure/api/review_controller.py b/backend/src/infrastructure/api/review_controller.py index 84d3701..8ad0993 100644 --- a/backend/src/infrastructure/api/review_controller.py +++ b/backend/src/infrastructure/api/review_controller.py @@ -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 @@ -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, diff --git a/backend/src/infrastructure/repo_implementations/review_repos/mongo_review_repository.py b/backend/src/infrastructure/repo_implementations/review_repos/mongo_review_repository.py index 02e5adb..69bee01 100644 --- a/backend/src/infrastructure/repo_implementations/review_repos/mongo_review_repository.py +++ b/backend/src/infrastructure/repo_implementations/review_repos/mongo_review_repository.py @@ -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