Skip to content

[✨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

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

[✨feat] ScrapCount VO 구현 #47

wants to merge 2 commits into from

Conversation

jsoonworld
Copy link
Member

📄 Work Description

InternshipAnnouncement의 스크랩 수를 관리하기 위한 값 객체 ScrapCount를 구현했습니다.
정수 기반의 단순 필드를 VO로 추출하여 불변성과 도메인 책임을 명확히 했습니다.

  • from()을 통해 항상 0으로 초기화되며 외부 값 주입은 허용하지 않습니다.
  • increase()decrease()를 통해 상태를 변경하며, 감소 시 0 이하로 내려갈 수 없도록 보호합니다.
  • equals, hashCode, toString을 오버라이딩하여 VO 특성을 갖추었습니다.

💭 Thoughts

  • 조회수와 달리 스크랩 수는 증가와 감소가 모두 필요한 값이므로 decrease() 메서드를 추가했습니다.
  • 음수로 감소하지 않도록 방어 로직을 포함하여 도메인 무결성을 보장합니다.
  • 이후 InternshipAnnouncement 엔티티에 적용하여 책임 분리 및 테스트 가능성을 높일 예정입니다.

✅ Testing Result

스크린샷 2025-05-18 오후 3 19 53


🗂 Related Issue

- 스크랩 수를 책임지는 값 객체 ScrapCount를 구현했습니다.
- 외부에서 임의의 값을 주입할 수 없도록 생성자를 제한하고, 항상 0에서 시작하도록 from() 메서드를 제공합니다.
- increase(), decrease()를 통해 상태를 변경하며, 값은 0 미만으로 감소할 수 없도록 예외 처리를 포함했습니다.
- equals, hashCode, toString을 오버라이딩하여 값 객체로서의 동등성 비교를 보장합니다.
- from() 호출 시 0으로 초기화되는 ScrapCount의 생성 동작을 검증했습니다.
- increase()와 decrease()를 통해 각각 값이 1씩 증가/감소하는 동작을 확인했습니다.
- 값이 0일 때 decrease()를 호출하면 예외가 발생하는 케이스도 검증했습니다.
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

Implements a value object to manage scrap counts on InternshipAnnouncement, enforcing immutability and non-negative constraints, with unit tests.

  • Add ScrapCount VO with increase(), 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() or toString(). Adding these would ensure full VO behavior coverage.
package com.terning.server.kotlin.domain.internshipAnnouncement

@Embeddable
class ScrapCount private constructor(
val value: Int,
) {
Copy link
Preview

Copilot AI May 18, 2025

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.

Suggested change
) {
) {
protected constructor() : this(MIN_VALUE)

Copilot uses AI. Check for mistakes.

import jakarta.persistence.Embeddable

@Embeddable
class ScrapCount private constructor(
Copy link
Preview

Copilot AI May 18, 2025

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.

Suggested change
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

Copy link
Preview

Copilot AI May 18, 2025

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.

Suggested change
/**
* 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.

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.

스크랩 수를 위한 증가, 감소 함수 잘 보았습니다! 수고하셨어요~

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