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

프로필 이미지가 null일 경우 알림 전송에 실패하는 오류 해결 #412

Merged
merged 13 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -10,7 +10,8 @@
import com.ddang.ddang.chat.infrastructure.persistence.JpaChatRoomRepository;
import com.ddang.ddang.chat.infrastructure.persistence.JpaMessageRepository;
import com.ddang.ddang.chat.presentation.dto.request.ReadMessageRequest;
import com.ddang.ddang.image.application.util.ImageIdProcessor;
import com.ddang.ddang.image.domain.ProfileImage;
import com.ddang.ddang.image.presentation.util.ImageUrlCalculator;
import com.ddang.ddang.notification.application.NotificationService;
import com.ddang.ddang.notification.application.dto.CreateNotificationDto;
import com.ddang.ddang.notification.domain.NotificationType;
Expand Down Expand Up @@ -67,27 +68,24 @@ public Long create(final CreateMessageDto dto, final String baseUrl) {
}

private String sendNotification(final Message message, final String baseUrl) {
final ProfileImage writerProfileImage = message.getWriter().getProfileImage();

final CreateNotificationDto dto = new CreateNotificationDto(
NotificationType.MESSAGE,
message.getReceiver().getId(),
message.getWriter().getName(),
message.getContents(),
calculateRedirectUrl(message.getChatRoom().getId()),
calculateProfileImageUrl(message, baseUrl)
ImageUrlCalculator.calculateProfileImageUrl(writerProfileImage, baseUrl)
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍🏻

);

return notificationService.send(dto);
}

private String calculateRedirectUrl(final Long id) {
return "/chattings/" + id;
}

private String calculateProfileImageUrl(final Message message, final String baseUrl) {
final Long profileImageId = ImageIdProcessor.process(message.getWriter().getProfileImage());
return baseUrl.concat(String.valueOf(profileImageId));
}

public List<ReadMessageDto> readAllByLastMessageId(final ReadMessageRequest request) {
if (!userRepository.existsById(request.userId())) {
throw new UserNotFoundException("지정한 아이디에 대한 사용자를 찾을 수 없습니다.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.ddang.ddang.image.presentation.util;

import com.ddang.ddang.image.application.util.ImageIdProcessor;
import com.ddang.ddang.image.domain.ProfileImage;

public final class ImageUrlCalculator {

private ImageUrlCalculator() {
Expand All @@ -14,4 +17,9 @@ public static String calculate(final ImageBaseUrl imageBaseUrl, final Long id) {

return baseUrl.concat(String.valueOf(id));
}

public static String calculateProfileImageUrl(final ProfileImage profileImage, final String baseUrl) {
final Long profileImageId = ImageIdProcessor.process(profileImage);
return baseUrl.concat(String.valueOf(profileImageId));
}
}