Skip to content

Commit df98a98

Browse files
authored
Merge pull request #151 from Me1tingPot/feature/#145
[Feature] ์‹ ๊ณ ๋กœ์ง ์ž‘์„ฑ
2 parents 528220c + dee34d7 commit df98a98

File tree

16 files changed

+237
-73
lines changed

16 files changed

+237
-73
lines changed

โ€Žsrc/main/java/meltingpot/server/auth/service/MailService.javaโ€Ž

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import lombok.RequiredArgsConstructor;
44
import meltingpot.server.auth.controller.dto.MailVerificationRequestDto;
55
import meltingpot.server.auth.controller.dto.VerificationCodeRequestDto;
6+
import meltingpot.server.domain.entity.Account;
7+
import meltingpot.server.domain.entity.UserReportCount;
68
import meltingpot.server.util.Constants;
79
import meltingpot.server.domain.entity.MailVerification;
810
import meltingpot.server.domain.repository.AccountRepository;
@@ -118,4 +120,21 @@ public void checkUserName(String username) {
118120
}
119121
}
120122

123+
@Transactional
124+
public ResponseCode sendReportAlertEmail(Account account, int reportCount) {
125+
String title = "๋ˆ„์  ์‹ ๊ณ  5ํšŒ ์ด์ƒ ์•Œ๋ฆผ";
126+
String to = "[email protected]";
127+
String templateName = "ReportAlertTemplate.html";
128+
129+
Map<String, String> mailValues = Map.of(
130+
"username", account.getName(),
131+
"userEmail",account.getUsername(),
132+
"userId", account.getId().toString(),
133+
"reportCount", String.valueOf(reportCount)
134+
);
135+
136+
mailUtil.sendMimeMessageMailWithValues(title, to, templateName, mailValues);
137+
return ResponseCode.MAIL_REPORT_ALRERT_SEND_SUCCESS;
138+
}
139+
121140
}

โ€Žsrc/main/java/meltingpot/server/domain/entity/Account.javaโ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public class Account extends BaseEntity {
8282
@OneToMany(mappedBy = "account")
8383
private List<AccountRole> accountRoles = new ArrayList<>();
8484

85+
@OneToOne(mappedBy = "account", cascade = CascadeType.ALL)
86+
private UserReportCount userReportCount;
87+
8588
public List<String> toAuthStringList() {
8689
return accountRoles.stream().map(a -> a.getRole().getAuthority())
8790
.collect(Collectors.toList());

โ€Žsrc/main/java/meltingpot/server/domain/entity/Report.javaโ€Ž

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import jakarta.persistence.*;
44
import lombok.*;
5+
import meltingpot.server.domain.entity.comment.Comment;
56
import meltingpot.server.domain.entity.common.BaseEntity;
67
import meltingpot.server.domain.entity.post.Post;
78

@@ -16,13 +17,20 @@ public class Report extends BaseEntity {
1617
@Column(name = "report_id")
1718
private Long id;
1819

20+
@Column(length = 1500)
1921
private String content;
2022

2123
@ManyToOne(fetch = FetchType.LAZY)
2224
@JoinColumn(name = "post_id")
2325
private Post post;
2426

27+
@ManyToOne(fetch = FetchType.LAZY)
28+
@JoinColumn(name = "comment_id")
29+
private Comment comment;
30+
2531
@ManyToOne(fetch = FetchType.LAZY)
2632
@JoinColumn(name = "user_id")
2733
private Account account;
34+
35+
2836
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package meltingpot.server.domain.entity;
2+
3+
import jakarta.persistence.*;
4+
import lombok.*;
5+
6+
@Entity
7+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
8+
@AllArgsConstructor(access = AccessLevel.PROTECTED)
9+
@Builder
10+
@Getter
11+
@Setter
12+
public class UserReportCount {
13+
@Id
14+
@GeneratedValue(strategy = GenerationType.IDENTITY)
15+
@Column(name = "user_report_count_id")
16+
private Long id;
17+
18+
@Column(name = "report_count")
19+
private int reportCount;
20+
21+
@OneToOne(fetch = FetchType.LAZY)
22+
@JoinColumn(name = "account_id")
23+
private Account account;
24+
25+
public void incrementReportCount() {
26+
this.reportCount++;
27+
}
28+
29+
public UserReportCount(Account account, int reportCount) {
30+
this.account = account;
31+
this.reportCount = reportCount;
32+
}
33+
}

โ€Žsrc/main/java/meltingpot/server/domain/entity/comment/Comment.javaโ€Ž

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ public class Comment extends BaseEntity {
2121
@Column(name = "comment_id")
2222
private Long id;
2323

24-
@Size(min = 10, max = 500)
24+
@Column(length = 1500)
2525
private String content;
2626

2727
@Column(name = "is_anonymous")
2828
private boolean isAnonymous = false;
2929

30+
@Column(name = "report_count",nullable = false)
31+
private int reportCount;
32+
3033
@ManyToOne(fetch = FetchType.LAZY)
3134
@JoinColumn(name = "post_id")
3235
private Post post;
@@ -104,4 +107,8 @@ public void setParent(Comment parent) {
104107
public void setChildren(List<Comment> children) {
105108
this.children = children;
106109
}
110+
111+
public void incrementReportCount() {
112+
this.reportCount++;
113+
}
107114
}

โ€Žsrc/main/java/meltingpot/server/domain/entity/post/Post.javaโ€Ž

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,22 @@ public class Post extends BaseEntity {
2929
@Column(name = "post_id")
3030
private Long id;
3131

32-
@Size(min = 10, max = 500)
32+
@Column(length = 500)
33+
@Size(max = 500, message = "์ œ๋ชฉ์€ ํ•œ๊ธ€ ๊ธฐ์ค€ 500์ž ์ด๋‚ด๋กœ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.")
3334
private String title;
3435

35-
@Size(min = 10, max = 500)
36+
@Column(length = 500)
37+
@Size(max = 500, message = "๋‚ด์šฉ์€ ํ•œ๊ธ€ ๊ธฐ์ค€ 500์ž ์ด๋‚ด๋กœ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.")
3638
private String content;
3739

3840
@Enumerated(EnumType.STRING)
3941
private PostType postType;
4042

4143
private Boolean isDraft;
4244

45+
@Column(name = "report_count",nullable = false)
46+
private int reportCount;
47+
4348
@ManyToOne(fetch = FetchType.LAZY)
4449
@JoinColumn(name = "user_id")
4550
private Account account;
@@ -69,4 +74,8 @@ public void setPostImages(List<PostImage> postImages) {
6974
public void setIsDraft(boolean isDraft) {
7075
this.isDraft = isDraft;
7176
}
77+
78+
public void incrementReportCount() {
79+
this.reportCount++;
80+
}
7281
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package meltingpot.server.domain.repository;
2+
3+
import meltingpot.server.domain.entity.UserReportCount;
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
6+
public interface UserReportCountRepository extends JpaRepository<UserReportCount, Long> {
7+
}

โ€Žsrc/main/java/meltingpot/server/post/dto/PostDetailResponse.javaโ€Ž

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package meltingpot.server.post.dto;
22

33
import lombok.*;
4+
import meltingpot.server.domain.entity.enums.PostType;
45
import meltingpot.server.domain.entity.post.Post;
56
import java.time.LocalDateTime;
67
import java.util.List;
@@ -13,14 +14,14 @@
1314
public class PostDetailResponse {
1415
private Long postId;
1516
private Long userId;
17+
private PostType postType;
1618
private String name;
1719
private String title;
1820
private String content;
19-
private List<ImageData> imgData; // Image data including ID and URL
21+
private List<ImageData> imgData;
2022
private Integer commentCount;
2123
private LocalDateTime updatedAt;
2224

23-
// Static nested class to hold image data
2425
@Getter
2526
@AllArgsConstructor
2627
@NoArgsConstructor
@@ -41,6 +42,7 @@ public static PostDetailResponse of(Post post) {
4142
return PostDetailResponse.builder()
4243
.postId(post.getId())
4344
.userId(post.getAccount().getId())
45+
.postType(post.getPostType())
4446
.name(post.getAccount().getName())
4547
.title(post.getTitle())
4648
.content(post.getContent())

โ€Žsrc/main/java/meltingpot/server/report/controller/ReportController.javaโ€Ž

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import io.swagger.v3.oas.annotations.Operation;
44
import lombok.RequiredArgsConstructor;
55
import meltingpot.server.domain.entity.Account;
6-
import meltingpot.server.report.dto.ReportRequestDTO;
6+
import meltingpot.server.report.dto.ReportRequest;
77
import meltingpot.server.report.service.ReportService;
88
import meltingpot.server.util.*;
99
import org.springframework.http.ResponseEntity;
@@ -17,11 +17,22 @@
1717
public class ReportController {
1818
private final ReportService reportService;
1919

20-
@Operation(summary = "์‹ ๊ณ  ์ž‘์„ฑ")
20+
@Operation(summary = "๊ฒŒ์‹œ๊ธ€ ์‹ ๊ณ  ์ž‘์„ฑ")
2121
@PostMapping("/{postId}")
22-
public ResponseEntity<ResponseData> createPost(@CurrentUser Account account, @RequestBody ReportRequestDTO.CreateReportDTO createReportDTO, @PathVariable Long postId) {
22+
public ResponseEntity<ResponseData> createPostReport (@CurrentUser Account account, @RequestBody ReportRequest reportRequest, @PathVariable Long postId) {
2323
try{
24-
reportService.createReport(createReportDTO, account, postId);
24+
reportService.createReport(reportRequest, account, postId,null);
25+
return ResponseData.toResponseEntity (ResponseCode.REPORT_CREATE_SUCCESS);
26+
}catch (NoSuchElementException e) {
27+
return ResponseData.toResponseEntity( ResponseCode.REPORT_CREATE_FAIL);
28+
}
29+
}
30+
31+
@Operation(summary = "๋Œ“๊ธ€ ์‹ ๊ณ  ์ž‘์„ฑ")
32+
@PostMapping("/{commentId}")
33+
public ResponseEntity<ResponseData> createCommentReport(@CurrentUser Account account, @RequestBody ReportRequest reportRequest, @PathVariable Long commentId) {
34+
try{
35+
reportService.createReport(reportRequest, account, null ,commentId);
2536
return ResponseData.toResponseEntity (ResponseCode.REPORT_CREATE_SUCCESS);
2637
}catch (NoSuchElementException e) {
2738
return ResponseData.toResponseEntity( ResponseCode.REPORT_CREATE_FAIL);

โ€Žsrc/main/java/meltingpot/server/report/converter/ReportConverter.javaโ€Ž

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
ย (0)