diff --git a/src/main/ai/data/CategoryRecommendationQueue.py b/src/main/ai/data/CategoryRecommendationQueue.py index 5db9dcd..205cd32 100644 --- a/src/main/ai/data/CategoryRecommendationQueue.py +++ b/src/main/ai/data/CategoryRecommendationQueue.py @@ -11,14 +11,14 @@ def __init__(self, sqs_client: boto3.client, queue_url: str): self.sqs = sqs_client self.queue_url = queue_url - def send_message(self, request_id: str, title: str, user_id: str): + def send_message(self, request_id: str, file_id: str, user_id: str): try: message_body = { 'request_type': 'category_recommendation', 'request_id': request_id, 'user_id': str(user_id), 'payload': { - 'title': title + 'file_id': file_id } } diff --git a/src/main/ai/data/CategoryRecommendationRepository.py b/src/main/ai/data/CategoryRecommendationRepository.py index 1813f95..88709e1 100644 --- a/src/main/ai/data/CategoryRecommendationRepository.py +++ b/src/main/ai/data/CategoryRecommendationRepository.py @@ -10,9 +10,9 @@ def __init__(self, client: MongoClient): self.db = client.get_database() self.collection: Collection = self.db.get_collection('category_recommendations') - def create_recommendation_request(self, title: str, user_id: str) -> dict: + def create_recommendation_request(self, file_id: str, user_id: str) -> dict: document = { - "title": title, + "file_id": file_id, "user_id": user_id, "is_completed": False, "created_at": self.get_current_time() diff --git a/src/main/ai/models/CategoryRecommendation.py b/src/main/ai/models/CategoryRecommendation.py index e20e032..a71e42e 100644 --- a/src/main/ai/models/CategoryRecommendation.py +++ b/src/main/ai/models/CategoryRecommendation.py @@ -4,7 +4,7 @@ class CategoryRecommendationRequest(BaseModel): - title: str + file_id: str class CategoryRecommendationResponse(BaseModel): diff --git a/src/main/ai/router/AIPublicAPIRouter.py b/src/main/ai/router/AIPublicAPIRouter.py index e507e74..c23218c 100644 --- a/src/main/ai/router/AIPublicAPIRouter.py +++ b/src/main/ai/router/AIPublicAPIRouter.py @@ -22,7 +22,7 @@ async def create_category_recommendation_request( service: CategoryRecommendationService = Depends(get_category_recommendation_service) ): """ - 자료 제목에 따른 추천 카테고리 요청 + 업로드한 파일에 따른 추천 카테고리 요청 """ return service.create_recommendation_request(request, user_id) @@ -34,7 +34,7 @@ async def get_category_recommendation_status( service: CategoryRecommendationService = Depends(get_category_recommendation_service) ): """ - 자료 제목에 따른 추천 카테고리 조회 + 업로드한 파일에 따른 추천 카테고리 조회 """ result = service.get_recommendation_status(request_id, user_id) diff --git a/src/main/ai/service/CategoryRecommendationService.py b/src/main/ai/service/CategoryRecommendationService.py index 9638859..d90d0c3 100644 --- a/src/main/ai/service/CategoryRecommendationService.py +++ b/src/main/ai/service/CategoryRecommendationService.py @@ -20,7 +20,7 @@ def __init__(self, repository: CategoryRecommendationRepository, queue: Category def create_recommendation_request(self, request: CategoryRecommendationRequest, user_id: uuid.UUID) -> CategoryRecommendationResponse: # MongoDB에 저장 - ObjectId 자동 생성 document = self.repository.create_recommendation_request( - title=request.title, + file_id=request.file_id, user_id=str(user_id) ) @@ -30,7 +30,7 @@ def create_recommendation_request(self, request: CategoryRecommendationRequest, # 메시지 발행 self.queue.send_message( request_id=request_id, - title=request.title, + file_id=request.file_id, user_id=str(user_id) ) diff --git a/src/tests/ai/data/test_category_recommendation_queue.py b/src/tests/ai/data/test_category_recommendation_queue.py index a6dafef..97afe21 100644 --- a/src/tests/ai/data/test_category_recommendation_queue.py +++ b/src/tests/ai/data/test_category_recommendation_queue.py @@ -16,7 +16,7 @@ def setup_method(self): def test_send_message_success(self): # given request_id = "test-request-id" - title = "테스트 제목" + file_id = "67dd86ac60a0a6d929904d47" user_id = "test-user-id" # SQS 응답 설정 @@ -24,7 +24,7 @@ def test_send_message_success(self): self.mock_sqs_client.send_message.return_value = expected_response # when - result = self.queue.send_message(request_id, title, user_id) + result = self.queue.send_message(request_id, file_id, user_id) # then expected_message_body = { @@ -32,7 +32,7 @@ def test_send_message_success(self): 'request_id': request_id, 'user_id': user_id, 'payload': { - 'title': title + 'file_id': file_id } } @@ -47,7 +47,7 @@ def test_send_message_success(self): def test_send_message_with_exception(self): # given request_id = "test-request-id" - title = "테스트 제목" + file_id = "67dd86ac60a0a6d929904d47" user_id = "test-user-id" # SQS 예외 발생 설정 @@ -55,7 +55,7 @@ def test_send_message_with_exception(self): # when/then with pytest.raises(Exception) as e: - self.queue.send_message(request_id, title, user_id) + self.queue.send_message(request_id, file_id, user_id) assert "SQS error" in str(e.value) @@ -64,7 +64,7 @@ def test_send_message_with_exception(self): 'request_id': request_id, 'user_id': user_id, 'payload': { - 'title': title + 'file_id': file_id } } diff --git a/src/tests/ai/data/test_category_recommendation_repository.py b/src/tests/ai/data/test_category_recommendation_repository.py index 651b0a3..ffce54d 100644 --- a/src/tests/ai/data/test_category_recommendation_repository.py +++ b/src/tests/ai/data/test_category_recommendation_repository.py @@ -32,7 +32,7 @@ def teardown_method(self): def test_create_recommendation_request(self): # given - title = "테스트 제목" + file_id = "67dd86ac60a0a6d929904d47" user_id = "test-user-id" mock_id = ObjectId("6123456789abcdef01234567") @@ -40,11 +40,11 @@ def test_create_recommendation_request(self): self.mock_collection.insert_one.return_value = MagicMock(inserted_id=mock_id) # when - result = self.repository.create_recommendation_request(title, user_id) + result = self.repository.create_recommendation_request(file_id, user_id) # then expected_doc = { - "title": title, + "file_id": file_id, "user_id": user_id, "is_completed": False, "created_at": datetime(2023, 1, 1, tzinfo=timezone.utc), @@ -61,7 +61,7 @@ def test_get_recommendation_by_id(self): user_id = "test-user-id" expected_result = { "_id": ObjectId(request_id), - "title": "테스트 제목", + "file_id": "67dd86ac60a0a6d929904d47", "user_id": user_id, "is_completed": False, "created_at": datetime(2023, 1, 1, tzinfo=timezone.utc) @@ -102,7 +102,7 @@ def test_update_recommendation_result(self): expected_doc = { "_id": ObjectId(request_id), - "title": "테스트 제목", + "file_id": "67dd86ac60a0a6d929904d47", "user_id": "test-user-id", "is_completed": True, "predicted_category": predicted_category, diff --git a/src/tests/ai/models/test_category_recommendation_models.py b/src/tests/ai/models/test_category_recommendation_models.py index 43ec33e..b22f15d 100644 --- a/src/tests/ai/models/test_category_recommendation_models.py +++ b/src/tests/ai/models/test_category_recommendation_models.py @@ -13,16 +13,16 @@ class TestCategoryRecommendationModels: def test_category_recommendation_request_valid(self): # given - title = "테스트 제목" + file_id = "67dd86ac60a0a6d929904d47" # when - model = CategoryRecommendationRequest(title=title) + model = CategoryRecommendationRequest(file_id=file_id) # then - assert model.title == title + assert model.file_id == file_id def test_category_recommendation_request_invalid(self): - # when/then - 제목이 없는 경우 검증 오류 + # when/then - 파일 ID가 없는 경우 검증 오류 with pytest.raises(ValidationError): CategoryRecommendationRequest() diff --git a/src/tests/ai/router/test_ai_public_api_router.py b/src/tests/ai/router/test_ai_public_api_router.py index caff74c..9d8fdd9 100644 --- a/src/tests/ai/router/test_ai_public_api_router.py +++ b/src/tests/ai/router/test_ai_public_api_router.py @@ -34,15 +34,15 @@ def client(): class TestAIPublicAPIRouter: def setup_method(self): # 테스트 공통 데이터 - self.test_title = "테스트 제목" + self.test_file_id = "67dd86ac60a0a6d929904d47" self.test_user_id = uuid.UUID("12345678-1234-5678-1234-567812345678") self.test_request_id = "6123456789abcdef01234567" - self.test_file_id = "7123456789abcdef01234567" + self.test_check_file_id = "7123456789abcdef01234567" def test_create_category_recommendation_request(self, client): # given request_data = { - "title": self.test_title + "file_id": self.test_file_id } # 서비스 응답 모의 설정 @@ -107,23 +107,23 @@ def test_get_file_duplicate_check_status_exists(self, client): # 서비스 응답 설정 mock_service.return_value = FileDuplicateCheckStatusResponse( request_id=self.test_request_id, - file_id=self.test_file_id, + file_id=self.test_check_file_id, is_completed=True, is_duplicated=False ) # when - response = client.get(f"/ai/file-duplicate-checks?file_id={self.test_file_id}") + response = client.get(f"/ai/file-duplicate-checks?file_id={self.test_check_file_id}") # then assert response.status_code == 200 assert response.json() == { "request_id": self.test_request_id, - "file_id": self.test_file_id, + "file_id": self.test_check_file_id, "is_completed": True, "is_duplicated": False } - mock_service.assert_called_once_with(self.test_file_id, str(self.test_user_id)) + mock_service.assert_called_once_with(self.test_check_file_id, str(self.test_user_id)) def test_get_file_duplicate_check_status_not_found(self, client): # given @@ -133,11 +133,11 @@ def test_get_file_duplicate_check_status_not_found(self, client): mock_service.return_value = None # when - response = client.get(f"/ai/file-duplicate-checks?file_id={self.test_file_id}") + response = client.get(f"/ai/file-duplicate-checks?file_id={self.test_check_file_id}") # then assert response.status_code == 404 assert response.json() == { "detail": "요청을 찾을 수 없습니다. 존재하지 않는 ID입니다." } - mock_service.assert_called_once_with(self.test_file_id, str(self.test_user_id)) \ No newline at end of file + mock_service.assert_called_once_with(self.test_check_file_id, str(self.test_user_id)) \ No newline at end of file diff --git a/src/tests/ai/service/test_category_recommendation_service.py b/src/tests/ai/service/test_category_recommendation_service.py index 47c75dd..9fa6c5f 100644 --- a/src/tests/ai/service/test_category_recommendation_service.py +++ b/src/tests/ai/service/test_category_recommendation_service.py @@ -23,19 +23,19 @@ def setup_method(self): self.service = CategoryRecommendationService(self.mock_repository, self.mock_queue) # 테스트 공통 데이터 - self.test_title = "테스트 제목" + self.test_file_id = "67dd86ac60a0a6d929904d47" self.test_user_id = uuid.UUID("12345678-1234-5678-1234-567812345678") self.test_request_id = "6123456789abcdef01234567" self.test_object_id = ObjectId(self.test_request_id) def test_create_recommendation_request(self): # given - request = CategoryRecommendationRequest(title=self.test_title) + request = CategoryRecommendationRequest(file_id=self.test_file_id) # 리포지토리 응답 설정 mongo_document = { "_id": self.test_object_id, - "title": self.test_title, + "file_id": self.test_file_id, "user_id": str(self.test_user_id), "is_completed": False, "created_at": datetime(2023, 1, 1, tzinfo=timezone.utc) @@ -47,13 +47,13 @@ def test_create_recommendation_request(self): # then self.mock_repository.create_recommendation_request.assert_called_once_with( - title=self.test_title, + file_id=self.test_file_id, user_id=str(self.test_user_id) ) self.mock_queue.send_message.assert_called_once_with( request_id=self.test_request_id, - title=self.test_title, + file_id=self.test_file_id, user_id=str(self.test_user_id) ) @@ -65,7 +65,7 @@ def test_get_recommendation_status_exists(self): # 리포지토리 응답 설정 - 완료되지 않은 추천 mongo_document = { "_id": self.test_object_id, - "title": self.test_title, + "file_id": self.test_file_id, "user_id": str(self.test_user_id), "is_completed": False, "created_at": datetime(2023, 1, 1, tzinfo=timezone.utc) @@ -90,7 +90,7 @@ def test_get_recommendation_status_completed(self): # 리포지토리 응답 설정 - 완료된 추천 mongo_document = { "_id": self.test_object_id, - "title": self.test_title, + "file_id": self.test_file_id, "user_id": str(self.test_user_id), "is_completed": True, "predicted_category": "기술", @@ -134,7 +134,7 @@ def test_update_recommendation_result_success(self): # 리포지토리 응답 설정 updated_document = { "_id": self.test_object_id, - "title": self.test_title, + "file_id": self.test_file_id, "user_id": str(self.test_user_id), "is_completed": True, "predicted_category": "기술",