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

알림 읽기 기능 구현 #775

Merged
merged 23 commits into from
Oct 18, 2023
Merged

알림 읽기 기능 구현 #775

merged 23 commits into from
Oct 18, 2023

Conversation

woo-chang
Copy link
Collaborator

🔥 연관 이슈

📝 작업 요약

알림 읽기 기능을 구현하였습니다.

⏰ 소요 시간

1시간

🔎 작업 상세 설명

  • 알림을 읽을 수 있는 대상인 경우 알림을 읽은 상태로 변경하는 기능입니다.

🌟 논의 사항

리뷰 감사합니다 :)

@github-actions
Copy link

github-actions bot commented Oct 18, 2023

Test Results

467 tests   466 ✔️  33s ⏱️
150 suites      1 💤
150 files        0

Results for commit 4355004.

♻️ This comment has been updated with latest results.

Copy link
Collaborator

@jeomxon jeomxon left a comment

Choose a reason for hiding this comment

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

빠르게 구현해주셨네요!
궁금한 점이 남아있어 RC드립니다!

final Alarm alarm = alarmRepository.findById(alarmId)
.orElseThrow(() -> new NotFoundException(AlarmExceptionType.NOT_FOUND));

alarm.checkOwner(loginMember);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Q
조회하는 시점부터 회원 + 알림ID로 하는 방법과의 차이는 무엇인가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

멤버와도 같이 조회해버리면 ID가 없어서 발생하는 예외인지, 멤버가 일치하지 않아서 발생하는 예외인지 확인할 수가 없더라구요 🥲

또한 알림의 대상이 누구인지 검증하는 책임은 알림 도메인에 있다고 생각하여 도메인 로직을 통해 검증할 수 있도록 하였습니다 !

Comment on lines +16 to +34
@Test
@DisplayName("알림을 읽으면 읽음 여부가 TRUE로 수정된다.")
void readAlarm() {
// given
Member member = MemberFixtures.MALE_30.get();
Alarm alarm = Alarm.builder()
.member(member)
.alarmType(AlarmType.COMMENT)
.targetId(1L)
.detail("detail")
.isChecked(false)
.build();

// when
alarm.read();

// then
assertThat(alarm.isChecked()).isTrue();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

P2
setter에 대한 테스트가 필요한가요?

Copy link
Collaborator

Choose a reason for hiding this comment

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

전 개인적으로 파라미터로 값을 전달해주는 완전한 setter가 아니면 추후에 해당 메서드의 내부 로직이 어떻게 변할 지 모르고, 이 또한 해당 메서드의 명세가 될 수 있기 때문에 테스트가 필요하다고 생각하는데,

다즐의 의견도 궁금하네요.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

저도 아벨의 의견에 동의해요 :)

캡슐화 되어있기 떄문에 내부적으로 세터인지 외부에서는 알 수 없습니다. 추후에 로직이 변경되었을 때 로직을 확인할 수 있는 하나의 문서로 테스트가 존재할 수 있기에 테스트가 있으면 좋을 것 같아요 !

Copy link
Collaborator

Choose a reason for hiding this comment

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

오 그렇네요 제가 빠르게 보다보니 일반적인 setter와 같다고 생각했던 것 같아요
테스트 있으면 좋을 것 같습니다!

.when().patch("/alarms/{id}", alarmId)
.then().log().all()
.status(HttpStatus.BAD_REQUEST)
.body("code", equalTo(201))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Q
이 코드 201은 어디서 나온 코드인가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ui 계층에서 발생하는 예외 코드는 GlobalExceptionHandler에서 정의하고 있습니다 😀

Copy link
Collaborator

@tjdtls690 tjdtls690 left a comment

Choose a reason for hiding this comment

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

수고하셨습니다 다즐!
몇 가지 리뷰 남겼어요 :)

Comment on lines +16 to +34
@Test
@DisplayName("알림을 읽으면 읽음 여부가 TRUE로 수정된다.")
void readAlarm() {
// given
Member member = MemberFixtures.MALE_30.get();
Alarm alarm = Alarm.builder()
.member(member)
.alarmType(AlarmType.COMMENT)
.targetId(1L)
.detail("detail")
.isChecked(false)
.build();

// when
alarm.read();

// then
assertThat(alarm.isChecked()).isTrue();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

전 개인적으로 파라미터로 값을 전달해주는 완전한 setter가 아니면 추후에 해당 메서드의 내부 로직이 어떻게 변할 지 모르고, 이 또한 해당 메서드의 명세가 될 수 있기 때문에 테스트가 필요하다고 생각하는데,

다즐의 의견도 궁금하네요.

Comment on lines 45 to 48
@ApiResponse(
responseCode = "201",
description = "조회 성공"
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

페이지가 0미만이면 400 반환한다는 내용도 포함되면 좋을 것 같아요 :)

Comment on lines 58 to 59
final PageRequest pageRequest = PageRequest.of(page, BASIC_PAGE_SIZE,
Sort.by(Sort.Direction.DESC, "createdAt"));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
final PageRequest pageRequest = PageRequest.of(page, BASIC_PAGE_SIZE,
Sort.by(Sort.Direction.DESC, "createdAt"));
final PageRequest pageRequest = PageRequest.of(
page,
BASIC_PAGE_SIZE,
Sort.by(Sort.Direction.DESC, "createdAt")
);

이렇게 바꿔보는 것은 어떨까요

Comment on lines +71 to +75
public void checkOwner(final Member member) {
if (!Objects.equals(this.member.getId(), member.getId())) {
throw new BadRequestException(AlarmExceptionType.NOT_OWNER);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Q
자신 것이 아닌 알람을 읽을 수 있는 경우는 어떤 상황에 있을 수 있는지 궁금합니다

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

알림 ID가 노출되어 다른 회원이 해당 ID로 API를 요청하는 것을 방지하기 위한 방어 코드입니다 :)

Comment on lines 24 to 27
@ApiResponse(
responseCode = "400",
description = "알림을 읽을 수 있는 대상이 아닌 경우"
),
Copy link
Collaborator

Choose a reason for hiding this comment

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

alarmId가 1미만인 경우도 적어주면 좋을 것 같아요.

Copy link
Collaborator

@tjdtls690 tjdtls690 left a comment

Choose a reason for hiding this comment

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

고생하셨습니다 ㅡ 즐 ㅡ

Copy link
Collaborator

@aiaiaiai1 aiaiaiai1 left a comment

Choose a reason for hiding this comment

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

빠르게 수정해서 구현해주셨네요!
딱히 피드백이 보이지 않아서 바로 approve 하겠습니다
고생하셨습니다!


private final AlarmReadStrategyProvider alarmReadStrategyProvider;

public void readAlarm(final Long alarmId, final String type, final Member loginMember) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

개행이 빠져있어요~

# Conflicts:
#	backend/src/main/java/com/votogether/domain/alarm/controller/AlarmCommandControllerDocs.java
#	backend/src/main/java/com/votogether/domain/alarm/controller/AlarmQueryController.java
#	backend/src/main/java/com/votogether/domain/alarm/service/AlarmQueryService.java
#	backend/src/test/java/com/votogether/domain/alarm/controller/AlarmCommandControllerTest.java
#	backend/src/test/java/com/votogether/domain/alarm/service/AlarmQueryServiceTest.java
Copy link
Collaborator

@jeomxon jeomxon left a comment

Choose a reason for hiding this comment

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

👍🏻

@woo-chang woo-chang merged commit df585f2 into dev Oct 18, 2023
3 checks passed
@woo-chang woo-chang deleted the feat/#766 branch October 18, 2023 09:56
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.

알림 읽기 기능 구현
4 participants