리뷰 서비스 (Review)
개요
리뷰 서비스는 상품에 대한 사용자 리뷰와 평점을 관리합니다. 구매 확인된 리뷰를 표시하고, 상품별 평점 집계를 제공합니다.
| 항목 | 값 |
|---|---|
| 언어 | Python 3.11 |
| 프레임워크 | FastAPI |
| 데이터베이 스 | DocumentDB (MongoDB 호환) |
| 네임스페이스 | mall-services |
| 포트 | 8000 |
| 헬스체크 | GET /health |
아키텍처
API 엔드포인트
리뷰 API
| 메서드 | 경로 | 설명 |
|---|---|---|
GET | /api/v1/reviews/product/{product_id} | 상품별 리뷰 목록 |
GET | /api/v1/reviews/{review_id} | 리뷰 상세 조회 |
POST | /api/v1/reviews | 리뷰 등록 |
PUT | /api/v1/reviews/{review_id} | 리뷰 수정 |
DELETE | /api/v1/reviews/{review_id} | 리뷰 삭제 |
요청/응답 예시
상 품별 리뷰 목록
요청:
GET /api/v1/reviews/product/prod_001?page=1&page_size=10
응답:
{
"reviews": [
{
"id": "rev_001",
"user_id": "user_001",
"product_id": "prod_001",
"rating": 5,
"title": "정말 만족스러운 제품입니다",
"body": "배송도 빠르고 품질도 좋아요. 색상도 사진과 동일합니다. 강력 추천합니다!",
"helpful_count": 42,
"verified_purchase": true,
"created_at": "2024-01-15T10:00:00Z",
"updated_at": "2024-01-15T10:00:00Z"
},
{
"id": "rev_002",
"user_id": "user_002",
"product_id": "prod_001",
"rating": 4,
"title": "좋은 제품이지만 배송이 좀 늦었어요",
"body": "제품 자체는 만족하지만 배송이 예상보다 이틀 늦게 왔습니다.",
"helpful_count": 15,
"verified_purchase": true,
"created_at": "2024-01-14T15:30:00Z",
"updated_at": "2024-01-14T15:30:00Z"
}
],
"total": 128,
"page": 1,
"page_size": 10,
"has_more": true
}
리뷰 등록
요청:
POST /api/v1/reviews
Content-Type: application/json
{
"user_id": "user_003",
"product_id": "prod_001",
"rating": 5,
"title": "최고의 선택이었습니다",
"body": "가격 대비 품질이 정말 좋습니다. 디자인도 세련되고 실용적입니다. 다음에도 이 브랜드 제품을 구매할 예정입니다.",
"verified_purchase": true
}
응답 (201 Created):
{
"id": "rev_003",
"user_id": "user_003",
"product_id": "prod_001",
"rating": 5,
"title": "최고의 선택이었습니다",
"body": "가격 대비 품질이 정말 좋습니다. 디자인도 세련되고 실용적입니다. 다음에도 이 브랜드 제품을 구매할 예정입니다.",
"helpful_count": 0,
"verified_purchase": true,
"created_at": "2024-01-15T11:00:00Z",
"updated_at": "2024-01-15T11:00:00Z"
}
리뷰 수정
요청:
PUT /api/v1/reviews/rev_003
Content-Type: application/json
{
"rating": 4,
"title": "좋은 제품이지만 한 가지 아쉬운 점",
"body": "전반적으로 만족하지만, 한 달 사용 후 약간의 변색이 있었습니다. 그래도 가격 대비 괜찮습니다."
}
응답:
{
"id": "rev_003",
"user_id": "user_003",
"product_id": "prod_001",
"rating": 4,
"title": "좋은 제품이지만 한 가지 아쉬운 점",
"body": "전반적으로 만족하지만, 한 달 사용 후 약간의 변색이 있었습니다. 그래도 가격 대비 괜찮습니다.",
"helpful_count": 0,
"verified_purchase": true,
"created_at": "2024-01-15T11:00:00Z",
"updated_at": "2024-02-15T09:00:00Z"
}
데이터 모델
Review
class Review(BaseModel):
id: str = ""
user_id: str
product_id: str
rating: int = Field(..., ge=1, le=5) # 1-5점
title: str
body: str
helpful_count: int = 0 # "도움이 됐어요" 수
verified_purchase: bool = False # 구매 확인 여부
created_at: datetime
updated_at: datetime
ReviewCreate
class ReviewCreate(BaseModel):
user_id: str
product_id: str
rating: int = Field(..., ge=1, le=5)
title: str = Field(..., min_length=1, max_length=200)
body: str = Field(..., min_length=1, max_length=5000)
verified_purchase: bool = False