-
Notifications
You must be signed in to change notification settings - Fork 1
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: YSL-12 출근 타이머 등록 기능 추가 #11
Conversation
오오오 잘 참고하겠습니다 |
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
WorkTimer workTimer = (WorkTimer) o; | ||
return Objects.equals(id, workTimer.id) && Objects.equals(checkIn, workTimer.checkIn) && Objects.equals(checkOut, workTimer.checkOut) && Objects.equals(code, workTimer.code); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, checkIn, checkOut, code); | ||
} |
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.
domain 부분에서 메소드를 만드는 것은 update 기능을 만들 때 사용한다고 생각했었는데 equals와 hashCode를 보고 값을 비교하거나 암호와 하는 메소드도 추가할 수 있다는 것을 알게 되었습니다.
import org.idiot.yesslave.worktimer.domain.WorkTimer; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface WorkTimerRepository extends JpaRepository<WorkTimer, Long>, WorkTimerCustomRepository { |
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.
WorkTimerCustomRepository를 따로 빼두신 이유가 나중에 관리하기 편함인지 궁금합니다:)
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.
JpaRepository를 상속받은 WorkTimerRepository를 implements 해서 구현하려고 하면, JpaRepository의 메소드들을 다 재정의를 해주어야 하기 때문에 .🥹. 자연스럽게 CustomRepository로 분리하게 되어씁니다 👍🏻
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.
�일단 승인합니다.
한번 봐줬으면 하는 부분 코멘트 달아드렸어요
|
||
@PostMapping | ||
public ResponseEntity<Void> timerCreate() { | ||
Long response = workTimerService.registerTimer(LocalDateTime.now(), new RandomCodeGenerator()); |
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.
RandomCodeGenerator.java
싱글톤으로 생성했지만 실제 사용은 객체를 만들어서 사용하는거 같네요 🥲
|
||
@Entity | ||
@Getter | ||
@AllArgsConstructor |
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.
AllArgsConstructor 쓰신 이유가 궁금합니다
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.
비즈니스 코드를 작성할떄는 크게 작성할 일이 없다만, 테스트 코드 작성시에 값을 할당해주기 위해 사용하고 있습니다.
혹시 다른 방법이 있을까요?
@AutoConfigureMockMvc | ||
@ExtendWith(SpringExtension.class) | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK) |
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.
컨트롤러 테스트에서 Mocking 을 사용하는데 @SpringBootTest 를 사용하신 이유가 있는지 궁금합니다.
제가 알기론 @SpringBootTest 는 기본적으로 모든 빈을 탐색하고 등록한다고 알고 있어서요.
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.
저는 mocking하는데에 있어서 webEnvironment = SpringBootTest.WebEnvironment.MOCK
를 명시해주면 mocking 환경을 제공해준다고 생각을 했는데, 현우님이 주신 코멘트로 인해 찾아보니 @SpringBootTest
자체가 기본 환경이 MOCK
이라고 하네요. ((충격))
새로이 배우게 되었습니다.
지금 새롭게 만드는 feature에서는 @WebMvcTest
로 구현 해보고, 테스트가 원할히 된다면 해당 코드도 수정을 해 보아야겠습니다
최초 타이머 저장을 요청할 경우, 조회할 수 있는 URL이 반환됩니다.