From cdfde7827934c9ce9482690d2f236d83821415e2 Mon Sep 17 00:00:00 2001 From: Hellin22 Date: Thu, 14 Nov 2024 10:21:52 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20/=20=EC=88=98=EC=A0=95:=20=EB=B8=94=EB=9E=99?= =?UTF-8?q?=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EB=93=B1=EB=A1=9D=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/BlacklistController.java | 34 +++++++++------ .../blacklist/mapper/BlacklistMapper.java | 12 ++++++ .../blacklist/service/BlacklistService.java | 41 ++++++++++++++----- 3 files changed, 65 insertions(+), 22 deletions(-) diff --git a/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/controller/BlacklistController.java b/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/controller/BlacklistController.java index 81cba776..83175a4f 100644 --- a/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/controller/BlacklistController.java +++ b/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/controller/BlacklistController.java @@ -2,6 +2,7 @@ import intbyte4.learnsmate.blacklist.domain.dto.BlacklistDTO; import intbyte4.learnsmate.blacklist.domain.dto.BlacklistReportCommentDTO; +import intbyte4.learnsmate.blacklist.domain.vo.request.RequestSaveBlacklistVO; import intbyte4.learnsmate.blacklist.domain.vo.response.ResponseFindBlacklistVO; import intbyte4.learnsmate.blacklist.domain.vo.response.ResponseFindReservedBlacklistOneVO; import intbyte4.learnsmate.blacklist.domain.vo.response.ResponseFindReservedStudentBlacklistVO; @@ -11,30 +12,23 @@ import intbyte4.learnsmate.member.domain.MemberType; import intbyte4.learnsmate.report.domain.dto.ReportedMemberDTO; import io.swagger.v3.oas.annotations.Operation; +import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.ArrayList; import java.util.List; @RestController +@RequiredArgsConstructor @RequestMapping("/blacklist") public class BlacklistController { private final BlacklistService blacklistService; private final BlacklistMapper blacklistMapper; - @Autowired - public BlacklistController(BlacklistService blacklistService, BlacklistMapper blacklistMapper) { - this.blacklistService = blacklistService; - this.blacklistMapper = blacklistMapper; - } - // 1. 모든 학생 블랙리스트 조회 @Operation(summary = "직원 - 학생 블랙리스트 전체 조회") @GetMapping("/student") @@ -121,7 +115,7 @@ public ResponseEntity> findAllStude } // 직원 - 예비 블랙리스트 전체 조회(강사) - @Operation(summary = "직원 - 학생 예비 블랙리스트 전체 조회") + @Operation(summary = "직원 - 강사 예비 블랙리스트 전체 조회") @GetMapping("/tutor/reserved") public ResponseEntity> findAllTutorReservedBlacklist(){ // dto로 받아와야하는데 어떤 dto로 받아올까? @@ -157,7 +151,7 @@ public ResponseEntity> findStudentReser } // 강사 예비 블랙리스트 단건 조회 - @Operation(summary = "직원 - 직원 예비 블랙리스트 단건 세부 조회") + @Operation(summary = "직원 - 강사 예비 블랙리스트 단건 세부 조회") @GetMapping("/tutor/reserved/{tutorcode}") public ResponseEntity> findTutorReservedBlacklist( @PathVariable("tutorcode") Long tutorCode @@ -171,4 +165,20 @@ public ResponseEntity> findTutorReserve return ResponseEntity.status(HttpStatus.OK).body(voList); } + + // 멤버 예비 블랙리스트 -> 블랙리스트 "등록" 메서드 + @Operation(summary = "직원 - 예비 블랙리스트 블랙리스트 등록") + @PostMapping("/{membercode}") + public ResponseEntity addMemberToBlacklist( + @PathVariable("membercode") Long memberCode, + @RequestBody RequestSaveBlacklistVO request + ){ + BlacklistDTO blacklistDTO = new BlacklistDTO(); + blacklistDTO.setMemberCode(memberCode); + blacklistDTO.setBlackReason(request.getBlackReason()); + + blacklistService.addMemberToBlacklist(blacklistDTO); + + return ResponseEntity.status(HttpStatus.OK).body("블랙리스트 등록 성공"); + } } diff --git a/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/mapper/BlacklistMapper.java b/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/mapper/BlacklistMapper.java index 56d65832..c52fbac5 100644 --- a/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/mapper/BlacklistMapper.java +++ b/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/mapper/BlacklistMapper.java @@ -1,5 +1,6 @@ package intbyte4.learnsmate.blacklist.mapper; +import intbyte4.learnsmate.admin.domain.entity.Admin; import intbyte4.learnsmate.blacklist.domain.dto.BlacklistDTO; import intbyte4.learnsmate.blacklist.domain.dto.BlacklistReportCommentDTO; import intbyte4.learnsmate.blacklist.domain.entity.Blacklist; @@ -7,9 +8,11 @@ import intbyte4.learnsmate.blacklist.domain.vo.response.ResponseFindReservedBlacklistOneVO; import intbyte4.learnsmate.blacklist.domain.vo.response.ResponseFindReservedStudentBlacklistVO; import intbyte4.learnsmate.blacklist.domain.vo.response.ResponseFindReservedTutorBlacklistVO; +import intbyte4.learnsmate.member.domain.entity.Member; import intbyte4.learnsmate.report.domain.dto.ReportedMemberDTO; import org.springframework.stereotype.Component; +import java.time.LocalDateTime; import java.util.List; import java.util.stream.Collectors; @@ -61,4 +64,13 @@ public List fromBlacklistReportCommentDTOToR .build()) .collect(Collectors.toList()); } + + public Blacklist fromBlacklistDTOtoBlacklist(BlacklistDTO dto, Member member, Admin admin) { + return Blacklist.builder() + .createdAt(LocalDateTime.now()) + .blackReason(dto.getBlackReason()) + .admin(admin) + .member(member) + .build(); + } } diff --git a/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/service/BlacklistService.java b/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/service/BlacklistService.java index 58e60cf2..09541a74 100644 --- a/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/service/BlacklistService.java +++ b/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/service/BlacklistService.java @@ -1,5 +1,8 @@ package intbyte4.learnsmate.blacklist.service; +import intbyte4.learnsmate.admin.domain.dto.AdminDTO; +import intbyte4.learnsmate.admin.domain.entity.Admin; +import intbyte4.learnsmate.admin.mapper.AdminMapper; import intbyte4.learnsmate.blacklist.domain.dto.BlacklistDTO; import intbyte4.learnsmate.blacklist.domain.dto.BlacklistReportCommentDTO; import intbyte4.learnsmate.blacklist.domain.entity.Blacklist; @@ -8,11 +11,14 @@ import intbyte4.learnsmate.comment.domain.dto.CommentDTO; import intbyte4.learnsmate.comment.service.CommentService; import intbyte4.learnsmate.member.domain.MemberType; +import intbyte4.learnsmate.member.domain.dto.MemberDTO; +import intbyte4.learnsmate.member.domain.entity.Member; +import intbyte4.learnsmate.member.mapper.MemberMapper; import intbyte4.learnsmate.member.service.MemberService; import intbyte4.learnsmate.report.domain.dto.ReportDTO; import intbyte4.learnsmate.report.domain.dto.ReportedMemberDTO; import intbyte4.learnsmate.report.service.ReportService; -import org.springframework.beans.factory.annotation.Autowired; +import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import java.util.ArrayList; @@ -20,6 +26,7 @@ import java.util.stream.Collectors; @Service +@RequiredArgsConstructor public class BlacklistService { private final BlacklistRepository blacklistRepository; @@ -27,15 +34,8 @@ public class BlacklistService { private final ReportService reportService; private final MemberService memberService; private final CommentService commentService; - - @Autowired - public BlacklistService(BlacklistRepository blacklistRepository, BlacklistMapper blacklistMapper, ReportService reportService, MemberService memberService, CommentService commentService) { - this.blacklistRepository = blacklistRepository; - this.blacklistMapper = blacklistMapper; - this.reportService = reportService; - this.memberService = memberService; - this.commentService = commentService; - } + private final MemberMapper memberMapper; + private final AdminMapper adminMapper; // 1. flag는 볼필요 없음. -> 학생, 강사만 구분해야함. public List findAllBlacklistByMemberType(MemberType memberType) { @@ -91,4 +91,25 @@ public List findBlacklistReportComment(Long memberCod } return blacklistReportCommentDTOList; } + + // 블랙리스트 등록 메서드 + public void addMemberToBlacklist(BlacklistDTO dto) { + // 1. memberCode에 해당하는 사람 + MemberDTO memberDTO = memberService.findById(dto.getMemberCode()); + Member member = memberMapper.fromMemberDTOtoMember(memberDTO); + + // 2. admin을 찾아와야 하는데 나중에 token으로 처리 할듯? + AdminDTO adminDTO = new AdminDTO(); + Admin admin = adminMapper.toEntity(adminDTO); + + // 3. BlacklistDTO 생성 -> 이유만 있으면 됨. -> 이유도 넘겨받아야함. -> dto 자체를 넘겨받으면 해결 + // 블랙리스트로 저장해야하니까 Blacklist 엔티티를 만들어야함. + Blacklist blacklist = blacklistMapper.fromBlacklistDTOtoBlacklist(dto, member, admin); + + // 4. 블랙리스트에 저장 + blacklistRepository.save(blacklist); + + // 5. 회원 flag false로 수정 + memberService.deleteMember(dto.getMemberCode()); + } }