Skip to content

Commit

Permalink
Merge pull request #160 from KUDDY-2023/feature/8-community
Browse files Browse the repository at this point in the history
[feat] ๋™ํ–‰ ์„ฑ์‚ฌ ๋ฉ”์ผ ์•Œ๋ฆผ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•œ๋‹ค.
  • Loading branch information
ParkIsComing authored Oct 13, 2023
2 parents 6f8443d + 06bb7dd commit ccffcaf
Show file tree
Hide file tree
Showing 7 changed files with 425 additions and 59 deletions.
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;

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,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

0 comments on commit ccffcaf

Please sign in to comment.