Skip to content
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

[Be/fix] 특정 날짜의 식사 정보 조회하는 API 오류 수정 #427

Merged
merged 13 commits into from
Jul 22, 2024

Conversation

hwangdaesun
Copy link
Collaborator

📌 관련 이슈

#425

🔑 주요 변경사항

  • CustomMemberRepositoryImpl 클래스의 findByMemberIdAndDate메서드 수정

켈린더 상세 조회시 해당 회원의 상태는 특정 날짜에 따라 달라져야 한다. 따라서, 특정 날짜 기준으로 MemberEntity의 updatedAt 필드가 그 전에 있을 경우 MemberEntity에 저장된 회원 정보를 사용한다.

  • CustomHistoryRepositoryImpl의 findByMemberIdAndDate 메서드 수정

그리고, 특정 날짜 기준으로 MemberEntity updated 필드가 그 이후에 있다면 과거 변경 이력이 있다는 뜻으로 HistoryEntity를 확인하다.
이때, HistoryEntity의 경우 특정 날짜를 기준으로 미래중 가장 가까운 기록을 사용한다.

  • CustomMemberRepositoryImpl 클래스, CustomHistoryRepositoryImpl 클래스 쿼리 테스트 수행

  • 회원가입한 날짜보다 전의 켈린더 조회하는 경우 Validate하는 ValidateBeforeSignUpUsecase 개발

  • 특정 날짜의 식사 정보 조회하는 API 통합 테스트 보충 (식사 기록이 없을 경우, 회원가입 되기 전 날짜를 조회한 경우)

@hwangdaesun hwangdaesun added bug Something isn't working BE fix test labels Jul 22, 2024
@hwangdaesun hwangdaesun requested a review from LJH098 July 22, 2024 08:44
@hwangdaesun hwangdaesun self-assigned this Jul 22, 2024
@hwangdaesun hwangdaesun added this to the BE_daesun milestone Jul 22, 2024
Comment on lines 28 to 34
.where(
historyEntity
.memberEntity
.id
.eq(memberId)
.and(checkFutureDate(historyEntity, date)))
.orderBy(historyEntity.createdDate.asc())
Copy link
Collaborator

Choose a reason for hiding this comment

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

정렬도 pk로 정렬하는게 가장 빠른 것으로 알고있는데 Id GeneratorType을 AutoIncrement로 안했을 경우를 대비하여 createdDate로 정렬한건가요?

Copy link
Collaborator Author

@hwangdaesun hwangdaesun Jul 22, 2024

Choose a reason for hiding this comment

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

PK로 정렬하는 게 더 빠르네요. 반영하겠습니다.

Comment on lines +15 to +27
@RequiredArgsConstructor
public class ValidateBeforeSignupService implements ValidateBeforeSignUpUsecase {

private final MemberPersistenceAdapter memberPersistenceAdapter;

@Override
public void execute(Long memberId, LocalDateTime dateTime) {
MemberEntity memberEntity = memberPersistenceAdapter.query(memberId);
if (memberEntity.checkIfBeforeSignUp(dateTime)) {
throw InValidDateFoundException.EXECPTION;
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

이 유효성 검증은 왜 서비스로 따로 뺴셨나요? POJO 도메인안에 메서드로 작성하자고 하지 않았나용?

Copy link
Collaborator Author

@hwangdaesun hwangdaesun Jul 22, 2024

Choose a reason for hiding this comment

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

MemberEntity의 updatedAt을 이용해서 해당 날짜가 회원가입 전이란 것을 알려주는 것 (checkIfBeforeSignUp 메서드) 까지는 MemberEntity에서 하는 것이라 생각했고, InValidDateFoundException 예외를 터뜨리는 것은 켈린더 상세 조회 서비스의 책임이라고 생각했습니다.

Comment on lines 22 to 28
void findMostRecentFutureMember() {
LocalDateTime dateTime = LocalDateTime.of(2023, 12, 04, 12, 00);
HistoryEntity historyEntity =
customHistoryRepository.findMostRecentFutureMember(1L, dateTime);
assertEquals(historyEntity.getWeight(), 72.0);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

왜 여기 메서드 이름은 when_~~ 으로 하지 않았나요?

Copy link
Collaborator Author

@hwangdaesun hwangdaesun Jul 22, 2024

Choose a reason for hiding this comment

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

으악 감사합니다.

@hwangdaesun hwangdaesun merged commit 764e34f into be Jul 22, 2024
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BE bug Something isn't working fix test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants