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

[feat] 동행 성사 메일 알림 기능을 구현한다. #160

Merged
merged 6 commits into from
Oct 13, 2023
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 @@ -14,6 +14,7 @@ public class MyCommentResDto {
private Long id;
private String postType;
private String postTitle;
private Boolean isJoinus;
private LocalDateTime createdDate;
private Boolean isJoinus;

Choose a reason for hiding this comment

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

이 코드 패치는 MyCommentResDto 클래스에 새로운 필드인 isJoinus를 추가하는 것으로 보입니다.

이 코드의 주된 문제는 중복된 필드 isJoinus가 두 번 선언되었다는 점입니다. 이러한 유형의 중복은 충돌을 일으킬 수 있으며 코드의 가독성과 유지 보수성을 저해할 수 있습니다. 따라서 한 번만 선언되도록 수정하는 것이 좋습니다.

또한, 코드에서 사용되는 변수들에 대한 주석이나 설명이 없습니다. 다른 개발자들이 코드를 이해하기 어려울 수 있으므로 명확한 설명을 추가하는 것이 좋습니다.

마지막으로, 코드에서 어디에 사용되는지 확인할 수 없는 id, postType, postTitle, createdDate 변수들이 선언되어 있습니다. 필요한 경우 해당 변수들에 대한 사용처를 추가하거나 제거하는 것이 좋습니다.

이러한 수정 사항을 고려하여 코드를 개선하실 수 있을 것입니다.

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
import com.kuddy.common.member.domain.ProviderType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import com.kuddy.apiserver.meetup.dto.MeetupListResDto;
import com.kuddy.common.meetup.domain.Meetup;

Choose a reason for hiding this comment

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

이 코드 패치는 어떤 리팩토링 작업인가요?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.kuddy.apiserver.notification.service.CommentNotiService;
import com.kuddy.apiserver.notification.service.MeeupNotiService;
import com.kuddy.common.meetup.service.MeetupService;
import com.kuddy.common.member.domain.Member;
import com.kuddy.common.notification.calendar.service.KakaoCalendarService;
Expand All @@ -10,12 +11,11 @@
import com.kuddy.common.security.user.AuthUser;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import java.io.UnsupportedEncodingException;
import javax.mail.MessagingException;

@Slf4j
@RestController
Expand All @@ -25,6 +25,7 @@ public class NotificationController {
private final CommentNotiService notificationService;
private final MeetupService meetupService;
private final KakaoCalendarService kakaoCalendarService;
private final MeeupNotiService meeupNotiService;

//알림 구독 (SSE)
@GetMapping(value = "/subscribe", produces = "text/event-stream")
Expand Down Expand Up @@ -69,4 +70,15 @@ public ResponseEntity<StatusResponse> createCalendarEvent(@AuthUser Member membe
.build());
}

@GetMapping("/mails")
public ResponseEntity<StatusResponse> sendEmailForMeetupSuccess(@AuthUser Member member, @RequestParam String chatId) throws MessagingException, JsonProcessingException {
meeupNotiService.pubishMeetupPayedEvent(chatId);

return ResponseEntity.ok(StatusResponse.builder()
.status(StatusEnum.OK.getStatusCode())
.message(StatusEnum.OK.getCode())
.data("메일 전송 완료")
.build());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.thymeleaf.context.Context;
import org.thymeleaf.spring5.SpringTemplateEngine;
Expand Down Expand Up @@ -44,11 +46,19 @@ public void sendReviewRequestEmail() throws MessagingException {
for(Meetup meetup : meetups) {
Member kuddy = meetup.getKuddy();
Member traveler = meetup.getTraveler();
sendEmail(kuddy, traveler);
sendEmail(traveler, kuddy);
sendReviewRequestEmail(kuddy, traveler);
sendReviewRequestEmail(traveler, kuddy);
}
}
private void sendEmail(Member receiver, Member partner) throws MessagingException {

@Async
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void sendMeetupPayedMail(String kuddyEmail, String travelerEmail, String kuddyNickname, String travelerNickname) throws MessagingException {
sendMeetupPayedEmail(kuddyEmail, kuddyNickname, travelerNickname);
sendMeetupPayedEmail(travelerEmail, travelerNickname, kuddyNickname);

}
private void sendReviewRequestEmail(Member receiver, Member partner) throws MessagingException {
String emailSubject = "[KUDDY] How was the meet up yesterday? Please write a review.";

MimeMessage kuddyMessage = javaMailSender.createMimeMessage();
Expand All @@ -60,13 +70,29 @@ private void sendEmail(Member receiver, Member partner) throws MessagingExceptio
javaMailSender.send(kuddyMessage);
}

private void sendMeetupPayedEmail(String receiverEmail, String receiverNickname, String partnerNickname) throws MessagingException {
String emailSubject = "[KUDDY] There is a confirmed meetup. Please check it!";
MimeMessage kuddyMessage = javaMailSender.createMimeMessage();
MimeMessageHelper kuddyMessageHelper = new MimeMessageHelper(kuddyMessage, false, "UTF-8");

kuddyMessageHelper.setTo(receiverEmail);
kuddyMessageHelper.setSubject(emailSubject);
kuddyMessageHelper.setText(setContextForMeetupPayed(receiverNickname, partnerNickname), true);
javaMailSender.send(kuddyMessage);
}

public String setContext(String receiver, String partner){
Context context = new Context();
context.setVariable("receiver", receiver);
context.setVariable("partner", partner);
return templateEngine.process("email-form.html",context);
}


public String setContextForMeetupPayed(String receiver, String partner){
Context context = new Context();
context.setVariable("receiver", receiver);
context.setVariable("partner", partner);
return templateEngine.process("meetupPayedForm.html",context);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.kuddy.apiserver.notification.service;

import com.kuddy.common.meetup.domain.Meetup;
import com.kuddy.common.meetup.exception.MeetupNotFoundException;
import com.kuddy.common.meetup.repository.MeetupRepository;
import com.kuddy.common.member.domain.Member;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import javax.mail.MessagingException;
import javax.transaction.Transactional;

@Service
@Transactional
@RequiredArgsConstructor
public class MeeupNotiService {
private final MeetupRepository meetupRepository;
private final MailNotiService mailNotiService;

public void pubishMeetupPayedEvent(String chatId) throws MessagingException {
Meetup meetup = meetupRepository.findByChatId(chatId).orElseThrow(MeetupNotFoundException::new);
Member kuddy = meetup.getKuddy();
Member traveler = meetup.getTraveler();
mailNotiService.sendMeetupPayedMail(kuddy.getEmail(), traveler.getEmail(), kuddy.getNickname(), traveler.getNickname());
}

}
Loading