-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from BokDoong/feat/report
feat: "신고 api완료"
- Loading branch information
Showing
13 changed files
with
268 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/java/hanium/englishfairytale/report/controller/ReportController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package hanium.englishfairytale.report.controller; | ||
|
||
import hanium.englishfairytale.report.dto.PostReportQueryDto; | ||
import hanium.englishfairytale.report.dto.UserReportQueryDto; | ||
import hanium.englishfairytale.report.service.PostReportService; | ||
import hanium.englishfairytale.report.service.UserReportService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestPart; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/community/report") | ||
@RequiredArgsConstructor | ||
public class ReportController { | ||
private final PostReportService postReportService; | ||
private final UserReportService userReportService; | ||
|
||
@PostMapping("post") | ||
public void postReport(@Validated @RequestPart PostReportQueryDto postReportQueryDto) { | ||
postReportService.report(postReportQueryDto); | ||
} | ||
@PostMapping("user") | ||
public void userReport(@Validated @RequestPart UserReportQueryDto userReportQueryDto){ | ||
userReportService.report(userReportQueryDto); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/hanium/englishfairytale/report/dto/PostReportQueryDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package hanium.englishfairytale.report.dto; | ||
|
||
import lombok.Data; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
@Data | ||
public class PostReportQueryDto { | ||
@NotNull | ||
private Long taleId; | ||
@NotNull | ||
private Long memberId; | ||
|
||
public PostReportQueryDto(Long taleId, Long memberId) { | ||
this.taleId = taleId; | ||
this.memberId = memberId; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/hanium/englishfairytale/report/dto/UserReportQueryDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package hanium.englishfairytale.report.dto; | ||
|
||
import lombok.Data; | ||
|
||
import javax.validation.constraints.NotNull; | ||
@Data | ||
public class UserReportQueryDto { | ||
@NotNull | ||
private Long reportedId; | ||
@NotNull | ||
private Long reporterId; | ||
|
||
public UserReportQueryDto(Long reportedId, Long reporterId) { | ||
this.reportedId = reportedId; | ||
this.reporterId = reporterId; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/hanium/englishfairytale/report/entity/PostReport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package hanium.englishfairytale.report.entity; | ||
|
||
import hanium.englishfairytale.member.domain.Member; | ||
import hanium.englishfairytale.tale.domain.Tale; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
import java.time.LocalDateTime; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
public class PostReport { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "id") | ||
private Long id; | ||
@ManyToOne(cascade = CascadeType.MERGE) | ||
@JoinColumn(name = "tale_id") | ||
private Tale tale; | ||
@OneToOne(cascade = CascadeType.MERGE) | ||
@JoinColumn(name = "reporter_id") | ||
private Member member; | ||
@Column(name = "created_date") | ||
private LocalDateTime createdTime; | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/hanium/englishfairytale/report/entity/UserReport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package hanium.englishfairytale.report.entity; | ||
|
||
import hanium.englishfairytale.member.domain.Member; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import javax.persistence.*; | ||
import java.time.LocalDateTime; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Builder | ||
public class UserReport { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "id") | ||
private Long id; | ||
@ManyToOne(cascade = CascadeType.MERGE) | ||
@JoinColumn(name = "reported_id") | ||
private Member reported; | ||
@OneToOne(cascade = CascadeType.MERGE) | ||
@JoinColumn(name = "reporter_id") | ||
private Member reporter; | ||
@Column(name = "created_date") | ||
private LocalDateTime createdTime; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/hanium/englishfairytale/report/repository/PostReportRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package hanium.englishfairytale.report.repository; | ||
|
||
import hanium.englishfairytale.member.domain.Member; | ||
import hanium.englishfairytale.report.entity.PostReport; | ||
import hanium.englishfairytale.tale.domain.Tale; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.Optional; | ||
|
||
public interface PostReportRepository extends JpaRepository<PostReport, Long> { | ||
// public Long save(PostReport postReport); | ||
Optional<PostReport> findByMemberAndTale(Member member, Tale tale); | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/hanium/englishfairytale/report/repository/UserReportRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package hanium.englishfairytale.report.repository; | ||
|
||
import hanium.englishfairytale.report.entity.UserReport; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface UserReportRepository extends JpaRepository<UserReport, Long> { | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/hanium/englishfairytale/report/service/PostReportService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package hanium.englishfairytale.report.service; | ||
|
||
import hanium.englishfairytale.member.domain.Member; | ||
import hanium.englishfairytale.report.dto.PostReportQueryDto; | ||
import hanium.englishfairytale.tale.domain.Tale; | ||
|
||
public interface PostReportService { | ||
void report(PostReportQueryDto postReportQueryDto); | ||
void createPostReport(Member member, Tale tale); | ||
Member verifyAndGetMember(Long member_id); | ||
Tale verifyAndGetTale(Long tale_id); | ||
void verifyExistedMember(Member member, Tale tale); | ||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/hanium/englishfairytale/report/service/PostReportServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package hanium.englishfairytale.report.service; | ||
|
||
import hanium.englishfairytale.exception.BusinessException; | ||
import hanium.englishfairytale.exception.NotFoundException; | ||
import hanium.englishfairytale.exception.code.ErrorCode; | ||
import hanium.englishfairytale.member.domain.Member; | ||
import hanium.englishfairytale.member.domain.MemberRepository; | ||
import hanium.englishfairytale.report.dto.PostReportQueryDto; | ||
import hanium.englishfairytale.report.entity.PostReport; | ||
import hanium.englishfairytale.report.repository.PostReportRepository; | ||
import hanium.englishfairytale.tale.domain.Tale; | ||
import hanium.englishfairytale.tale.domain.TaleRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class PostReportServiceImpl implements PostReportService{ | ||
private final PostReportRepository postReportRepository; | ||
private final MemberRepository memberRepository; | ||
private final TaleRepository taleRepository; | ||
|
||
|
||
@Override | ||
@Transactional | ||
public void report(PostReportQueryDto postReportQueryDto){ // 더 해야할 것 자기자신 신고 예외 처리, 포스트 되지 않은 게시물 예외처리 | ||
Member member = verifyAndGetMember(postReportQueryDto.getMemberId()); | ||
Tale tale = verifyAndGetTale(postReportQueryDto.getTaleId()); | ||
verifyExistedMember(member, tale); | ||
createPostReport(member, tale); | ||
} | ||
@Override | ||
@Transactional | ||
public void createPostReport(Member member, Tale tale) { | ||
PostReport postReport = PostReport.builder() | ||
.id(1L) | ||
.member(member) | ||
.tale(tale) | ||
.build(); | ||
postReportRepository.save(postReport); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public Member verifyAndGetMember(Long member_id) { | ||
return memberRepository.findMemberById(member_id).orElseThrow(() -> new NotFoundException(ErrorCode.MEMBER_NOT_FOUND)); | ||
} | ||
@Override | ||
@Transactional | ||
public Tale verifyAndGetTale(Long tale_id) { | ||
return taleRepository.findTaleByTaleId(tale_id).orElseThrow(() -> new NotFoundException(ErrorCode.TALE_NOT_FOUND)); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public void verifyExistedMember(Member member, Tale tale) { | ||
if ( postReportRepository.findByMemberAndTale(member, tale).isPresent()) { | ||
throw new BusinessException(ErrorCode.EXISTED_REPORT); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/hanium/englishfairytale/report/service/UserReportService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package hanium.englishfairytale.report.service; | ||
|
||
import hanium.englishfairytale.member.domain.Member; | ||
import hanium.englishfairytale.report.dto.UserReportQueryDto; | ||
|
||
public interface UserReportService { | ||
void report(UserReportQueryDto userReportQueryDto); | ||
Member getMember(Long member_id); | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/hanium/englishfairytale/report/service/UserReportServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package hanium.englishfairytale.report.service; | ||
|
||
import hanium.englishfairytale.exception.NotFoundException; | ||
import hanium.englishfairytale.exception.code.ErrorCode; | ||
import hanium.englishfairytale.member.domain.Member; | ||
import hanium.englishfairytale.member.domain.MemberRepository; | ||
import hanium.englishfairytale.report.dto.UserReportQueryDto; | ||
import hanium.englishfairytale.report.entity.UserReport; | ||
import hanium.englishfairytale.report.repository.UserReportRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UserReportServiceImpl implements UserReportService { | ||
private final UserReportRepository userReportRepository; | ||
private final MemberRepository memberRepository; | ||
|
||
@Override | ||
@Transactional | ||
public void report(UserReportQueryDto userReportQueryDto) { | ||
Member reporterUser = getMember(userReportQueryDto.getReporterId()); | ||
Member reportedUser = getMember(userReportQueryDto.getReportedId()); | ||
|
||
UserReport userReport = UserReport.builder() | ||
.reported(reportedUser) | ||
.reporter(reporterUser) | ||
.build(); | ||
userReportRepository.save(userReport); | ||
} | ||
@Override | ||
@Transactional | ||
public Member getMember(Long member_id) { | ||
return memberRepository.findMemberById(member_id).orElseThrow(() -> new NotFoundException(ErrorCode.MEMBER_NOT_FOUND)); | ||
} | ||
} |