Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WEAV-34] ✨ 직장 검색 API #25

Merged
merged 2 commits into from
Oct 8, 2024
Merged

[WEAV-34] ✨ 직장 검색 API #25

merged 2 commits into from
Oct 8, 2024

Conversation

waterfogSW
Copy link
Member

@waterfogSW waterfogSW commented Oct 8, 2024

Summary by CodeRabbit

  • 새로운 기능

    • 회사 관련 API 요청을 관리하는 REST 컨트롤러 추가.
    • 회사 이름으로 검색하고 결과를 페이지네이션할 수 있는 기능 구현.
  • 버그 수정

    • 기존의 회사 조회 기능 유지.
  • 문서화

    • API 계약에 따른 회사 데이터 쿼리 및 형식화 로직 캡슐화.

@waterfogSW waterfogSW self-assigned this Oct 8, 2024
Copy link

coderabbitai bot commented Oct 8, 2024

Walkthrough

이 변경 사항은 CompaniesController.kt 파일에 회사 관련 API 요청을 관리하는 REST 컨트롤러를 추가하며, CompanyQueryRepositoryCompanyQueryPersistenceAdapter에 회사 검색 기능을 구현합니다. searchCompanies 메서드는 회사 이름, 선택적 UUID(페이지네이션 용) 및 최대 결과 수를 매개변수로 받아 회사 데이터를 검색하고, 결과를 SearchCompaniesResponse로 반환합니다. 이로 인해 회사 데이터 쿼리 및 포맷팅 로직이 API 계약에 맞춰 캡슐화됩니다.

Changes

파일 경로 변경 요약
bootstrap/api/src/main/kotlin/com/threedays/bootstrap/api/user/CompaniesController.kt CompaniesController 클래스 추가 및 searchCompanies 메서드 구현.
domain/src/main/kotlin/com/threedays/domain/user/repository/CompanyQueryRepository.kt searchCompanies 메서드 추가, 회사 이름 및 페이지네이션 지원.
infrastructure/persistence/src/main/kotlin/com/threedays/persistence/user/adapter/CompanyQueryPersistenceAdapter.kt searchCompanies 메서드 구현, 생성자에 EntityManagerRenderContext 추가.
infrastructure/persistence/src/main/kotlin/com/threedays/persistence/user/repository/CompanyJpaRepository.kt CompanyJpaRepository 인터페이스가 KotlinJdslJpqlExecutor를 확장하도록 수정.

Possibly related PRs

  • ✨ 회사, 직장 도메인 추가 #17: CompaniesController.ktCompanyQueryRepository.kt의 변경 사항은 회사 및 직장 관련 새로운 도메인 추가와 관련이 있습니다.
  • ♻️ JPA 전환 #18: CompanyQueryRepository.kt의 수정 및 CompanyQueryPersistenceAdaptersearchCompanies 메서드 도입은 본 PR에서 구현된 새로운 검색 기능과 직접적으로 관련이 있습니다.

Suggested labels

기능구현

Suggested reviewers

  • dojinyou

🐇 새로운 기능이 생겼네,
회사 찾기 더 쉬워졌지!
API가 뚝딱, 데이터가 쏙,
페이지네이션도 척척,
모두 함께 기뻐하자,
귀여운 토끼가 노래해! 🎶


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@waterfogSW waterfogSW changed the title ✨ 직장 검색 API [WEAV-34] ✨ 직장 검색 API Oct 8, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (2)
domain/src/main/kotlin/com/threedays/domain/user/repository/CompanyQueryRepository.kt (1)

8-12: LGTM! 메서드 서명이 명확하고 적절합니다.

메서드 서명이 잘 설계되었으며, 페이지네이션을 위한 커서 기반 접근 방식을 적절히 구현하고 있습니다. 반환 타입인 Pair<List<Company>, Company.Id?>는 검색 결과와 다음 커서를 함께 반환하기에 적합합니다.

메서드에 KDoc 주석을 추가하여 문서화를 개선하는 것이 좋겠습니다. 다음과 같이 추가할 수 있습니다:

/**
 * 회사 이름으로 회사를 검색합니다.
 *
 * @param name 검색할 회사 이름
 * @param next 페이지네이션을 위한 다음 회사 ID (선택적)
 * @param limit 반환할 최대 결과 수
 * @return 검색된 회사 목록과 다음 페이지 커서 (있는 경우)의 쌍
 */
fun searchCompanies(
    name: String,
    next: Company.Id?,
    limit: Int
): Pair<List<Company>, Company.Id?>
bootstrap/api/src/main/kotlin/com/threedays/bootstrap/api/user/CompaniesController.kt (1)

22-41: searchCompanies 메서드 구현이 잘 되었습니다. 오류 처리를 고려해보세요.

메서드 구현이 전반적으로 잘 되어 있습니다. 주입된 리포지토리를 올바르게 사용하고 있으며, 도메인 엔티티를 API 응답 객체로 매핑하는 과정도 적절합니다. 선택적 next 매개변수 처리도 잘 되어 있습니다.

다만, 오류 처리에 대한 부분이 보이지 않습니다. 예를 들어, 리포지토리 호출 시 발생할 수 있는 예외나 잘못된 입력값에 대한 처리를 추가하는 것이 좋겠습니다.

오류 처리 로직을 추가하는 것에 대해 어떻게 생각하시나요? 필요하다면 예외 처리 코드 예시를 제공해 드릴 수 있습니다.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e95cf44 and 3417472.

📒 Files selected for processing (4)
  • bootstrap/api/src/main/kotlin/com/threedays/bootstrap/api/user/CompaniesController.kt (1 hunks)
  • domain/src/main/kotlin/com/threedays/domain/user/repository/CompanyQueryRepository.kt (1 hunks)
  • infrastructure/persistence/src/main/kotlin/com/threedays/persistence/user/adapter/CompanyQueryPersistenceAdapter.kt (1 hunks)
  • infrastructure/persistence/src/main/kotlin/com/threedays/persistence/user/repository/CompanyJpaRepository.kt (1 hunks)
🧰 Additional context used
🔇 Additional comments (5)
infrastructure/persistence/src/main/kotlin/com/threedays/persistence/user/repository/CompanyJpaRepository.kt (1)

3-3: Kotlin JDSL 지원 추가에 대한 승인

KotlinJdslJpqlExecutor를 확장함으로써 CompanyJpaRepository의 기능이 향상되었습니다. 이 변경은 다음과 같은 이점을 제공합니다:

  1. 더 유연하고 타입 안전한 쿼리 구성 가능
  2. 복잡한 쿼리를 직접 리포지토리에서 작성할 수 있는 능력
  3. 기존 JPA 작업과의 호환성 유지

이 변경은 코드베이스의 쿼리 기능을 향상시키는 긍정적인 개선입니다.

Also applies to: 10-10

bootstrap/api/src/main/kotlin/com/threedays/bootstrap/api/user/CompaniesController.kt (3)

1-10: 패키지 선언과 임포트가 적절합니다.

패키지 선언이 정확하고 필요한 모든 클래스와 인터페이스가 올바르게 임포트되었습니다. 사용되지 않는 임포트도 없어 깔끔합니다.


12-15: 클래스 선언과 생성자가 잘 구현되었습니다.

@RestController 어노테이션의 사용이 적절하며, CompaniesApi 인터페이스를 구현하여 API 계약을 준수하고 있습니다. 생성자를 통한 의존성 주입도 좋은 방식입니다.


17-21: searchCompanies 메서드 시그니처가 적절합니다.

메서드 시그니처가 API 계약을 잘 준수하고 있습니다. ResponseEntity를 사용하여 HTTP 응답을 더 세밀하게 제어할 수 있게 한 점이 좋습니다.

infrastructure/persistence/src/main/kotlin/com/threedays/persistence/user/adapter/CompanyQueryPersistenceAdapter.kt (1)

37-38: next 조건의 Null 처리 확인 필요

next?.let { ... } 구문을 사용하여 next가 null이 아닐 때만 조건을 추가하고 있습니다. 하지만 whereAnd에 null이 전달될 경우 예상치 못한 동작이 발생할 수 있으니, Null 처리가 올바르게 이루어지고 있는지 확인이 필요합니다.

다음 스크립트를 실행하여 Null 조건이 JPQL DSL에서 올바르게 처리되는지 확인하세요:

✅ Verification successful

next의 Null 처리 확인 완료

무한 문제가 발견되지 않았으며, next?.let { ... } 구문을 사용한 null 처리가 올바르게 수행되고 있습니다.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 설명: JPQL DSL에서 null 조건 처리가 올바른지 확인
# 테스트: null 조건을 포함한 쿼리 생성 시 예외가 발생하지 않아야 합니다.

# 예시 코드로 테스트 쿼리 작성
cat <<EOT > Test.kt
import com.linecorp.kotlinjdsl.dsl.jpql.jpql
import com.linecorp.kotlinjdsl.querymodel.jpql.select.SelectQuery

val next: Long? = null
val query: SelectQuery<CompanyJpaEntity> = jpql {
    select(entity(CompanyJpaEntity::class))
        .from(entity(CompanyJpaEntity::class))
        .whereAnd(
            path(CompanyJpaEntity::name).like("%test%"),
            next?.let { path(CompanyJpaEntity::id).gt(it) }
        )
}
EOT

# 컴파일 테스트
kotlinc Test.kt -cp kotlin-jdsl.jar

Length of output: 119


Script:

#!/bin/bash
# 설명: whereAnd 함수가 null을 올바르게 처리하는지 확인하기 위해 코드를 검색합니다.
# 테스트: whereAnd 함수에 null이 전달되는 호출을 찾고, 이러한 호출이 올바르게 처리되고 있는지 확인합니다.

# whereAnd 함수 호출 중 null을 인자로 사용하는 경우를 검색
rg 'whereAnd\s*\(\s*null' .

Length of output: 29

Copy link

sonarcloud bot commented Oct 8, 2024

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
infrastructure/persistence/src/main/kotlin/com/threedays/persistence/user/adapter/CompanyQueryPersistenceAdapter.kt (1)

23-48: LGTM: searchCompanies 메서드가 잘 구현되었습니다.

메서드가 페이지네이션을 포함한 검색 기능을 올바르게 구현하고 있습니다. Kotlin JDSL을 사용하여 타입 안전한 쿼리 구성을 제공하는 것이 좋습니다.

개선 제안:

  1. 이전 리뷰 코멘트에서 언급된 대로, Pair 대신 데이터 클래스를 사용하여 반환 값을 더 명확하게 표현할 수 있습니다. 이는 가독성을 향상시키고 유지보수를 용이하게 할 것입니다.

다음과 같은 데이터 클래스를 사용하는 것을 고려해보세요:

data class SearchCompaniesResult(
    val companies: List<Company>,
    val nextId: Company.Id?
)

그리고 메서드 시그니처와 반환문을 다음과 같이 변경할 수 있습니다:

override fun searchCompanies(
    name: String,
    next: Company.Id?,
    limit: Int
): SearchCompaniesResult {
    // ... existing implementation ...
    return SearchCompaniesResult(result.take(limit), nextId)
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 3417472 and 69f06e1.

📒 Files selected for processing (1)
  • infrastructure/persistence/src/main/kotlin/com/threedays/persistence/user/adapter/CompanyQueryPersistenceAdapter.kt (1 hunks)
🧰 Additional context used
🔇 Additional comments (2)
infrastructure/persistence/src/main/kotlin/com/threedays/persistence/user/adapter/CompanyQueryPersistenceAdapter.kt (2)

3-6: LGTM: 새로운 import 문이 적절히 추가되었습니다.

Kotlin JDSL 관련 import 문들이 searchCompanies 메서드 구현에 필요한 기능을 제공하기 위해 적절히 추가되었습니다.

Also applies to: 11-11


18-20: LGTM: 생성자가 적절히 업데이트되었습니다.

entityManagerjdslRenderContext 파라미터가 추가되어 JPQL 쿼리 실행에 필요한 의존성을 제공합니다. 이는 searchCompanies 메서드의 새로운 구현과 일관성이 있습니다.

@waterfogSW waterfogSW merged commit 0ddcc72 into main Oct 8, 2024
3 checks passed
@waterfogSW waterfogSW deleted the feat/search-company branch October 8, 2024 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants