Skip to content

[✨feat] ViewCount VO 구현 #45

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

Open
wants to merge 2 commits into
base: feat/#42
Choose a base branch
from
Open

[✨feat] ViewCount VO 구현 #45

wants to merge 2 commits into from

Conversation

jsoonworld
Copy link
Member

📄 Work Description

  • 조회수를 담당하는 값 객체 ViewCount를 구현했습니다.
  • 항상 0에서 시작하며, 외부에서 임의의 값을 전달할 수 없도록 설계했습니다.
  • increase() 메서드를 통해서만 값이 변경되며, 불변성을 유지합니다.
  • 음수 값에 대한 방어 로직을 포함해 무결성을 보장합니다.

💭 Thoughts

  • 조회수는 도메인상 항상 0부터 시작하고 증가만 허용되므로, 정적 팩터리 메서드 from()만 제공하도록 제한했습니다.
  • 외부에서 음수 값이 전달될 수 없도록 설계한 구조이므로, 예외 테스트는 생략했습니다.
  • 추후 InternshipAnnouncement 엔티티에 적용할 예정입니다.

✅ Testing Result

스크린샷 2025-05-18 오후 3 08 42


🗂 Related Issue

- 조회수 정보를 캡슐화한 값 객체 ViewCount를 구현했습니다.
- 항상 0에서 시작하며, increase() 메서드를 통해서만 상태가 변경됩니다.
- 외부 값 전달은 허용하지 않고, from()을 통한 생성만 허용하여 무결성을 보장합니다.
- equals, hashCode, toString 오버라이딩을 통해 VO로서의 특성을 갖추었습니다.
- from()을 통해 0으로 초기화되는 ViewCount의 생성 동작을 검증했습니다.
- increase() 호출 시 값이 1 증가된 새 인스턴스가 반환되는 동작을 검증했습니다.
- 외부 값 전달이 불가능한 구조이므로, 음수 예외 테스트는 포함하지 않았습니다.
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces an immutable ViewCount value object to enforce that the view count always starts at zero and only increments. It includes a factory method for initialization, an increase() method returning a new instance, and corresponding unit tests.

  • Implements the ViewCount VO with immutability and negative value guarding.
  • Adds unit tests verifying initial value and incrementation.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/main/kotlin/com/terning/server/kotlin/domain/internshipAnnouncement/ViewCount.kt Implements the immutable ViewCount object with built-in invariant checks and a controlled increase() method
src/test/kotlin/com/terning/server/kotlin/domain/internshipAnnouncement/ViewCountTest.kt Provides unit tests validating the ViewCount initialization and increment behavior

Copy link
Member

@leeeyubin leeeyubin left a comment

Choose a reason for hiding this comment

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

완벽해서 코드리뷰 달 게 없네용..😂
정적 팩토리 메서드까지 고려하신 점 인상깊게 보고 갑니다~!

Comment on lines +13 to +22
fun increase(): ViewCount = ViewCount(value + 1)

companion object {
private const val MIN_VALUE = 0
private const val INVALID_VIEW_COUNT_MESSAGE = "조회수는 음수일 수 없습니다."

fun from(): ViewCount = ViewCount(MIN_VALUE)
}

override fun equals(other: Any?): Boolean = other is ViewCount && value == other.value
Copy link
Member

Choose a reason for hiding this comment

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

이전 PR에서 언급은 했지만, 코드리뷰 확인해보시구 여기도 순서 맞춰주면 좋을 것 같아요!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants