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

코드 리팩터링 #257

Merged
merged 1 commit into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,8 @@ public void update(final DailyRoutine dailyRoutine) {
this.routineType = dailyRoutine.getRoutineType();
this.routineDescription = dailyRoutine.getRoutineDescription();
}

public boolean isNotOwner(final Long memberId) {
return !this.memberId.equals(memberId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ private DailyRoutineEntity getDailyRoutineEntity(final Long timeBlockId, final M
final DailyRoutineEntity dailyRoutineEntity = dailyRoutineRepository.findById(timeBlockId)
.orElseThrow(() -> new EntityNotFoundException("해당하는 ID의 DailyRoutine이 존재하지 않습니다."));

if (!dailyRoutineEntity.getMemberId().equals(member.getId())) {
if (dailyRoutineEntity.isNotOwner(member.getId())) {
throw new BusinessException("본인의 DailyRoutine만 수정 및 삭제할 수 있습니다.");
}

return dailyRoutineEntity;
}

@Transactional
public Long deleteDailyRoutine(final Long timeBlockId, final MemberEntity member) {
final DailyRoutineEntity dailyRoutineEntity = getDailyRoutineEntity(timeBlockId, member);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,23 @@ void update() {
assertThat(dailyRoutineEntity.getRoutineDescription()).isEqualTo(newDailyRoutine.getRoutineDescription());
assertThat(dailyRoutineEntity.getMemberId()).isEqualTo(memberId);
}

@Test
@DisplayName("dailyRoutineEntity의 멤버 아이디와 비교하여 본인의 DailyRoutine인지 확인할 수 있다.")
void isNotOwner() {
//given
final Long memberId = 1L;
final DailyRoutine dailyRoutine = getDailyRoutine(
getRoutineTime(9, 10),
"SLEEP",
"낮잠"
);
final DailyRoutineEntity dailyRoutineEntity = DailyRoutineEntity.of(dailyRoutine, memberId);

//when
final boolean isNotOwner = dailyRoutineEntity.isNotOwner(2L);

//then
assertThat(isNotOwner).isTrue();
}
}
Loading