Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
june0216 committed Oct 15, 2023
2 parents c10c125 + 6523fff commit 41281db
Show file tree
Hide file tree
Showing 8 changed files with 430 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class MyCommentResDto {
private Long id;
private String postType;
private String postTitle;
private LocalDateTime createdDate;
private Boolean isJoinus;
private LocalDateTime createdDate;

public static MyCommentResDto of(Comment comment) {
Post post = comment.getPost();
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;
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,29 +46,54 @@ 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, meetup.getId());
sendReviewRequestEmail(traveler, kuddy, meetup.getId());
}
}
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);

}
public void sendReviewRequestEmail(Member receiver, Member partner, Long meetupId) throws MessagingException { //TODO: private으로 수정
String emailSubject = "[KUDDY] How was the meet up yesterday? Please write a review.";

MimeMessage kuddyMessage = javaMailSender.createMimeMessage();
MimeMessageHelper kuddyMessageHelper = new MimeMessageHelper(kuddyMessage, false, "UTF-8");

kuddyMessageHelper.setTo(receiver.getEmail());
kuddyMessageHelper.setSubject(emailSubject);
kuddyMessageHelper.setText(setContext(receiver.getNickname(), partner.getNickname()), true);
kuddyMessageHelper.setText(setContext(receiver.getNickname(), partner.getNickname(), meetupId), true);
javaMailSender.send(kuddyMessage);
}

public String setContext(String receiver, String partner){
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, Long meetupId){
Context context = new Context();
context.setVariable("receiver", receiver);
context.setVariable("partner", partner);
context.setVariable("meetupId", meetupId);
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());
}

}
4 changes: 2 additions & 2 deletions api-server/src/main/resources/templates/email-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" style="border-collapse:separate;line-height:100%;">
<tr>
<td align="center" bgcolor="#2F67F6" role="presentation" style="border:none;border-radius:3px;color:#ffffff;cursor:auto;padding:15px 25px;" valign="middle">
<p style="background:#2F67F6;color:#ffffff;font-family:'Helvetica Neue',Arial,sans-serif;font-size:15px;font-weight:normal;line-height:120%;Margin:0;text-decoration:none;text-transform:none;">
<a th:href="@{https://kuddy.co.kr/my/write-review/{meetupId}(meetupId = ${meetupId})}" style="background-color: rgba(0, 0, 0, 0); color: #fff; font-family: 'Helvetica Neue', Arial, sans-serif; font-size: 15px; font-weight: normal; line-height: 120%; Margin: 0; text-decoration: none; text-transform: none;">
Write a Review
</p>
</a>
</td>
</tr>
</table>
Expand Down
Loading

0 comments on commit 41281db

Please sign in to comment.