-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: (#513) Report 도메인 코드 가독성 리팩토링 * refactor: (#513) Report 도메인 관련 테스트 코드 리팩토링 * refactor: (#513) Report의 Controller, Service를 컨벤션에 맞춰 클래스명 개선 * refactor: (#513) 전략 패턴 클래스들에 대한 테스트 코드 추가 * refactor: (#513) Transactional 어노테이션 클래스에 붙는 것으로 위치 개선 * refactor: (#513) 닉네임 3회 신고 받은 후 해당 멤버에 대한 닉네임 신고 기록 삭제 * refactor: (#513) 각 신고 전략에 관한 상수는 각 클래스에 두는 것으로 개선 * refactor: (#513) 파라미터가 2개인 메서드의 선언문 개행 되돌리기 * refactor: (#513) deleteByReportTypeAndTargetId 메서드의 테스트 코드 추가 * refactor: (#513) 파라미터 2개인 메서드 선언부 개행 삭제
- Loading branch information
Showing
21 changed files
with
1,083 additions
and
310 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
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
37 changes: 37 additions & 0 deletions
37
backend/src/main/java/com/votogether/domain/report/service/ReportCommandService.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 com.votogether.domain.report.service; | ||
|
||
import com.votogether.domain.member.entity.Member; | ||
import com.votogether.domain.report.dto.request.ReportRequest; | ||
import com.votogether.domain.report.entity.vo.ReportType; | ||
import com.votogether.domain.report.service.strategy.ReportCommentStrategy; | ||
import com.votogether.domain.report.service.strategy.ReportNicknameStrategy; | ||
import com.votogether.domain.report.service.strategy.ReportPostStrategy; | ||
import com.votogether.domain.report.service.strategy.ReportStrategy; | ||
import java.util.EnumMap; | ||
import java.util.Map; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Transactional | ||
@Service | ||
public class ReportCommandService { | ||
|
||
private final Map<ReportType, ReportStrategy> reportActions; | ||
|
||
public ReportCommandService( | ||
final ReportPostStrategy reportPostStrategy, | ||
final ReportCommentStrategy reportCommentStrategy, | ||
final ReportNicknameStrategy reportNicknameStrategy | ||
) { | ||
this.reportActions = new EnumMap<>(ReportType.class); | ||
this.reportActions.put(ReportType.POST, reportPostStrategy); | ||
this.reportActions.put(ReportType.COMMENT, reportCommentStrategy); | ||
this.reportActions.put(ReportType.NICKNAME, reportNicknameStrategy); | ||
} | ||
|
||
public void report(final Member reporter, final ReportRequest request) { | ||
final ReportStrategy reportStrategy = reportActions.get(request.type()); | ||
reportStrategy.report(reporter, request); | ||
} | ||
|
||
} |
164 changes: 0 additions & 164 deletions
164
backend/src/main/java/com/votogether/domain/report/service/ReportService.java
This file was deleted.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
...nd/src/main/java/com/votogether/domain/report/service/strategy/ReportCommentStrategy.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,55 @@ | ||
package com.votogether.domain.report.service.strategy; | ||
|
||
import com.votogether.domain.member.entity.Member; | ||
import com.votogether.domain.post.entity.comment.Comment; | ||
import com.votogether.domain.post.exception.CommentExceptionType; | ||
import com.votogether.domain.post.repository.CommentRepository; | ||
import com.votogether.domain.report.dto.request.ReportRequest; | ||
import com.votogether.domain.report.exception.ReportExceptionType; | ||
import com.votogether.domain.report.repository.ReportRepository; | ||
import com.votogether.global.exception.NotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class ReportCommentStrategy implements ReportStrategy { | ||
|
||
private static final int NUMBER_OF_COMMENT_BLIND_BASED_REPORTS = 5; | ||
|
||
private final CommentRepository commentRepository; | ||
private final ReportRepository reportRepository; | ||
|
||
@Override | ||
public void report(final Member reporter, final ReportRequest request) { | ||
final Comment reportedComment = commentRepository.findById(request.id()) | ||
.orElseThrow(() -> new NotFoundException(CommentExceptionType.COMMENT_NOT_FOUND)); | ||
validateComment(reporter, request, reportedComment); | ||
|
||
saveReport(reporter, request, reportRepository); | ||
blindComment(request, reportedComment); | ||
} | ||
|
||
private void validateComment( | ||
final Member reporter, | ||
final ReportRequest request, | ||
final Comment reportedComment | ||
) { | ||
reportedComment.validateMine(reporter); | ||
reportedComment.validateHidden(); | ||
validateDuplicatedReport( | ||
reporter, | ||
request, | ||
ReportExceptionType.DUPLICATE_COMMENT_REPORT, | ||
reportRepository | ||
); | ||
} | ||
|
||
private void blindComment(final ReportRequest request, final Comment reportedComment) { | ||
final int reportCount = reportRepository.countByReportTypeAndTargetId(request.type(), request.id()); | ||
if (reportCount >= NUMBER_OF_COMMENT_BLIND_BASED_REPORTS) { | ||
reportedComment.blind(); | ||
} | ||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
...d/src/main/java/com/votogether/domain/report/service/strategy/ReportNicknameStrategy.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,59 @@ | ||
package com.votogether.domain.report.service.strategy; | ||
|
||
import com.votogether.domain.member.entity.Member; | ||
import com.votogether.domain.member.exception.MemberExceptionType; | ||
import com.votogether.domain.member.repository.MemberRepository; | ||
import com.votogether.domain.report.dto.request.ReportRequest; | ||
import com.votogether.domain.report.entity.vo.ReportType; | ||
import com.votogether.domain.report.exception.ReportExceptionType; | ||
import com.votogether.domain.report.repository.ReportRepository; | ||
import com.votogether.global.exception.BadRequestException; | ||
import com.votogether.global.exception.NotFoundException; | ||
import java.util.Objects; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class ReportNicknameStrategy implements ReportStrategy { | ||
|
||
private static final int NUMBER_OF_NICKNAME_CHANGE_REPORTS = 3; | ||
|
||
private final MemberRepository memberRepository; | ||
private final ReportRepository reportRepository; | ||
|
||
@Override | ||
public void report(final Member reporter, final ReportRequest request) { | ||
final Member reportedMember = memberRepository.findById(request.id()) | ||
.orElseThrow(() -> new NotFoundException(MemberExceptionType.NONEXISTENT_MEMBER)); | ||
validateNickname(reporter, request); | ||
|
||
saveReport(reporter, request, reportRepository); | ||
changeNicknameByReport(reportedMember, request); | ||
} | ||
|
||
private void validateNickname(final Member reporter, final ReportRequest request) { | ||
validateMyNickname(reporter, request); | ||
validateDuplicatedReport( | ||
reporter, | ||
request, | ||
ReportExceptionType.DUPLICATE_NICKNAME_REPORT, | ||
reportRepository | ||
); | ||
} | ||
|
||
private void validateMyNickname(final Member reporter, final ReportRequest request) { | ||
if (Objects.equals(reporter.getId(), request.id())) { | ||
throw new BadRequestException(ReportExceptionType.REPORT_MY_NICKNAME); | ||
} | ||
} | ||
|
||
private void changeNicknameByReport(final Member reportedMember, final ReportRequest request) { | ||
final int reportCount = reportRepository.countByReportTypeAndTargetId(request.type(), reportedMember.getId()); | ||
if (reportCount >= NUMBER_OF_NICKNAME_CHANGE_REPORTS) { | ||
reportedMember.changeNicknameByReport(); | ||
reportRepository.deleteByReportTypeAndTargetId(ReportType.NICKNAME, request.id()); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.