-
Notifications
You must be signed in to change notification settings - Fork 0
[✨feat] ScrapCount VO 구현 #47
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
base: feat/#44
Are you sure you want to change the base?
Conversation
- 스크랩 수를 책임지는 값 객체 ScrapCount를 구현했습니다. - 외부에서 임의의 값을 주입할 수 없도록 생성자를 제한하고, 항상 0에서 시작하도록 from() 메서드를 제공합니다. - increase(), decrease()를 통해 상태를 변경하며, 값은 0 미만으로 감소할 수 없도록 예외 처리를 포함했습니다. - equals, hashCode, toString을 오버라이딩하여 값 객체로서의 동등성 비교를 보장합니다.
- from() 호출 시 0으로 초기화되는 ScrapCount의 생성 동작을 검증했습니다. - increase()와 decrease()를 통해 각각 값이 1씩 증가/감소하는 동작을 확인했습니다. - 값이 0일 때 decrease()를 호출하면 예외가 발생하는 케이스도 검증했습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Implements a value object to manage scrap counts on InternshipAnnouncement
, enforcing immutability and non-negative constraints, with unit tests.
- Add
ScrapCount
VO withincrease()
,decrease()
, validation, and JPA embedding - Cover initial value, increment/decrement behavior, and underflow exception in tests
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
src/main/kotlin/com/terning/server/kotlin/domain/internshipAnnouncement/ScrapCount.kt | Implemented ScrapCount VO with validation and JPA annotation |
src/test/kotlin/com/terning/server/kotlin/domain/internshipAnnouncement/ScrapCountTest.kt | Added tests for initial, increase, decrease, and underflow |
Comments suppressed due to low confidence (1)
src/test/kotlin/com/terning/server/kotlin/domain/internshipAnnouncement/ScrapCountTest.kt:1
- There are no tests for
equals()
,hashCode()
ortoString()
. Adding these would ensure full VO behavior coverage.
package com.terning.server.kotlin.domain.internshipAnnouncement
@Embeddable | ||
class ScrapCount private constructor( | ||
val value: Int, | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JPA @embeddable classes require a no-argument constructor (at least protected) for runtime instantiation. Consider adding a protected default constructor alongside the private one.
) { | |
) { | |
protected constructor() : this(MIN_VALUE) |
Copilot uses AI. Check for mistakes.
import jakarta.persistence.Embeddable | ||
|
||
@Embeddable | ||
class ScrapCount private constructor( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider making this a Kotlin data class
to auto-generate equals
, hashCode
, and toString
, reducing boilerplate.
class ScrapCount private constructor( | |
data class ScrapCount private constructor( |
Copilot uses AI. Check for mistakes.
package com.terning.server.kotlin.domain.internshipAnnouncement | ||
|
||
import jakarta.persistence.Embeddable | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Add KDoc above the class to explain the domain intent, invariants (non-negative), and usage examples for future maintainers.
/** | |
* Represents the count of "scraps" in the domain model. | |
* | |
* This class enforces the invariant that the count must always be non-negative. | |
* It provides methods to increase or decrease the count, ensuring that the value | |
* never drops below zero. | |
* | |
* Example usage: | |
* ``` | |
* val initialCount = ScrapCount.from() // Creates a ScrapCount with value 0 | |
* val increasedCount = initialCount.increase() // Increases the count to 1 | |
* val decreasedCount = increasedCount.decrease() // Decreases the count back to 0 | |
* ``` | |
*/ |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
스크랩 수를 위한 증가, 감소 함수 잘 보았습니다! 수고하셨어요~
📄 Work Description
InternshipAnnouncement
의 스크랩 수를 관리하기 위한 값 객체ScrapCount
를 구현했습니다.정수 기반의 단순 필드를 VO로 추출하여 불변성과 도메인 책임을 명확히 했습니다.
from()
을 통해 항상 0으로 초기화되며 외부 값 주입은 허용하지 않습니다.increase()
와decrease()
를 통해 상태를 변경하며, 감소 시 0 이하로 내려갈 수 없도록 보호합니다.💭 Thoughts
InternshipAnnouncement
엔티티에 적용하여 책임 분리 및 테스트 가능성을 높일 예정입니다.✅ Testing Result
🗂 Related Issue