From c7c28315528e38ff9fc01bf9f24a1a23e1d4252e Mon Sep 17 00:00:00 2001 From: Chaerin Hwang Date: Mon, 19 Aug 2024 14:42:39 +0900 Subject: [PATCH 01/10] =?UTF-8?q?refactor:=20=EB=94=94=EB=A0=89=ED=84=B0?= =?UTF-8?q?=EB=A6=AC=20=EA=B5=AC=EC=A1=B0=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{member => email}/controller/EmailController.java | 6 +++--- .../{member/dto/request => email/dto}/EmailRequestDto.java | 2 +- .../domain/{member => email}/service/EmailService.java | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) rename src/main/java/sws/songpin/domain/{member => email}/controller/EmailController.java (85%) rename src/main/java/sws/songpin/domain/{member/dto/request => email/dto}/EmailRequestDto.java (87%) rename src/main/java/sws/songpin/domain/{member => email}/service/EmailService.java (95%) diff --git a/src/main/java/sws/songpin/domain/member/controller/EmailController.java b/src/main/java/sws/songpin/domain/email/controller/EmailController.java similarity index 85% rename from src/main/java/sws/songpin/domain/member/controller/EmailController.java rename to src/main/java/sws/songpin/domain/email/controller/EmailController.java index 038fc9e8..d2966237 100644 --- a/src/main/java/sws/songpin/domain/member/controller/EmailController.java +++ b/src/main/java/sws/songpin/domain/email/controller/EmailController.java @@ -1,4 +1,4 @@ -package sws.songpin.domain.member.controller; +package sws.songpin.domain.email.controller; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -8,8 +8,8 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; -import sws.songpin.domain.member.dto.request.EmailRequestDto; -import sws.songpin.domain.member.service.EmailService; +import sws.songpin.domain.email.dto.EmailRequestDto; +import sws.songpin.domain.email.service.EmailService; @Tag(name = "Email", description = "Email 관련 API입니다.") @RestController diff --git a/src/main/java/sws/songpin/domain/member/dto/request/EmailRequestDto.java b/src/main/java/sws/songpin/domain/email/dto/EmailRequestDto.java similarity index 87% rename from src/main/java/sws/songpin/domain/member/dto/request/EmailRequestDto.java rename to src/main/java/sws/songpin/domain/email/dto/EmailRequestDto.java index d9a581e3..a80299a0 100644 --- a/src/main/java/sws/songpin/domain/member/dto/request/EmailRequestDto.java +++ b/src/main/java/sws/songpin/domain/email/dto/EmailRequestDto.java @@ -1,4 +1,4 @@ -package sws.songpin.domain.member.dto.request; +package sws.songpin.domain.email.dto; import jakarta.validation.constraints.Email; import jakarta.validation.constraints.NotEmpty; diff --git a/src/main/java/sws/songpin/domain/member/service/EmailService.java b/src/main/java/sws/songpin/domain/email/service/EmailService.java similarity index 95% rename from src/main/java/sws/songpin/domain/member/service/EmailService.java rename to src/main/java/sws/songpin/domain/email/service/EmailService.java index 7aa8992a..172c272c 100644 --- a/src/main/java/sws/songpin/domain/member/service/EmailService.java +++ b/src/main/java/sws/songpin/domain/email/service/EmailService.java @@ -1,4 +1,4 @@ -package sws.songpin.domain.member.service; +package sws.songpin.domain.email.service; import jakarta.mail.MessagingException; import lombok.RequiredArgsConstructor; @@ -10,14 +10,14 @@ import org.springframework.transaction.annotation.Transactional; import org.thymeleaf.context.Context; import org.thymeleaf.spring6.SpringTemplateEngine; -import sws.songpin.domain.member.dto.request.EmailRequestDto; +import sws.songpin.domain.email.dto.EmailRequestDto; import jakarta.mail.internet.MimeMessage; +import sws.songpin.domain.member.service.MemberService; import sws.songpin.global.auth.RedisService; import sws.songpin.global.exception.CustomException; import sws.songpin.global.exception.ErrorCode; -import javax.xml.catalog.Catalog; import java.time.Duration; import java.util.HashMap; import java.util.UUID; From a8778553700acd2b79a09f872c8fd18d87ef2cf0 Mon Sep 17 00:00:00 2001 From: Chaerin Hwang Date: Mon, 19 Aug 2024 16:07:01 +0900 Subject: [PATCH 02/10] =?UTF-8?q?feat:=20=EC=8B=A0=EA=B3=A0=20=EB=A9=94?= =?UTF-8?q?=EC=9D=BC=20=EC=A0=84=EC=86=A1=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../email/controller/EmailController.java | 11 +++- .../domain/email/dto/ReportRequestDto.java | 13 ++++ .../domain/email/service/EmailService.java | 39 +++++++++++- .../sws/songpin/domain/model/ReportType.java | 25 ++++++++ .../resources/templates/email/reportMail.html | 59 +++++++++++++++++++ 5 files changed, 143 insertions(+), 4 deletions(-) create mode 100644 src/main/java/sws/songpin/domain/email/dto/ReportRequestDto.java create mode 100644 src/main/java/sws/songpin/domain/model/ReportType.java create mode 100644 src/main/resources/templates/email/reportMail.html diff --git a/src/main/java/sws/songpin/domain/email/controller/EmailController.java b/src/main/java/sws/songpin/domain/email/controller/EmailController.java index d2966237..22fa2294 100644 --- a/src/main/java/sws/songpin/domain/email/controller/EmailController.java +++ b/src/main/java/sws/songpin/domain/email/controller/EmailController.java @@ -7,22 +7,31 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import sws.songpin.domain.email.dto.EmailRequestDto; +import sws.songpin.domain.email.dto.ReportRequestDto; import sws.songpin.domain.email.service.EmailService; @Tag(name = "Email", description = "Email 관련 API입니다.") @RestController +@RequestMapping("/mail") @RequiredArgsConstructor public class EmailController { private final EmailService emailService; @Operation(summary = "비밀번호 재설정 이메일 전송", description = "요청받은 이메일로 비밀번호 재설정 링크 전달") - @PostMapping("/mail/pw") + @PostMapping("/pw") public ResponseEntity sendPasswordEmail(@RequestBody @Valid EmailRequestDto requestDto){ emailService.sendPasswordEmail(requestDto); return ResponseEntity.ok().build(); + } + @Operation(summary = "유저 신고 메일 전송", description = "유저 신고 내역을 담은 보고서를 운영자 메일로 전송") + @PostMapping("/report") + public ResponseEntity sendReportEmail(@RequestBody @Valid ReportRequestDto requestDto){ + emailService.sendReportEmail(requestDto); + return ResponseEntity.ok().build(); } } diff --git a/src/main/java/sws/songpin/domain/email/dto/ReportRequestDto.java b/src/main/java/sws/songpin/domain/email/dto/ReportRequestDto.java new file mode 100644 index 00000000..c28037db --- /dev/null +++ b/src/main/java/sws/songpin/domain/email/dto/ReportRequestDto.java @@ -0,0 +1,13 @@ +package sws.songpin.domain.email.dto; + +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Size; +import sws.songpin.domain.model.ReportType; + +public record ReportRequestDto( + @NotNull Long reporterId, + @NotNull Long reportedId, + @NotNull ReportType reportType, + @Size(max = 200) String reason + ) { +} diff --git a/src/main/java/sws/songpin/domain/email/service/EmailService.java b/src/main/java/sws/songpin/domain/email/service/EmailService.java index 172c272c..dae8de43 100644 --- a/src/main/java/sws/songpin/domain/email/service/EmailService.java +++ b/src/main/java/sws/songpin/domain/email/service/EmailService.java @@ -12,6 +12,7 @@ import org.thymeleaf.spring6.SpringTemplateEngine; import sws.songpin.domain.email.dto.EmailRequestDto; import jakarta.mail.internet.MimeMessage; +import sws.songpin.domain.email.dto.ReportRequestDto; import sws.songpin.domain.member.service.MemberService; import sws.songpin.global.auth.RedisService; import sws.songpin.global.exception.CustomException; @@ -46,11 +47,8 @@ public void sendPasswordEmail(EmailRequestDto requestDto){ //요청받은 이메일로 가입한 회원이 탈퇴하거나 없는 경우 예외 처리 memberService.getActiveMemberByEmail(email); - String uuid = UUID.randomUUID().toString().replaceAll("-", ""); - - String title = "[송핀] 비밀번호 재설정 링크 전송"; //이메일 제목 String link = passwordUrl + "/" + uuid; @@ -81,7 +79,42 @@ public void sendPasswordEmail(EmailRequestDto requestDto){ throw new CustomException(ErrorCode.EMAIL_ERROR); } + } + + public void sendReportEmail(ReportRequestDto requestDto){ + Long reporterId = requestDto.reporterId(); + Long reportedId = requestDto.reportedId(); + String reportedHandle = memberService.getActiveMemberById(reportedId).getHandle(); + String reportType = requestDto.reportType().toString(); + String reason = requestDto.reason(); + + HashMap map = new HashMap<>(); + map.put("reporterId", reporterId); + map.put("reportedId", reportedId); + map.put("reportedUrl", "https://www.songpin.kr/users/"+reportedHandle); + map.put("reportType", reportType); + map.put("reason", reason); + + Context context = new Context(); + context.setVariables(map); //템플릿에 전달할 데이터 + String content = templateEngine.process("reportMail.html", context); + + String title = "[유저 신고] " + reporterId + " → " + reportedId; //이메일 제목 + + //메일 전송 + try{ + MimeMessage mailMessage = javaMailSender.createMimeMessage(); + MimeMessageHelper helper = new MimeMessageHelper(mailMessage, true, "UTF-8"); + helper.setFrom(fromMail); //이메일 발신 주소 + helper.setTo(fromMail); //이메일 송신 주소 + helper.setSubject(title); //이메일 제목 + helper.setText(content, true); + helper.addInline("logo", new ClassPathResource(logoPath)); + javaMailSender.send(mailMessage); + } catch (MessagingException e){ + throw new CustomException(ErrorCode.EMAIL_ERROR); + } } } diff --git a/src/main/java/sws/songpin/domain/model/ReportType.java b/src/main/java/sws/songpin/domain/model/ReportType.java new file mode 100644 index 00000000..6d4e46a2 --- /dev/null +++ b/src/main/java/sws/songpin/domain/model/ReportType.java @@ -0,0 +1,25 @@ +package sws.songpin.domain.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import sws.songpin.global.exception.CustomException; +import sws.songpin.global.exception.ErrorCode; + +public enum ReportType { + + SPAM, + FLOODING, + ABUSE, + DOXXING, + OFFENSIVE, + OTHER + ; + + @JsonCreator + public static ReportType from(String s) { + try { + return ReportType.valueOf(s.toUpperCase()); + } catch (IllegalArgumentException e) { + throw new CustomException(ErrorCode.INVALID_ENUM_VALUE); + } + } +} diff --git a/src/main/resources/templates/email/reportMail.html b/src/main/resources/templates/email/reportMail.html new file mode 100644 index 00000000..86f9148f --- /dev/null +++ b/src/main/resources/templates/email/reportMail.html @@ -0,0 +1,59 @@ + + + + + Songpin Mail + + + + +
+ + + + + + + +
+ logo +
+

유저 신고 보고서

+

아래는 유저 신고의 세부 정보입니다:

+ + + + + + + + + + + + + + + + + +
+ 신고자 ID: + +
+ 신고된 ID: + +
+ 신고 유형: + +
+ 신고 사유: + +
+ +
+
+ + From 9ed73582a59349b9dfd50bec90f0dec2fa837ded Mon Sep 17 00:00:00 2001 From: Chaerin Hwang Date: Mon, 19 Aug 2024 16:13:23 +0900 Subject: [PATCH 03/10] =?UTF-8?q?refactor:=20=EC=A4=91=EB=B3=B5=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EB=A6=AC=ED=8C=A9=ED=84=B0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/email/service/EmailService.java | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/src/main/java/sws/songpin/domain/email/service/EmailService.java b/src/main/java/sws/songpin/domain/email/service/EmailService.java index dae8de43..e6298e01 100644 --- a/src/main/java/sws/songpin/domain/email/service/EmailService.java +++ b/src/main/java/sws/songpin/domain/email/service/EmailService.java @@ -42,10 +42,10 @@ public class EmailService { public void sendPasswordEmail(EmailRequestDto requestDto){ - String email = requestDto.email(); + String toMail = requestDto.email(); //요청받은 이메일로 가입한 회원이 탈퇴하거나 없는 경우 예외 처리 - memberService.getActiveMemberByEmail(email); + memberService.getActiveMemberByEmail(toMail); String uuid = UUID.randomUUID().toString().replaceAll("-", ""); @@ -60,24 +60,12 @@ public void sendPasswordEmail(EmailRequestDto requestDto){ String content = templateEngine.process("passwordResetMail.html", context); //Redis 에 (UUID,Email) 쌍 저장 - if(!redisService.setValuesWithTimeoutIfAbsent("password_uuid:"+uuid, email, Duration.ofMinutes(10))){ + if(!redisService.setValuesWithTimeoutIfAbsent("password_uuid:"+uuid, toMail, Duration.ofMinutes(10))){ throw new CustomException(ErrorCode.ERROR); } //메일 전송 - try{ - MimeMessage mailMessage = javaMailSender.createMimeMessage(); - MimeMessageHelper helper = new MimeMessageHelper(mailMessage, true, "UTF-8"); - helper.setFrom(fromMail); //이메일 발신 주소 - helper.setTo(email); //이메일 송신 주소 - helper.setSubject(title); //이메일 제목 - helper.setText(content, true); - helper.addInline("logo", new ClassPathResource(logoPath)); - - javaMailSender.send(mailMessage); - } catch (MessagingException e){ - throw new CustomException(ErrorCode.EMAIL_ERROR); - } + sendEmail(toMail,title,content); } @@ -88,6 +76,8 @@ public void sendReportEmail(ReportRequestDto requestDto){ String reportType = requestDto.reportType().toString(); String reason = requestDto.reason(); + String title = "[유저 신고] " + reporterId + " → " + reportedId; //이메일 제목 + HashMap map = new HashMap<>(); map.put("reporterId", reporterId); map.put("reportedId", reportedId); @@ -99,14 +89,16 @@ public void sendReportEmail(ReportRequestDto requestDto){ context.setVariables(map); //템플릿에 전달할 데이터 String content = templateEngine.process("reportMail.html", context); - String title = "[유저 신고] " + reporterId + " → " + reportedId; //이메일 제목 - //메일 전송 + sendEmail(fromMail,title,content); + } + + private void sendEmail(String toMail, String title, String content){ try{ MimeMessage mailMessage = javaMailSender.createMimeMessage(); MimeMessageHelper helper = new MimeMessageHelper(mailMessage, true, "UTF-8"); helper.setFrom(fromMail); //이메일 발신 주소 - helper.setTo(fromMail); //이메일 송신 주소 + helper.setTo(toMail); //이메일 송신 주소 helper.setSubject(title); //이메일 제목 helper.setText(content, true); helper.addInline("logo", new ClassPathResource(logoPath)); From ec8d68a1a171e3eed9df972e5cc17df9b421d50e Mon Sep 17 00:00:00 2001 From: Chaerin Hwang Date: Mon, 19 Aug 2024 16:34:34 +0900 Subject: [PATCH 04/10] =?UTF-8?q?feat:=20=EC=8B=A0=EA=B3=A0=20=EB=A9=94?= =?UTF-8?q?=EC=9D=BC=20=EC=A0=84=EC=86=A1=20API=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 신고자와 신고 대상이 같은 경우 에러 처리 --- .../java/sws/songpin/domain/email/service/EmailService.java | 5 +++++ src/main/java/sws/songpin/global/exception/ErrorCode.java | 1 + 2 files changed, 6 insertions(+) diff --git a/src/main/java/sws/songpin/domain/email/service/EmailService.java b/src/main/java/sws/songpin/domain/email/service/EmailService.java index e6298e01..23f53dec 100644 --- a/src/main/java/sws/songpin/domain/email/service/EmailService.java +++ b/src/main/java/sws/songpin/domain/email/service/EmailService.java @@ -76,6 +76,11 @@ public void sendReportEmail(ReportRequestDto requestDto){ String reportType = requestDto.reportType().toString(); String reason = requestDto.reason(); + //신고자 ID 와 신고 대상 ID 가 동일한 경우 + if(reporterId.equals(reportedId)){ + throw new CustomException(ErrorCode.REPORT_BAD_REQUEST); + } + String title = "[유저 신고] " + reporterId + " → " + reportedId; //이메일 제목 HashMap map = new HashMap<>(); diff --git a/src/main/java/sws/songpin/global/exception/ErrorCode.java b/src/main/java/sws/songpin/global/exception/ErrorCode.java index 7391f232..9934ec98 100644 --- a/src/main/java/sws/songpin/global/exception/ErrorCode.java +++ b/src/main/java/sws/songpin/global/exception/ErrorCode.java @@ -25,6 +25,7 @@ public enum ErrorCode { // 자신과 관련해 불가능한 요청 MEMBER_BAD_REQUEST(400, "자기 자신은 이 경로를 통해 조회할 수 없습니다."), FOLLOW_BAD_REQUEST(400,"자기 자신은 팔로잉할 수 없습니다."), + REPORT_BAD_REQUEST(400, "자기 자신을 신고할 수 없습니다."), // 401 Unauthorized // 로그인 상태여야 하는 요청 From 5bf14eebf23c9a3d310607832d584b7e60cb9030 Mon Sep 17 00:00:00 2001 From: Chaerin Hwang Date: Mon, 19 Aug 2024 17:09:07 +0900 Subject: [PATCH 05/10] =?UTF-8?q?feat:=20=EC=8B=A0=EA=B3=A0=EC=9E=90=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EB=A5=BC=20Authentication=EC=9D=84=20?= =?UTF-8?q?=ED=86=B5=ED=95=B4=20=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/sws/songpin/domain/email/dto/ReportRequestDto.java | 1 - .../java/sws/songpin/domain/email/service/EmailService.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/sws/songpin/domain/email/dto/ReportRequestDto.java b/src/main/java/sws/songpin/domain/email/dto/ReportRequestDto.java index c28037db..43d3cfa3 100644 --- a/src/main/java/sws/songpin/domain/email/dto/ReportRequestDto.java +++ b/src/main/java/sws/songpin/domain/email/dto/ReportRequestDto.java @@ -5,7 +5,6 @@ import sws.songpin.domain.model.ReportType; public record ReportRequestDto( - @NotNull Long reporterId, @NotNull Long reportedId, @NotNull ReportType reportType, @Size(max = 200) String reason diff --git a/src/main/java/sws/songpin/domain/email/service/EmailService.java b/src/main/java/sws/songpin/domain/email/service/EmailService.java index 23f53dec..25e9d55d 100644 --- a/src/main/java/sws/songpin/domain/email/service/EmailService.java +++ b/src/main/java/sws/songpin/domain/email/service/EmailService.java @@ -70,7 +70,7 @@ public void sendPasswordEmail(EmailRequestDto requestDto){ } public void sendReportEmail(ReportRequestDto requestDto){ - Long reporterId = requestDto.reporterId(); + Long reporterId = memberService.getCurrentMember().getMemberId(); Long reportedId = requestDto.reportedId(); String reportedHandle = memberService.getActiveMemberById(reportedId).getHandle(); String reportType = requestDto.reportType().toString(); From d70064d3046107569e1bb35751c62f1fabfe4d0a Mon Sep 17 00:00:00 2001 From: Chaerin Hwang Date: Mon, 19 Aug 2024 17:23:03 +0900 Subject: [PATCH 06/10] =?UTF-8?q?feat:=20=EC=8B=A0=EA=B3=A0=20=EB=A9=94?= =?UTF-8?q?=EC=9D=BC=20=ED=95=AD=EB=AA=A9=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/email/service/EmailService.java | 7 +++++-- .../sws/songpin/domain/model/ReportType.java | 18 ++++++++++++------ .../resources/templates/email/reportMail.html | 13 ++++++++++--- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/main/java/sws/songpin/domain/email/service/EmailService.java b/src/main/java/sws/songpin/domain/email/service/EmailService.java index 25e9d55d..638a5aa9 100644 --- a/src/main/java/sws/songpin/domain/email/service/EmailService.java +++ b/src/main/java/sws/songpin/domain/email/service/EmailService.java @@ -14,12 +14,14 @@ import jakarta.mail.internet.MimeMessage; import sws.songpin.domain.email.dto.ReportRequestDto; import sws.songpin.domain.member.service.MemberService; +import sws.songpin.domain.model.ReportType; import sws.songpin.global.auth.RedisService; import sws.songpin.global.exception.CustomException; import sws.songpin.global.exception.ErrorCode; import java.time.Duration; +import java.time.LocalDateTime; import java.util.HashMap; import java.util.UUID; @@ -73,7 +75,7 @@ public void sendReportEmail(ReportRequestDto requestDto){ Long reporterId = memberService.getCurrentMember().getMemberId(); Long reportedId = requestDto.reportedId(); String reportedHandle = memberService.getActiveMemberById(reportedId).getHandle(); - String reportType = requestDto.reportType().toString(); + ReportType reportType = requestDto.reportType(); String reason = requestDto.reason(); //신고자 ID 와 신고 대상 ID 가 동일한 경우 @@ -87,7 +89,8 @@ public void sendReportEmail(ReportRequestDto requestDto){ map.put("reporterId", reporterId); map.put("reportedId", reportedId); map.put("reportedUrl", "https://www.songpin.kr/users/"+reportedHandle); - map.put("reportType", reportType); + map.put("reportType", reportType+"("+reportType.getMessage()+")"); + map.put("reportTime", LocalDateTime.now()); map.put("reason", reason); Context context = new Context(); diff --git a/src/main/java/sws/songpin/domain/model/ReportType.java b/src/main/java/sws/songpin/domain/model/ReportType.java index 6d4e46a2..5f4a5831 100644 --- a/src/main/java/sws/songpin/domain/model/ReportType.java +++ b/src/main/java/sws/songpin/domain/model/ReportType.java @@ -1,19 +1,25 @@ package sws.songpin.domain.model; import com.fasterxml.jackson.annotation.JsonCreator; +import lombok.AllArgsConstructor; +import lombok.Getter; import sws.songpin.global.exception.CustomException; import sws.songpin.global.exception.ErrorCode; +@Getter +@AllArgsConstructor public enum ReportType { - SPAM, - FLOODING, - ABUSE, - DOXXING, - OFFENSIVE, - OTHER + SPAM("스팸/홍보"), + FLOODING("도배"), + ABUSE("욕설/비방"), + DOXXING("개인정보 노출"), + OFFENSIVE("불쾌감 조성"), + OTHER("기타") ; + private final String message; + @JsonCreator public static ReportType from(String s) { try { diff --git a/src/main/resources/templates/email/reportMail.html b/src/main/resources/templates/email/reportMail.html index 86f9148f..77d86fac 100644 --- a/src/main/resources/templates/email/reportMail.html +++ b/src/main/resources/templates/email/reportMail.html @@ -35,16 +35,23 @@

유저 신고 - 신고 유형: + 신고 시간: - + + 신고 유형: + + + + + + 신고 사유: - + From 84b71a63200bc1392a8707c358455d2c6c884069 Mon Sep 17 00:00:00 2001 From: Chaerin Hwang Date: Mon, 19 Aug 2024 19:05:12 +0900 Subject: [PATCH 07/10] =?UTF-8?q?feat:=20=EC=8B=A0=EA=B3=A0=20=EC=A0=91?= =?UTF-8?q?=EC=88=98=20=EC=8B=9C=20=EC=8B=A0=EA=B3=A0=EC=9E=90=EC=97=90?= =?UTF-8?q?=EA=B2=8C=20=EC=95=8C=EB=A6=BC=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../songpin/domain/alarm/entity/AlarmType.java | 1 + .../domain/alarm/service/AlarmService.java | 13 +++++++++++++ .../domain/email/service/EmailService.java | 17 ++++++++++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main/java/sws/songpin/domain/alarm/entity/AlarmType.java b/src/main/java/sws/songpin/domain/alarm/entity/AlarmType.java index b95dcc54..8c6ab9d7 100644 --- a/src/main/java/sws/songpin/domain/alarm/entity/AlarmType.java +++ b/src/main/java/sws/songpin/domain/alarm/entity/AlarmType.java @@ -7,6 +7,7 @@ @AllArgsConstructor public enum AlarmType { FOLLOW("{0}(@{1})님이 팔로우했어요."), + REPORT("{0}(@{1})님에 대한 신고가 접수되었어요."), DEFAULT("{0}(@{1})님이 보낸 알림이에요.") ; diff --git a/src/main/java/sws/songpin/domain/alarm/service/AlarmService.java b/src/main/java/sws/songpin/domain/alarm/service/AlarmService.java index 98e98089..54243662 100644 --- a/src/main/java/sws/songpin/domain/alarm/service/AlarmService.java +++ b/src/main/java/sws/songpin/domain/alarm/service/AlarmService.java @@ -47,6 +47,19 @@ public void createFollowAlarm(Member follower, Member following) { alarmRepository.save(alarm); emitterService.notify(following.getMemberId(), AlarmDefaultDataDto.from(true), "new alarm"); } + // 신고 접수 알림 생성 + public void createReportAlarm(Member reporter, Member reported) { + String message = MessageFormat.format(AlarmType.REPORT.getMessagePattern(), reported.getNickname(), reported.getHandle()); + Alarm alarm = Alarm.builder() + .alarmType(AlarmType.REPORT) + .message(message) + .sender(null) + .receiver(reporter) + .isRead(false) + .build(); + alarmRepository.save(alarm); + emitterService.notify(reporter.getMemberId(), AlarmDefaultDataDto.from(true), "new alarm"); + } public void deleteAllAlarmsOfMember(Member member){ alarmRepository.deleteAllBySender(member); diff --git a/src/main/java/sws/songpin/domain/email/service/EmailService.java b/src/main/java/sws/songpin/domain/email/service/EmailService.java index 638a5aa9..55c951a1 100644 --- a/src/main/java/sws/songpin/domain/email/service/EmailService.java +++ b/src/main/java/sws/songpin/domain/email/service/EmailService.java @@ -10,9 +10,11 @@ import org.springframework.transaction.annotation.Transactional; import org.thymeleaf.context.Context; import org.thymeleaf.spring6.SpringTemplateEngine; +import sws.songpin.domain.alarm.service.AlarmService; import sws.songpin.domain.email.dto.EmailRequestDto; import jakarta.mail.internet.MimeMessage; import sws.songpin.domain.email.dto.ReportRequestDto; +import sws.songpin.domain.member.entity.Member; import sws.songpin.domain.member.service.MemberService; import sws.songpin.domain.model.ReportType; import sws.songpin.global.auth.RedisService; @@ -40,6 +42,7 @@ public class EmailService { private final JavaMailSender javaMailSender; private final MemberService memberService; private final RedisService redisService; + private final AlarmService alarmService; private final SpringTemplateEngine templateEngine; public void sendPasswordEmail(EmailRequestDto requestDto){ @@ -72,9 +75,14 @@ public void sendPasswordEmail(EmailRequestDto requestDto){ } public void sendReportEmail(ReportRequestDto requestDto){ - Long reporterId = memberService.getCurrentMember().getMemberId(); - Long reportedId = requestDto.reportedId(); - String reportedHandle = memberService.getActiveMemberById(reportedId).getHandle(); + + Member reporter = memberService.getCurrentMember(); + Member reported = memberService.getActiveMemberById(requestDto.reportedId()); + + + Long reporterId = reporter.getMemberId(); + Long reportedId = reported.getMemberId(); + String reportedHandle = reported.getHandle(); ReportType reportType = requestDto.reportType(); String reason = requestDto.reason(); @@ -99,6 +107,9 @@ public void sendReportEmail(ReportRequestDto requestDto){ //메일 전송 sendEmail(fromMail,title,content); + + //신고자에게 알림 전송 + alarmService.createReportAlarm(reporter, reported); } private void sendEmail(String toMail, String title, String content){ From 50e12f55ccc357e9bc7cceb562af2a5e3fcabac5 Mon Sep 17 00:00:00 2001 From: Chaerin Hwang Date: Mon, 19 Aug 2024 19:15:14 +0900 Subject: [PATCH 08/10] =?UTF-8?q?fix:=20=EC=8B=A0=EA=B3=A0=20=EC=95=8C?= =?UTF-8?q?=EB=A6=BC=20=EC=83=9D=EC=84=B1=20=EC=8B=9C=20sender=20=EC=A7=80?= =?UTF-8?q?=EC=A0=95=20=EB=B0=8F=20=EC=95=8C=EB=A6=BC=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/sws/songpin/domain/alarm/service/AlarmService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/sws/songpin/domain/alarm/service/AlarmService.java b/src/main/java/sws/songpin/domain/alarm/service/AlarmService.java index 54243662..a41bd200 100644 --- a/src/main/java/sws/songpin/domain/alarm/service/AlarmService.java +++ b/src/main/java/sws/songpin/domain/alarm/service/AlarmService.java @@ -53,7 +53,7 @@ public void createReportAlarm(Member reporter, Member reported) { Alarm alarm = Alarm.builder() .alarmType(AlarmType.REPORT) .message(message) - .sender(null) + .sender(reported) // 이후 운영자 계정이 생기면 이 부분 수정 .receiver(reporter) .isRead(false) .build(); @@ -72,7 +72,7 @@ private List getAndReadAlarms(Pageable pageable) { Slice alarmSlice = alarmRepository.findByReceiverOrderByCreatedTimeDesc(currentMember, pageable); if (alarmSlice != null && alarmSlice.hasContent()) { for (Alarm alarm : alarmSlice) { - String message = MessageFormat.format(AlarmType.FOLLOW.getMessagePattern(), alarm.getSender().getNickname(), alarm.getSender().getHandle()); + String message = alarm.getMessage(); alarmList.add(AlarmUnitDto.from(alarm, message)); alarm.readAlarm(); } From 5fc7fc569364575ce85df637e7aa92293c027c3f Mon Sep 17 00:00:00 2001 From: Chaerin Hwang Date: Mon, 19 Aug 2024 20:43:01 +0900 Subject: [PATCH 09/10] =?UTF-8?q?fix:=20=EC=95=8C=EB=A6=BC=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sws/songpin/domain/alarm/service/AlarmService.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/sws/songpin/domain/alarm/service/AlarmService.java b/src/main/java/sws/songpin/domain/alarm/service/AlarmService.java index a41bd200..43ef57fb 100644 --- a/src/main/java/sws/songpin/domain/alarm/service/AlarmService.java +++ b/src/main/java/sws/songpin/domain/alarm/service/AlarmService.java @@ -53,7 +53,7 @@ public void createReportAlarm(Member reporter, Member reported) { Alarm alarm = Alarm.builder() .alarmType(AlarmType.REPORT) .message(message) - .sender(reported) // 이후 운영자 계정이 생기면 이 부분 수정 + .sender(reported) .receiver(reporter) .isRead(false) .build(); @@ -72,7 +72,11 @@ private List getAndReadAlarms(Pageable pageable) { Slice alarmSlice = alarmRepository.findByReceiverOrderByCreatedTimeDesc(currentMember, pageable); if (alarmSlice != null && alarmSlice.hasContent()) { for (Alarm alarm : alarmSlice) { - String message = alarm.getMessage(); + String message = switch (alarm.getAlarmType()){ + case AlarmType.FOLLOW -> MessageFormat.format(AlarmType.FOLLOW.getMessagePattern(), alarm.getSender().getNickname(), alarm.getSender().getHandle()); + case AlarmType.REPORT -> MessageFormat.format(AlarmType.REPORT.getMessagePattern(), alarm.getSender().getNickname(), alarm.getSender().getHandle()); + case DEFAULT -> MessageFormat.format(AlarmType.DEFAULT.getMessagePattern(), alarm.getSender().getNickname(), alarm.getSender().getHandle()); + }; alarmList.add(AlarmUnitDto.from(alarm, message)); alarm.readAlarm(); } From 849fce22a859f895a4e228983c3b2003b73edfeb Mon Sep 17 00:00:00 2001 From: Chaerin Hwang Date: Mon, 19 Aug 2024 20:45:46 +0900 Subject: [PATCH 10/10] =?UTF-8?q?refactor:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=84=B0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/sws/songpin/domain/alarm/service/AlarmService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/sws/songpin/domain/alarm/service/AlarmService.java b/src/main/java/sws/songpin/domain/alarm/service/AlarmService.java index 43ef57fb..1327184f 100644 --- a/src/main/java/sws/songpin/domain/alarm/service/AlarmService.java +++ b/src/main/java/sws/songpin/domain/alarm/service/AlarmService.java @@ -73,8 +73,8 @@ private List getAndReadAlarms(Pageable pageable) { if (alarmSlice != null && alarmSlice.hasContent()) { for (Alarm alarm : alarmSlice) { String message = switch (alarm.getAlarmType()){ - case AlarmType.FOLLOW -> MessageFormat.format(AlarmType.FOLLOW.getMessagePattern(), alarm.getSender().getNickname(), alarm.getSender().getHandle()); - case AlarmType.REPORT -> MessageFormat.format(AlarmType.REPORT.getMessagePattern(), alarm.getSender().getNickname(), alarm.getSender().getHandle()); + case FOLLOW -> MessageFormat.format(AlarmType.FOLLOW.getMessagePattern(), alarm.getSender().getNickname(), alarm.getSender().getHandle()); + case REPORT -> MessageFormat.format(AlarmType.REPORT.getMessagePattern(), alarm.getSender().getNickname(), alarm.getSender().getHandle()); case DEFAULT -> MessageFormat.format(AlarmType.DEFAULT.getMessagePattern(), alarm.getSender().getNickname(), alarm.getSender().getHandle()); }; alarmList.add(AlarmUnitDto.from(alarm, message));