-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat: 벌레 조회 기능 구현 #21
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
12a512d
feat: Bug 임베디드 타입 생성
kmebin 6f4b4e0
feat: 벌레 조회 API 구현
kmebin a4f3897
docs: PR merge 시, Issue 자동 close로 수정
kmebin e7ab9ef
refactor: 엔티티 생성자 id 포함으로 변경
kmebin 3e45ef9
feat: 벌레 개수 검증 추가
kmebin ee520a8
test: 벌레 조회 서비스 테스트
kmebin a9afd52
style: dto 내 bug 패키지 제거
kmebin 1c0c287
test: Bug 도메인 테스트
kmebin 594208d
style: 테스트 메서드 네이밍 수정
kmebin 48f0e7c
test: 벌레 조회 controller 테스트
kmebin ea7170e
refactor: private 생성자 추가
kmebin 6d66ee5
Merge branch 'develop' into feature/#11
kmebin bd35b4e
test: 멤버 fixture 생성 및 적용
kmebin 2f493bd
test: 벌레 fixture 생성 및 적용
kmebin 1eb913a
test: 멤버 엔티티 테스트에 Bug 추가
kmebin 48f49d2
fix: code smell 제거
kmebin 3c90fa8
style: BugMapper 메서드 네이밍 수정
kmebin 416adac
style: return 전 줄바꿈 추가
kmebin ebb1e1e
refactor: ResponseStatus + DTO 방식으로 변경
kmebin 89163c4
test: 벌레 개수 검증 테스트에 ParameterizedTest 적용
kmebin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
## 📋 Checklist | ||
|
||
- [ ] 🔀 PR 제목의 형식을 잘 작성했나요? (e.g. `feat: 유저 조회 기능 구현`) | ||
- [ ] 🏷️ 라벨, 프로젝트, 마일스톤은 등록했나요? | ||
- [ ] 🧹 코드 스멜은 해결했나요? | ||
|
||
## 🧩 이슈 번호 <!-- 이슈 번호를 작성해주세요 ex) #11 --> | ||
|
||
- #이슈번호 | ||
- close #이슈번호 | ||
|
||
## 👩💻 공유 포인트 및 논의 사항 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.moabam.api.application; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.moabam.api.domain.entity.Member; | ||
import com.moabam.api.dto.BugMapper; | ||
import com.moabam.api.dto.BugResponse; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class BugService { | ||
|
||
private final MemberService memberService; | ||
|
||
public BugResponse getBug(Long memberId) { | ||
Member member = memberService.getById(memberId); | ||
|
||
return BugMapper.toBugResponse(member.getBug()); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/moabam/api/application/MemberService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.moabam.api.application; | ||
|
||
import static com.moabam.global.error.model.ErrorMessage.*; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.moabam.api.domain.entity.Member; | ||
import com.moabam.api.domain.repository.MemberRepository; | ||
import com.moabam.global.error.exception.NotFoundException; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class MemberService { | ||
|
||
private final MemberRepository memberRepository; | ||
|
||
public Member getById(Long memberId) { | ||
return memberRepository.findById(memberId) | ||
.orElseThrow(() -> new NotFoundException(MEMBER_NOT_FOUND)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.moabam.api.domain.entity; | ||
|
||
import static com.moabam.global.error.model.ErrorMessage.*; | ||
|
||
import org.hibernate.annotations.ColumnDefault; | ||
|
||
import com.moabam.global.error.exception.BadRequestException; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Embeddable | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Bug { | ||
|
||
@Column(name = "morning_bug", nullable = false) | ||
@ColumnDefault("0") | ||
private int morningBug; | ||
|
||
@Column(name = "night_bug", nullable = false) | ||
@ColumnDefault("0") | ||
private int nightBug; | ||
|
||
@Column(name = "golden_bug", nullable = false) | ||
@ColumnDefault("0") | ||
private int goldenBug; | ||
|
||
@Builder | ||
private Bug(int morningBug, int nightBug, int goldenBug) { | ||
this.morningBug = validateBugCount(morningBug); | ||
this.nightBug = validateBugCount(nightBug); | ||
this.goldenBug = validateBugCount(goldenBug); | ||
} | ||
|
||
private int validateBugCount(int bug) { | ||
if (bug < 0) { | ||
throw new BadRequestException(INVALID_BUG_COUNT); | ||
} | ||
|
||
return bug; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/main/java/com/moabam/api/domain/repository/MemberRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.moabam.api.domain.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.moabam.api.domain.entity.Member; | ||
|
||
public interface MemberRepository extends JpaRepository<Member, Long> { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.moabam.api.dto; | ||
|
||
import com.moabam.api.domain.entity.Bug; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public final class BugMapper { | ||
|
||
public static BugResponse toBugResponse(Bug bug) { | ||
return BugResponse.builder() | ||
.morningBug(bug.getMorningBug()) | ||
.nightBug(bug.getNightBug()) | ||
.goldenBug(bug.getGoldenBug()) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.moabam.api.dto; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record BugResponse( | ||
int morningBug, | ||
int nightBug, | ||
int goldenBug | ||
) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/com/moabam/api/presentation/BugController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.moabam.api.presentation; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.moabam.api.application.BugService; | ||
import com.moabam.api.dto.BugResponse; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequestMapping("/bugs") | ||
@RequiredArgsConstructor | ||
public class BugController { | ||
|
||
private final BugService bugService; | ||
|
||
@GetMapping | ||
@ResponseStatus(HttpStatus.OK) | ||
public BugResponse getBug() { | ||
return bugService.getBug(1L); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/test/java/com/moabam/api/application/BugServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.moabam.api.application; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
import static org.mockito.BDDMockito.*; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import com.moabam.api.domain.entity.Bug; | ||
import com.moabam.api.domain.entity.Member; | ||
import com.moabam.api.dto.BugResponse; | ||
import com.moabam.fixture.MemberFixture; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class BugServiceTest { | ||
|
||
@InjectMocks | ||
BugService bugService; | ||
|
||
@Mock | ||
MemberService memberService; | ||
|
||
@DisplayName("벌레를 조회한다.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 조회 실패에 대한 테스트 코드는 없나요? |
||
@Test | ||
void get_bug_success() { | ||
// given | ||
Long memberId = 1L; | ||
Member member = MemberFixture.member(); | ||
given(memberService.getById(memberId)).willReturn(member); | ||
|
||
// when | ||
BugResponse response = bugService.getBug(memberId); | ||
|
||
// then | ||
Bug bug = member.getBug(); | ||
assertThat(response.morningBug()).isEqualTo(bug.getMorningBug()); | ||
assertThat(response.nightBug()).isEqualTo(bug.getNightBug()); | ||
assertThat(response.goldenBug()).isEqualTo(bug.getGoldenBug()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.moabam.api.domain.entity; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
|
||
import com.moabam.global.error.exception.BadRequestException; | ||
|
||
class BugTest { | ||
|
||
@DisplayName("벌레 개수가 음수이면 예외가 발생한다.") | ||
@ParameterizedTest | ||
@CsvSource({ | ||
"-10, 10, 10", | ||
"10, -10, 10", | ||
"10, 10, -10", | ||
}) | ||
void validate_bug_count_exception(int morningBug, int nightBug, int goldenBug) { | ||
Bug.BugBuilder bugBuilder = Bug.builder() | ||
.morningBug(morningBug) | ||
.nightBug(nightBug) | ||
.goldenBug(goldenBug); | ||
|
||
assertThatThrownBy(bugBuilder::build) | ||
.isInstanceOf(BadRequestException.class) | ||
.hasMessage("벌레 개수는 0 이상이어야 합니다."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@parksey 이것 좀 수정해주세요ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ
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.
ㅇㅈㅋㅋㅋㅋ
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.
ㅋㅋㅋㅋㅋㅋㅋ맞다 이거였다
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.
고쳤습니다ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ