Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release] v.1.0.6 (4) #292

Merged
merged 6 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,8 @@ public void updateTeamMember(TeamMember teamMember) {
public void updateTeam(Team team) {
this.team = team;
}

public String getWriterNickName() {
return teamMember.getMemberNickName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ public void init(String content, boolean isLeader){
this.content=content;
this.isLeader=isLeader;
}

public String getWriterNickName(){
return teamMember.getMemberNickName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -70,4 +74,7 @@ public void decrComNum() {
}


public String getWriterNickName(){
return member.getNickName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ public void init(String content, boolean isLeader){
this.content=content;
this.isLeader=isLeader;
}

public String getWriterNickName(){
return teamMember.getMemberNickName();
}
}
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();
}
}
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();
}
}
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);
}
}
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();
}
}
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();
}
}
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);

}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ public void deleteMember(Team team) {
this.isDeleted = true;
team.deleteTeamMember();
}

public String getMemberNickName(){
return member.getNickName();
}
}
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() {
}
}
Loading