-
Notifications
You must be signed in to change notification settings - Fork 2
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 #291 from Modagbul/MNG-20
refactor : 신고하기 기능 전략패턴 적용
- Loading branch information
Showing
15 changed files
with
210 additions
and
78 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
30 changes: 30 additions & 0 deletions
30
.../java/com/moing/backend/domain/report/application/service/BoardCommentReportStrategy.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 com.moing.backend.domain.report.application.service; | ||
|
||
import com.moing.backend.domain.boardComment.domain.entity.BoardComment; | ||
import com.moing.backend.domain.boardComment.domain.service.BoardCommentGetService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import static com.moing.backend.domain.report.presentation.constant.ReportResponseMessage.REPORT_MESSAGE; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class BoardCommentReportStrategy implements ReportStrategy { | ||
|
||
|
||
private final BoardCommentGetService boardCommentGetService; | ||
|
||
|
||
@Override | ||
public String processReport(Long targetId) { | ||
BoardComment boardComment = boardCommentGetService.getComment(targetId); | ||
boardComment.updateContent(REPORT_MESSAGE.getMessage()); | ||
return getTargetMemberNickName(boardComment); | ||
} | ||
|
||
private String getTargetMemberNickName(BoardComment boardComment){ | ||
return boardComment.getWriterNickName(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/moing/backend/domain/report/application/service/BoardReportStrategy.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,33 @@ | ||
package com.moing.backend.domain.report.application.service; | ||
|
||
import com.moing.backend.domain.board.application.dto.request.UpdateBoardRequest; | ||
import com.moing.backend.domain.board.domain.entity.Board; | ||
import com.moing.backend.domain.board.domain.service.BoardGetService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import static com.moing.backend.domain.report.presentation.constant.ReportResponseMessage.REPORT_MESSAGE; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class BoardReportStrategy implements ReportStrategy { | ||
|
||
private final BoardGetService boardGetService; | ||
|
||
@Override | ||
public String processReport(Long targetId) { | ||
Board board = boardGetService.getBoard(targetId); | ||
board.updateBoard(UpdateBoardRequest.builder() | ||
.title(REPORT_MESSAGE.getMessage()) | ||
.content(REPORT_MESSAGE.getMessage()) | ||
.isNotice(board.isNotice()) | ||
.build()); | ||
return getTargetMemberNickName(board); | ||
} | ||
|
||
private String getTargetMemberNickName(Board board){ | ||
return board.getWriterNickName(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...ava/com/moing/backend/domain/report/application/service/MissionArchiveReportStrategy.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,45 @@ | ||
package com.moing.backend.domain.report.application.service; | ||
|
||
import com.moing.backend.domain.mission.domain.entity.Mission; | ||
import com.moing.backend.domain.mission.domain.entity.constant.MissionWay; | ||
import com.moing.backend.domain.missionArchive.application.dto.req.MissionArchiveReq; | ||
import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; | ||
import com.moing.backend.domain.missionArchive.domain.entity.MissionArchiveStatus; | ||
import com.moing.backend.domain.missionArchive.domain.service.MissionArchiveQueryService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import static com.moing.backend.domain.report.presentation.constant.ReportResponseMessage.REPORT_MESSAGE; | ||
import static com.moing.backend.domain.report.presentation.constant.ReportResponseMessage.REPORT_PHOTO; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class MissionArchiveReportStrategy implements ReportStrategy { | ||
|
||
|
||
private final MissionArchiveQueryService missionArchiveQueryService; | ||
|
||
|
||
@Override | ||
public String processReport(Long targetId) { | ||
MissionArchive missionArchive = missionArchiveQueryService.findByMissionArchiveId(targetId); | ||
|
||
if (isCompletedPhotoArchive(missionArchive)) { | ||
missionArchive.updateArchive(REPORT_PHOTO.getMessage()); | ||
} else { | ||
missionArchive.updateArchive(REPORT_MESSAGE.getMessage()); | ||
} | ||
|
||
return getTargetMemberNickName(missionArchive); | ||
} | ||
|
||
private String getTargetMemberNickName(MissionArchive missionArchive){ | ||
return missionArchive.getWriterNickName(); | ||
} | ||
|
||
private Boolean isCompletedPhotoArchive (MissionArchive archive) { | ||
return archive.getMission().getWay().equals(MissionWay.PHOTO) && archive.getStatus().equals(MissionArchiveStatus.COMPLETE); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...ava/com/moing/backend/domain/report/application/service/MissionCommentReportStrategy.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 com.moing.backend.domain.report.application.service; | ||
|
||
import com.moing.backend.domain.missionComment.domain.entity.MissionComment; | ||
import com.moing.backend.domain.missionComment.domain.service.MissionCommentGetService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import static com.moing.backend.domain.report.presentation.constant.ReportResponseMessage.REPORT_MESSAGE; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class MissionCommentReportStrategy implements ReportStrategy { | ||
|
||
|
||
private final MissionCommentGetService missionCommentGetService; | ||
|
||
|
||
@Override | ||
public String processReport(Long targetId) { | ||
MissionComment missionComment=missionCommentGetService.getComment(targetId); | ||
missionComment.updateContent(REPORT_MESSAGE.getMessage()); | ||
|
||
return getTargetMemberNickName(missionComment); | ||
} | ||
|
||
private String getTargetMemberNickName(MissionComment missionComment){ | ||
return missionComment.getWriterNickName(); | ||
} | ||
} |
79 changes: 7 additions & 72 deletions
79
src/main/java/com/moing/backend/domain/report/application/service/ReportCreateUseCase.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 |
---|---|---|
@@ -1,95 +1,30 @@ | ||
package com.moing.backend.domain.report.application.service; | ||
|
||
import com.moing.backend.domain.board.application.dto.request.UpdateBoardRequest; | ||
import com.moing.backend.domain.board.domain.entity.Board; | ||
import com.moing.backend.domain.board.domain.service.BoardGetService; | ||
import com.moing.backend.domain.boardComment.domain.entity.BoardComment; | ||
import com.moing.backend.domain.boardComment.domain.service.BoardCommentGetService; | ||
import com.moing.backend.domain.member.domain.service.MemberGetService; | ||
import com.moing.backend.domain.mission.domain.entity.Mission; | ||
import com.moing.backend.domain.mission.domain.entity.constant.MissionWay; | ||
import com.moing.backend.domain.missionArchive.application.dto.req.MissionArchiveReq; | ||
import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; | ||
import com.moing.backend.domain.missionArchive.domain.entity.MissionArchiveStatus; | ||
import com.moing.backend.domain.missionArchive.domain.service.MissionArchiveQueryService; | ||
import com.moing.backend.domain.missionComment.domain.entity.MissionComment; | ||
import com.moing.backend.domain.missionComment.domain.service.MissionCommentGetService; | ||
import com.moing.backend.domain.report.application.mapper.ReportMapper; | ||
import com.moing.backend.domain.report.domain.entity.Report; | ||
import com.moing.backend.domain.report.domain.entity.constant.ReportType; | ||
import com.moing.backend.domain.report.domain.service.ReportSaveService; | ||
import com.moing.backend.domain.report.presentation.constant.StrategyCategory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.Map; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class ReportCreateUseCase { | ||
|
||
private final ReportSaveService reportSaveService; | ||
private final Map<String, ReportStrategy> strategyMap; | ||
private final MemberGetService memberGetService; | ||
|
||
private final BoardGetService boardGetService; | ||
private final MissionArchiveQueryService missionArchiveQueryService; | ||
private final BoardCommentGetService boardCommentGetService; | ||
private final MissionCommentGetService missionCommentGetService; | ||
|
||
private final String REPORT_BOARD_TITLE ="신고 접수된 게시물입니다."; | ||
private final String REPORT_BOARD_MESSAGE ="신고 접수로 삭제된 게시물입니다."; | ||
private final String REPORT_MISSION_MESSAGE ="신고 접수로 삭제된 인증입니다."; | ||
private final String REPORT_MISSION_PHOTO ="https://modagbul.s3.ap-northeast-2.amazonaws.com/reportImage.png"; | ||
|
||
|
||
public Long createReport(String socialId, Long targetId, String reportType) { | ||
ReportStrategy strategy = strategyMap.get(StrategyCategory.valueOf(reportType).getStrategyName()); | ||
Long memberId = memberGetService.getMemberBySocialId(socialId).getMemberId(); | ||
String targetMemberNickName = null ; | ||
|
||
if (reportType.equals(ReportType.BOARD.name())) { | ||
Board board = boardGetService.getBoard(targetId); | ||
|
||
targetMemberNickName = board.getTeamMember().getMember().getNickName(); | ||
|
||
board.updateBoard(UpdateBoardRequest.builder() | ||
.title(REPORT_BOARD_TITLE) | ||
.content(REPORT_BOARD_MESSAGE) | ||
.isNotice(board.isNotice()) | ||
.build()); | ||
} | ||
else if (reportType.equals(ReportType.BCOMMENT.name())) { | ||
BoardComment boardComment = boardCommentGetService.getComment(targetId); | ||
targetMemberNickName = boardComment.getTeamMember().getMember().getNickName(); | ||
boardComment.updateContent(REPORT_BOARD_MESSAGE); | ||
|
||
} else if(reportType.equals(ReportType.MCOMMENT.name())){ | ||
MissionComment missionComment=missionCommentGetService.getComment(targetId); | ||
targetMemberNickName=missionComment.getTeamMember().getMember().getNickName(); | ||
missionComment.updateContent(REPORT_BOARD_MESSAGE); | ||
} | ||
else { | ||
|
||
MissionArchive missionArchive = missionArchiveQueryService.findByMissionArchiveId(targetId); | ||
Mission mission = missionArchive.getMission(); | ||
|
||
targetMemberNickName = missionArchive.getMember().getNickName(); | ||
|
||
if (mission.getWay().equals(MissionWay.PHOTO) && missionArchive.getStatus().equals(MissionArchiveStatus.COMPLETE)) { | ||
missionArchive.updateArchive(MissionArchiveReq.builder() | ||
.archive(REPORT_MISSION_PHOTO) | ||
.status(missionArchive.getStatus().name()) | ||
.build()); | ||
} else { | ||
missionArchive.updateArchive(MissionArchiveReq.builder() | ||
.archive(REPORT_MISSION_MESSAGE) | ||
.status(missionArchive.getStatus().name()) | ||
.build()); | ||
|
||
} | ||
|
||
} | ||
|
||
Report save = reportSaveService.save(ReportMapper.mapToReport(memberId, targetId, reportType,targetMemberNickName)); | ||
|
||
String targetMemberNickName= strategy.processReport(targetId); | ||
Report save = reportSaveService.save(ReportMapper.mapToReport(memberId, targetId, reportType, targetMemberNickName)); | ||
return save.getTargetId(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/moing/backend/domain/report/application/service/ReportStrategy.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,6 @@ | ||
package com.moing.backend.domain.report.application.service; | ||
|
||
public interface ReportStrategy { | ||
String processReport(Long targetId); | ||
|
||
} |
9 changes: 4 additions & 5 deletions
9
src/main/java/com/moing/backend/domain/report/presentation/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
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
16 changes: 16 additions & 0 deletions
16
src/main/java/com/moing/backend/domain/report/presentation/constant/StrategyCategory.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,16 @@ | ||
package com.moing.backend.domain.report.presentation.constant; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum StrategyCategory { | ||
|
||
BCOMMENT("boardCommentReportStrategy"), | ||
BOARD("boardReportStrategy"), | ||
MISSION("missionArchiveReportStrategy"), | ||
MCOMMENT("missionCommentReportStrategy"); | ||
|
||
private final String strategyName; | ||
} |
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
12 changes: 12 additions & 0 deletions
12
src/test/java/com/moing/backend/domain/team/application/service/CreateTeamUseCaseTest.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,12 @@ | ||
package com.moing.backend.domain.team.application.service; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class CreateTeamUseCaseTest { | ||
|
||
@Test | ||
void createTeam() { | ||
} | ||
} |