diff --git a/src/main/java/com/moing/backend/domain/board/domain/entity/Board.java b/src/main/java/com/moing/backend/domain/board/domain/entity/Board.java index 7b6691ec..dc2b5899 100644 --- a/src/main/java/com/moing/backend/domain/board/domain/entity/Board.java +++ b/src/main/java/com/moing/backend/domain/board/domain/entity/Board.java @@ -79,4 +79,8 @@ public void updateTeamMember(TeamMember teamMember) { public void updateTeam(Team team) { this.team = team; } + + public String getWriterNickName() { + return teamMember.getMemberNickName(); + } } diff --git a/src/main/java/com/moing/backend/domain/boardComment/domain/entity/BoardComment.java b/src/main/java/com/moing/backend/domain/boardComment/domain/entity/BoardComment.java index 6a4092d4..6b39e57e 100644 --- a/src/main/java/com/moing/backend/domain/boardComment/domain/entity/BoardComment.java +++ b/src/main/java/com/moing/backend/domain/boardComment/domain/entity/BoardComment.java @@ -46,4 +46,8 @@ public void init(String content, boolean isLeader){ this.content=content; this.isLeader=isLeader; } + + public String getWriterNickName(){ + return teamMember.getMemberNickName(); + } } diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/entity/MissionArchive.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/entity/MissionArchive.java index 2a60411f..558a6089 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/entity/MissionArchive.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/entity/MissionArchive.java @@ -57,6 +57,10 @@ public void updateArchive(MissionArchiveReq missionArchiveReq) { this.status = MissionArchiveStatus.valueOf(missionArchiveReq.getStatus()); } + public void updateArchive(String archive) { + this.archive = archive; + } + public void updateCount(Long count) { this.count = count; } @@ -70,4 +74,7 @@ public void decrComNum() { } + public String getWriterNickName(){ + return member.getNickName(); + } } diff --git a/src/main/java/com/moing/backend/domain/missionComment/domain/entity/MissionComment.java b/src/main/java/com/moing/backend/domain/missionComment/domain/entity/MissionComment.java index a3941527..2cc87f50 100644 --- a/src/main/java/com/moing/backend/domain/missionComment/domain/entity/MissionComment.java +++ b/src/main/java/com/moing/backend/domain/missionComment/domain/entity/MissionComment.java @@ -45,4 +45,8 @@ public void init(String content, boolean isLeader){ this.content=content; this.isLeader=isLeader; } + + public String getWriterNickName(){ + return teamMember.getMemberNickName(); + } } diff --git a/src/main/java/com/moing/backend/domain/report/application/service/BoardCommentReportStrategy.java b/src/main/java/com/moing/backend/domain/report/application/service/BoardCommentReportStrategy.java new file mode 100644 index 00000000..d3be8ffa --- /dev/null +++ b/src/main/java/com/moing/backend/domain/report/application/service/BoardCommentReportStrategy.java @@ -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(); + } +} diff --git a/src/main/java/com/moing/backend/domain/report/application/service/BoardReportStrategy.java b/src/main/java/com/moing/backend/domain/report/application/service/BoardReportStrategy.java new file mode 100644 index 00000000..a5cf41c1 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/report/application/service/BoardReportStrategy.java @@ -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(); + } +} \ No newline at end of file diff --git a/src/main/java/com/moing/backend/domain/report/application/service/MissionArchiveReportStrategy.java b/src/main/java/com/moing/backend/domain/report/application/service/MissionArchiveReportStrategy.java new file mode 100644 index 00000000..c2485915 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/report/application/service/MissionArchiveReportStrategy.java @@ -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); + } +} diff --git a/src/main/java/com/moing/backend/domain/report/application/service/MissionCommentReportStrategy.java b/src/main/java/com/moing/backend/domain/report/application/service/MissionCommentReportStrategy.java new file mode 100644 index 00000000..b9eab647 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/report/application/service/MissionCommentReportStrategy.java @@ -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(); + } +} diff --git a/src/main/java/com/moing/backend/domain/report/application/service/ReportCreateUseCase.java b/src/main/java/com/moing/backend/domain/report/application/service/ReportCreateUseCase.java index 5c6fa313..e3805608 100644 --- a/src/main/java/com/moing/backend/domain/report/application/service/ReportCreateUseCase.java +++ b/src/main/java/com/moing/backend/domain/report/application/service/ReportCreateUseCase.java @@ -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 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(); } } diff --git a/src/main/java/com/moing/backend/domain/report/application/service/ReportStrategy.java b/src/main/java/com/moing/backend/domain/report/application/service/ReportStrategy.java new file mode 100644 index 00000000..45f1f2d3 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/report/application/service/ReportStrategy.java @@ -0,0 +1,6 @@ +package com.moing.backend.domain.report.application.service; + +public interface ReportStrategy { + String processReport(Long targetId); + +} \ No newline at end of file diff --git a/src/main/java/com/moing/backend/domain/report/presentation/ReportController.java b/src/main/java/com/moing/backend/domain/report/presentation/ReportController.java index b0332b5e..5489aedb 100644 --- a/src/main/java/com/moing/backend/domain/report/presentation/ReportController.java +++ b/src/main/java/com/moing/backend/domain/report/presentation/ReportController.java @@ -1,17 +1,16 @@ package com.moing.backend.domain.report.presentation; -import com.moing.backend.domain.missionArchive.application.dto.req.MissionArchiveReq; -import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveRes; import com.moing.backend.domain.report.application.service.ReportCreateUseCase; -import com.moing.backend.domain.report.domain.entity.Report; import com.moing.backend.global.config.security.dto.User; import com.moing.backend.global.response.SuccessResponse; import lombok.AllArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; -import static com.moing.backend.domain.missionArchive.domain.constant.MissionArchiveResponseMessage.CREATE_ARCHIVE_SUCCESS; import static com.moing.backend.domain.report.presentation.constant.ReportResponseMessage.CREATE_REPORT_SUCCESS; @RestController diff --git a/src/main/java/com/moing/backend/domain/report/presentation/constant/ReportResponseMessage.java b/src/main/java/com/moing/backend/domain/report/presentation/constant/ReportResponseMessage.java index 60f5aa47..e5d9133a 100644 --- a/src/main/java/com/moing/backend/domain/report/presentation/constant/ReportResponseMessage.java +++ b/src/main/java/com/moing/backend/domain/report/presentation/constant/ReportResponseMessage.java @@ -7,7 +7,9 @@ @RequiredArgsConstructor public enum ReportResponseMessage { - CREATE_REPORT_SUCCESS("게시글 신고를 완료 했습니다."); + CREATE_REPORT_SUCCESS("게시글 신고를 완료 했습니다."), + REPORT_MESSAGE("신고 접수로 삭제되었습니다."), + REPORT_PHOTO("https://modagbul.s3.ap-northeast-2.amazonaws.com/reportImage.png"); private final String message; diff --git a/src/main/java/com/moing/backend/domain/report/presentation/constant/StrategyCategory.java b/src/main/java/com/moing/backend/domain/report/presentation/constant/StrategyCategory.java new file mode 100644 index 00000000..b2acdf43 --- /dev/null +++ b/src/main/java/com/moing/backend/domain/report/presentation/constant/StrategyCategory.java @@ -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; +} diff --git a/src/main/java/com/moing/backend/domain/teamMember/domain/entity/TeamMember.java b/src/main/java/com/moing/backend/domain/teamMember/domain/entity/TeamMember.java index 9d7aa88e..d2ef4648 100644 --- a/src/main/java/com/moing/backend/domain/teamMember/domain/entity/TeamMember.java +++ b/src/main/java/com/moing/backend/domain/teamMember/domain/entity/TeamMember.java @@ -48,4 +48,8 @@ public void deleteMember(Team team) { this.isDeleted = true; team.deleteTeamMember(); } + + public String getMemberNickName(){ + return member.getNickName(); + } } diff --git a/src/test/java/com/moing/backend/domain/team/application/service/CreateTeamUseCaseTest.java b/src/test/java/com/moing/backend/domain/team/application/service/CreateTeamUseCaseTest.java new file mode 100644 index 00000000..e38801c2 --- /dev/null +++ b/src/test/java/com/moing/backend/domain/team/application/service/CreateTeamUseCaseTest.java @@ -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() { + } +} \ No newline at end of file