Skip to content

feat(connection): 현재 connection attempt 조회 메서드 구현#49

Merged
dojinyou merged 1 commit intomainfrom
feature/get-connection
Apr 9, 2025
Merged

feat(connection): 현재 connection attempt 조회 메서드 구현#49
dojinyou merged 1 commit intomainfrom
feature/get-connection

Conversation

@dojinyou
Copy link
Copy Markdown
Collaborator

@dojinyou dojinyou commented Apr 9, 2025

Summary by CodeRabbit

  • New Features
    • 사용자가 최신 연결 시도를 쉽게 확인할 수 있는 기능 추가.
    • 백엔드 서비스와 데이터 접근 방식이 개선되어, 연결 내역 조회가 더욱 효율적이고 신뢰성 있게 처리됨.

@dojinyou dojinyou requested a review from waterfogSW as a code owner April 9, 2025 11:51
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 9, 2025

Walkthrough

이번 변경사항은 사용자 연결 시도의 최신 정보를 조회하기 위한 인터페이스와 서비스 기능을 추가합니다. GetCurrentConnectionAttempt 인터페이스와 관련 Command, Result 데이터 클래스를 정의하고, 이를 구현하는 ConnectionQueryService 클래스를 도입합니다. 또한, 사용자별 최신 연결 시도 정보를 조회할 수 있도록 도메인, 퍼시스턴스 계층의 저장소 인터페이스와 어댑터에 새로운 메서드를 추가합니다.

Changes

파일 경로 변경 내용
application/src/main/kotlin/com/threedays/application/connection/port/inbound/GetCurrentConnection.kt
application/src/main/kotlin/com/threedays/application/connection/service/ConnectionQueryService.kt
새로운 인터페이스 GetCurrentConnectionAttempt 추가 (Command, Result 포함) 및 이를 구현하는 ConnectionQueryService 클래스 도입, 사용자 연결 시도 조회 기능 구현
domain/src/main/kotlin/com/threedays/domain/connection/repository/ConnectionAttemptRepository.kt 사용자 ID 기반 최신 연결 시도 조회를 위한 findLatestConnectionAttempt(userId: User.Id): ConnectionAttempt? 메서드 추가
infrastructure/persistence/src/main/kotlin/com/threedays/persistence/connection/adapter/ConnectionAttemptPersistenceAdapter.kt
infrastructure/persistence/src/main/kotlin/com/threedays/persistence/connection/repository/ConnectionAttemptJpaRepository.kt
퍼시스턴스 계층에서 최신 연결 시도 조회 기능 추가: 어댑터에 findLatestConnectionAttempt 구현 및 JPA 레포지토리에 findFirstByUserIdOrderByCreatedAtDesc(userId: UUID): ConnectionAttemptJpaEntity? 메서드 추가

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Service as ConnectionQueryService
    participant Repo as ConnectionAttemptRepository
    participant Adapter as ConnectionAttemptPersistenceAdapter
    participant JPA as ConnectionAttemptJpaRepository

    Client->>Service: invoke(Command)
    Service->>Repo: findLatestConnectionAttempt(userId)
    Repo->>Adapter: call adapter method
    Adapter->>JPA: findFirstByUserIdOrderByCreatedAtDesc(userId)
    JPA-->>Adapter: ConnectionAttemptJpaEntity / null
    Adapter-->>Repo: 도메인 ConnectionAttempt 반환
    Repo-->>Service: ConnectionAttempt 혹은 null
    alt ConnectionAttempt 존재
       Service-->>Client: Result(ConnectionAttempt)
    else 존재하지 않음
       Service-->>Client: NotFoundException 발생
    end
Loading

Possibly related PRs

Suggested reviewers

  • waterfogSW

Poem

나는 작은 토끼, 코드의 숲을 달리고,
새로운 연결 시도를 심었네.
명령과 결과가 춤추듯
서로를 이어주는 이 길,
한 줄기 빛처럼 반짝이며
코드의 가치를 노래하네 🐇✨.
앞으로도 함께 뛰어가리라!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8aa4c4f and 8f70dd8.

📒 Files selected for processing (6)
  • application/src/main/kotlin/com/threedays/application/connection/port/inbound/GetCurrentConnection.kt (1 hunks)
  • application/src/main/kotlin/com/threedays/application/connection/service/ConnectionQueryService.kt (1 hunks)
  • domain/src/main/kotlin/com/threedays/domain/connection/repository/ConnectionAttemptRepository.kt (1 hunks)
  • domain/src/testFixtures/kotlin/com/threedays/domain/connection/repository/ConnectionAttemptRepositorySpy.kt (1 hunks)
  • infrastructure/persistence/src/main/kotlin/com/threedays/persistence/connection/adapter/ConnectionAttemptPersistenceAdapter.kt (1 hunks)
  • infrastructure/persistence/src/main/kotlin/com/threedays/persistence/connection/repository/ConnectionAttemptJpaRepository.kt (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • domain/src/testFixtures/kotlin/com/threedays/domain/connection/repository/ConnectionAttemptRepositorySpy.kt
  • domain/src/main/kotlin/com/threedays/domain/connection/repository/ConnectionAttemptRepository.kt
  • infrastructure/persistence/src/main/kotlin/com/threedays/persistence/connection/repository/ConnectionAttemptJpaRepository.kt
  • application/src/main/kotlin/com/threedays/application/connection/port/inbound/GetCurrentConnection.kt
  • application/src/main/kotlin/com/threedays/application/connection/service/ConnectionQueryService.kt
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Run unit test and static analysis
🔇 Additional comments (2)
infrastructure/persistence/src/main/kotlin/com/threedays/persistence/connection/adapter/ConnectionAttemptPersistenceAdapter.kt (2)

5-5: User 엔티티의 Id 타입을 사용하기 위한 import 추가

사용자 ID를 매개변수로 받는 새로운 메서드를 위해 User 엔티티의 Id 타입을 사용하기 위한 import 구문이 적절하게 추가되었습니다.


15-17: 사용자별 최신 연결 시도를 조회하는 메서드 구현이 적절합니다.

PR 목적에 맞게 사용자별 최신 연결 시도 정보를 조회하는 메서드가 잘 구현되었습니다.

  • JPA Repository에서 createdAt 기준 내림차순 정렬하여 첫 번째 결과를 가져오는 접근 방식이 적절합니다.
  • 도메인 엔티티로의 변환도 일관성 있게 처리되었습니다.
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@dojinyou dojinyou force-pushed the feature/get-connection branch from c31e001 to f20d543 Compare April 9, 2025 11:54
Copy link
Copy Markdown

@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

🧹 Nitpick comments (2)
application/src/main/kotlin/com/threedays/application/connection/service/ConnectionQueryService.kt (1)

9-11: 의존성 은닉성 개선이 필요합니다.

서비스 클래스의 구현은 전반적으로 잘 되어 있습니다만, 의존성 주입 부분에서 개선이 필요합니다. 현재 connectionAttemptRepositoryval로 선언되어 있어 외부에서 접근 가능한 공개 프로퍼티가 되었습니다. 의존성은 일반적으로 캡슐화하는 것이 좋은 관행입니다.

다음과 같이 수정하는 것을 권장합니다:

-class ConnectionQueryService(
-    val connectionAttemptRepository: ConnectionAttemptRepository,
-) : GetCurrentConnectionAttempt {
+class ConnectionQueryService(
+    private val connectionAttemptRepository: ConnectionAttemptRepository,
+) : GetCurrentConnectionAttempt {
application/src/main/kotlin/com/threedays/application/connection/port/inbound/GetCurrentConnection.kt (1)

1-20: 인터페이스 설계가 명확하고 적절합니다.

코드는 잘 구조화되어 있으며 헥사고날 아키텍처 패턴을 적절하게 따르고 있습니다. 다만 몇 가지 개선할 점이 있습니다:

  1. 파일명(GetCurrentConnection.kt)과 인터페이스명(GetCurrentConnectionAttempt)이 일치하지 않습니다. 일관성을 위해 둘 중 하나를 수정하는 것이 좋겠습니다.

  2. 인터페이스와 메서드에 KDoc 문서화가 없습니다. 각 매개변수의 목적과 동작 방식에 대한 문서를 추가하면 코드의 가독성과 유지보수성이 향상될 것입니다.

  3. Result 클래스의 connectionAttempt 속성이 null이 될 수 없습니다. 사용자에 대한 연결 시도가 없는 경우를 처리하는 방법을 고려해야 합니다.

data class Result(
    val connectionAttempt: ConnectionAttempt?,
)

또는 빈 목록을 반환하는 방식도 고려할 수 있습니다:

data class Result(
    val connectionAttempts: List<ConnectionAttempt> = emptyList(),
)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 730b553 and c31e001.

📒 Files selected for processing (5)
  • application/src/main/kotlin/com/threedays/application/connection/port/inbound/GetCurrentConnection.kt (1 hunks)
  • application/src/main/kotlin/com/threedays/application/connection/service/ConnectionQueryService.kt (1 hunks)
  • domain/src/main/kotlin/com/threedays/domain/connection/repository/ConnectionAttemptRepository.kt (1 hunks)
  • infrastructure/persistence/src/main/kotlin/com/threedays/persistence/connection/adapter/ConnectionAttemptPersistenceAdapter.kt (2 hunks)
  • infrastructure/persistence/src/main/kotlin/com/threedays/persistence/connection/repository/ConnectionAttemptJpaRepository.kt (1 hunks)
🔇 Additional comments (4)
infrastructure/persistence/src/main/kotlin/com/threedays/persistence/connection/repository/ConnectionAttemptJpaRepository.kt (1)

9-11: Spring Data JPA 메서드 구현이 잘 되었습니다!

메서드 이름이 Spring Data JPA 명명 규칙을 정확히 따르고 있으며, 특정 사용자의 가장 최근 연결 시도를 조회하는 기능을 효과적으로 구현했습니다. 반환 타입이 nullable로 설정된 것도 사용자에게 연결 시도가 없을 수 있는 경우를 고려한 좋은 설계입니다.

domain/src/main/kotlin/com/threedays/domain/connection/repository/ConnectionAttemptRepository.kt (1)

4-4: 도메인 계층의 리포지토리 인터페이스 확장이 잘 구현되었습니다!

User.Id 타입을 매개변수로 사용하고 도메인 엔티티인 ConnectionAttempt를 반환하는 메서드 시그니처는 도메인 주도 설계 원칙에 잘 부합합니다. 도메인 타입을 사용하여 영속성 계층의 구현 세부사항(raw UUID)을 도메인 계층에서 숨기는 추상화가 잘 되어 있습니다.

Also applies to: 8-10

infrastructure/persistence/src/main/kotlin/com/threedays/persistence/connection/adapter/ConnectionAttemptPersistenceAdapter.kt (1)

5-5: 어댑터 구현이 헥사고날 아키텍처 패턴을 잘 따르고 있습니다!

도메인 계층의 User.Id를 받아 JPA 리포지토리 메서드에 필요한 UUID로 변환하고, 결과를 다시 도메인 엔티티로 매핑하는 구현이 깔끔합니다. 안전 호출 연산자(?.)를 사용해 결과가 없을 경우 null을 반환하도록 처리한 부분도 적절합니다. 영속성 계층과 도메인 계층을 잘 분리한 좋은 구현입니다.

Also applies to: 17-19

application/src/main/kotlin/com/threedays/application/connection/service/ConnectionQueryService.kt (1)

13-17: 유스케이스 구현이 잘 되었습니다!

repository를 통해 최신 연결 시도를 조회하고, 결과가 없을 경우 적절한 예외를 발생시키는 구현이 명확합니다. Elvis 연산자(?:)를 사용한 null 체크 처리도 코틀린 관용적인 방식으로 잘 작성되었습니다. 도메인 엔티티를 애플리케이션 레이어의 Result 객체로 변환하는 부분도 깔끔하게 처리되었습니다.

@@ -13,6 +14,10 @@ import kotlin.jvm.optionals.getOrNull
class ConnectionAttemptPersistenceAdapter(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Transactional 빼버릴까요? ㅋㅋ 단순 읽기작업에 트랜잭션이 나가는게 생각보다 성능에 유의미한 영향이 있다더라구요
https://tech.kakaopay.com/post/jpa-transactional-bri/

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@dojinyou dojinyou force-pushed the feature/get-connection branch from f20d543 to e31e9e1 Compare April 9, 2025 11:58
Copy link
Copy Markdown

@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: 1

🧹 Nitpick comments (1)
domain/src/testFixtures/kotlin/com/threedays/domain/connection/repository/ConnectionAttemptRepositorySpy.kt (1)

8-11: 테스트 스파이의 메서드 호출 추적 기능 추가 제안

테스트 스파이의 일반적인 목적은 메서드 호출을 추적하는 것입니다. 이 메서드가 호출되었는지와 어떤 매개변수로 호출되었는지 추적하는 기능을 추가하는 것이 좋을 것 같습니다.

class ConnectionAttemptRepositorySpy : ConnectionAttemptRepository, RepositorySpyBase<ConnectionAttempt, ConnectionAttempt.Id>() {
+    val findLatestConnectionAttemptCalls = mutableListOf<User.Id>()
+    
    override fun findLatestConnectionAttempt(userId: User.Id): ConnectionAttempt? {
+        findLatestConnectionAttemptCalls.add(userId)
        return entities.values
            .filter { it.userId == userId }
            .maxByOrNull { it.createdAt }
    }
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f20d543 and e31e9e1.

📒 Files selected for processing (6)
  • application/src/main/kotlin/com/threedays/application/connection/port/inbound/GetCurrentConnection.kt (1 hunks)
  • application/src/main/kotlin/com/threedays/application/connection/service/ConnectionQueryService.kt (1 hunks)
  • domain/src/main/kotlin/com/threedays/domain/connection/repository/ConnectionAttemptRepository.kt (1 hunks)
  • domain/src/testFixtures/kotlin/com/threedays/domain/connection/repository/ConnectionAttemptRepositorySpy.kt (1 hunks)
  • infrastructure/persistence/src/main/kotlin/com/threedays/persistence/connection/adapter/ConnectionAttemptPersistenceAdapter.kt (2 hunks)
  • infrastructure/persistence/src/main/kotlin/com/threedays/persistence/connection/repository/ConnectionAttemptJpaRepository.kt (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • application/src/main/kotlin/com/threedays/application/connection/service/ConnectionQueryService.kt
  • infrastructure/persistence/src/main/kotlin/com/threedays/persistence/connection/adapter/ConnectionAttemptPersistenceAdapter.kt
  • infrastructure/persistence/src/main/kotlin/com/threedays/persistence/connection/repository/ConnectionAttemptJpaRepository.kt
  • application/src/main/kotlin/com/threedays/application/connection/port/inbound/GetCurrentConnection.kt
  • domain/src/main/kotlin/com/threedays/domain/connection/repository/ConnectionAttemptRepository.kt
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Run unit test and static analysis

@dojinyou dojinyou force-pushed the feature/get-connection branch from e31e9e1 to 8aa4c4f Compare April 9, 2025 12:02
@dojinyou dojinyou force-pushed the feature/get-connection branch from 8aa4c4f to 8f70dd8 Compare April 9, 2025 12:04
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 9, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarQube Cloud

@dojinyou
Copy link
Copy Markdown
Collaborator Author

dojinyou commented Apr 9, 2025

image 요거 뭐징..

@waterfogSW
Copy link
Copy Markdown
Member

image 요거 뭐징..

ㅋㅋㅋ 첨봅니다. xml이니 고대 유물같은거아닐까요? 머지하시져

@dojinyou dojinyou merged commit dbc6cd6 into main Apr 9, 2025
1 of 2 checks passed
@dojinyou dojinyou deleted the feature/get-connection branch April 9, 2025 12:18
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