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 7c6093d3..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,7 +2,8 @@ import intbyte4.learnsmate.blacklist.domain.dto.BlacklistDTO; import intbyte4.learnsmate.blacklist.domain.dto.BlacklistReportCommentDTO; -import intbyte4.learnsmate.blacklist.domain.vo.response.ResponseFindReportVO; +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; import intbyte4.learnsmate.blacklist.domain.vo.response.ResponseFindReservedTutorBlacklistVO; @@ -10,40 +11,35 @@ import intbyte4.learnsmate.blacklist.service.BlacklistService; 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") - public ResponseEntity> findAllStudentBlacklist() { + public ResponseEntity> findAllStudentBlacklist() { // service에서 dto 반환 List blacklistDTOList = blacklistService.findAllBlacklistByMemberType(MemberType.STUDENT); - List response = new ArrayList<>(); + List response = new ArrayList<>(); - // dto -> ResponseFindReportVO로 전환해주기 + // dto -> ResponseFindBlacklistVO로 전환해주기 for(BlacklistDTO blacklistDTO : blacklistDTOList) { response.add(blacklistMapper.fromBlacklistDTOToResponseFindReportVO(blacklistDTO)); } @@ -52,15 +48,16 @@ public ResponseEntity> findAllStudentBlacklist() { } // 2. 모든 강사 블랙리스트 조회 + @Operation(summary = "직원 - 강사 블랙리스트 전체 조회") @GetMapping("/tutor") - public ResponseEntity> findAllTutorBlacklist() { + public ResponseEntity> findAllTutorBlacklist() { // service에서 dto 반환 List blacklistDTOList = blacklistService.findAllBlacklistByMemberType(MemberType.TUTOR); - List response = new ArrayList<>(); + List response = new ArrayList<>(); - // dto -> ResponseFindReportVO로 전환해주기 + // dto -> ResponseFindBlacklistVO로 전환해주기 for(BlacklistDTO blacklistDTO : blacklistDTOList) { response.add(blacklistMapper.fromBlacklistDTOToResponseFindReportVO(blacklistDTO)); } @@ -69,8 +66,11 @@ public ResponseEntity> findAllTutorBlacklist() { } // 3. 학생 블랙리스트 단건 조회 + @Operation(summary = "직원 - 학생 블랙리스트 단건 세부 조회") @GetMapping("/student/{studentcode}") - public ResponseEntity findStudentBlacklist(@PathVariable("studentcode") Long studentCode) { + public ResponseEntity> findStudentBlacklist( + @PathVariable("studentcode") Long studentCode + ) { // 보여줘야 하는것들 // 학생 정보 + 신고정보 + 댓글정보 -> 예비 블랙리스트하고 똑같이 하면 될거같네 List dtoList = blacklistService.findBlacklistReportComment(studentCode); @@ -82,8 +82,11 @@ public ResponseEntity findStudentBlacklist(@PathVariable("studentcode") Long } // 4. 강사 블랙리스트 단건 조회 + @Operation(summary = "직원 - 강사 블랙리스트 단건 세부 조회") @GetMapping("/tutor/{tutorcode}") - public ResponseEntity findTutorBlacklist(@PathVariable("tutorcode") Long tutorCode) { + public ResponseEntity> findTutorBlacklist( + @PathVariable("tutorcode") Long tutorCode + ) { List dtoList = blacklistService.findBlacklistReportComment(tutorCode); List voList @@ -93,6 +96,7 @@ public ResponseEntity findTutorBlacklist(@PathVariable("tutorcode") Long tuto } // 직원 - 예비 블랙리스트 전체 조회(학생) + @Operation(summary = "직원 - 학생 예비 블랙리스트 전체 조회") @GetMapping("/student/reserved") public ResponseEntity> findAllStudentReservedBlacklist() { // dto로 받아와야하는데 어떤 dto로 받아올까? @@ -111,6 +115,7 @@ public ResponseEntity> findAllStude } // 직원 - 예비 블랙리스트 전체 조회(강사) + @Operation(summary = "직원 - 강사 예비 블랙리스트 전체 조회") @GetMapping("/tutor/reserved") public ResponseEntity> findAllTutorReservedBlacklist(){ // dto로 받아와야하는데 어떤 dto로 받아올까? @@ -130,8 +135,11 @@ public ResponseEntity> findAllTutorRe } // 학생 예비 블랙리스트 단건 조회 + @Operation(summary = "직원 - 학생 예비 블랙리스트 단건 세부 조회") @GetMapping("/student/reserved/{studentcode}") - public ResponseEntity> findStudentReservedBlacklist(@PathVariable("studentcode") Long studentCode) { + public ResponseEntity> findStudentReservedBlacklist( + @PathVariable("studentcode") Long studentCode + ) { // 결국 예비 블랙리스트가 없어서 계산해서 가져와야함. -> Report에서 tutorcode에 해당하는 모든 Report 가져오고 // -> 그 report 안에 있는 comment code를 통해서 comment도 가져와야함. List dtoList = blacklistService.findBlacklistReportComment(studentCode); @@ -143,8 +151,11 @@ public ResponseEntity> findStudentReser } // 강사 예비 블랙리스트 단건 조회 + @Operation(summary = "직원 - 강사 예비 블랙리스트 단건 세부 조회") @GetMapping("/tutor/reserved/{tutorcode}") - public ResponseEntity> findTutorReservedBlacklist(@PathVariable("tutorcode") Long tutorCode) { + public ResponseEntity> findTutorReservedBlacklist( + @PathVariable("tutorcode") Long tutorCode + ) { // 결국 예비 블랙리스트가 없어서 계산해서 가져와야함. -> Report에서 tutorcode에 해당하는 모든 Report 가져오고 // -> 그 report 안에 있는 comment code를 통해서 comment도 가져와야함. List dtoList = blacklistService.findBlacklistReportComment(tutorCode); @@ -154,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/domain/dto/BlacklistDTO.java b/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/domain/dto/BlacklistDTO.java index 8d575eab..3b53e510 100644 --- a/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/domain/dto/BlacklistDTO.java +++ b/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/domain/dto/BlacklistDTO.java @@ -16,8 +16,6 @@ public class BlacklistDTO { private Long blackCode; private String blackReason; private LocalDateTime createdAt; - private LocalDateTime updatedAt; private Long memberCode; - private Long reportCode; private Long adminCode; } diff --git a/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/domain/entity/Blacklist.java b/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/domain/entity/Blacklist.java index 5572dade..4986e0d1 100644 --- a/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/domain/entity/Blacklist.java +++ b/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/domain/entity/Blacklist.java @@ -28,16 +28,16 @@ public class Blacklist { @Column(name = "created_at", nullable = false) private LocalDateTime createdAt; - @Column(name = "updated_at", nullable = false) - private LocalDateTime updatedAt; +// @Column(name = "updated_at", nullable = false) +// private LocalDateTime updatedAt; @ManyToOne @JoinColumn(name = "member_code", nullable = false) private Member member; - @ManyToOne - @JoinColumn(name = "report_code", nullable = false) - private Report report; +// @ManyToOne +// @JoinColumn(name = "report_code", nullable = false) +// private Report report; @ManyToOne @JoinColumn(name = "admin_code", nullable = false) diff --git a/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/domain/vo/request/RequestBlacklistVO.java b/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/domain/vo/request/RequestBlacklistVO.java index b76daeaa..f706ad09 100644 --- a/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/domain/vo/request/RequestBlacklistVO.java +++ b/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/domain/vo/request/RequestBlacklistVO.java @@ -17,8 +17,6 @@ public class RequestBlacklistVO { private Long blackCode; private String blackReason; private LocalDateTime createdAt; - private LocalDateTime updatedAt; private Long memberCode; - private Long reportCode; private Long adminCode; } diff --git a/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/domain/vo/request/RequestSaveBlacklistVO.java b/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/domain/vo/request/RequestSaveBlacklistVO.java new file mode 100644 index 00000000..6f4ea48d --- /dev/null +++ b/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/domain/vo/request/RequestSaveBlacklistVO.java @@ -0,0 +1,15 @@ +package intbyte4.learnsmate.blacklist.domain.vo.request; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.*; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +@Builder +@ToString +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class RequestSaveBlacklistVO { + private String BlackReason; +} diff --git a/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/domain/vo/response/ResponseBlacklistVO.java b/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/domain/vo/response/ResponseFindBlacklistVO.java similarity index 83% rename from LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/domain/vo/response/ResponseBlacklistVO.java rename to LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/domain/vo/response/ResponseFindBlacklistVO.java index 9e898997..65bf8781 100644 --- a/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/domain/vo/response/ResponseBlacklistVO.java +++ b/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/domain/vo/response/ResponseFindBlacklistVO.java @@ -11,13 +11,11 @@ @Builder @ToString @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) -public class ResponseBlacklistVO { +public class ResponseFindBlacklistVO { private Long blackCode; private String blackReason; private LocalDateTime createdAt; - private LocalDateTime updatedAt; private Long memberCode; - private Long reportCode; private Long adminCode; } diff --git a/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/domain/vo/response/ResponseFindReportVO.java b/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/domain/vo/response/ResponseFindReportVO.java deleted file mode 100644 index 649a0790..00000000 --- a/LearnsMate/src/main/java/intbyte4/learnsmate/blacklist/domain/vo/response/ResponseFindReportVO.java +++ /dev/null @@ -1,23 +0,0 @@ -package intbyte4.learnsmate.blacklist.domain.vo.response; - -import com.fasterxml.jackson.databind.PropertyNamingStrategies; -import com.fasterxml.jackson.databind.annotation.JsonNaming; -import lombok.*; - -import java.time.LocalDateTime; - -@Getter -@AllArgsConstructor -@NoArgsConstructor -@Builder -@ToString -@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) -public class ResponseFindReportVO { - - private Long blackCode; - private String blackReason; - private LocalDateTime createdAt; - private LocalDateTime updatedAt; - private Long memberCode; - private Long reportCode; - private Long adminCode;} 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 8d003124..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,15 +1,18 @@ 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; -import intbyte4.learnsmate.blacklist.domain.vo.response.ResponseFindReportVO; +import intbyte4.learnsmate.blacklist.domain.vo.response.ResponseFindBlacklistVO; 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; @@ -22,21 +25,17 @@ public BlacklistDTO fromBlacklistToBlacklistDTO(Blacklist blacklist) { .blackCode(blacklist.getBlackCode()) .blackReason(blacklist.getBlackReason()) .createdAt(blacklist.getCreatedAt()) - .updatedAt(blacklist.getUpdatedAt()) .memberCode(blacklist.getMember().getMemberCode()) - .reportCode(blacklist.getReport().getReportCode()) .adminCode(blacklist.getAdmin().getAdminCode()) .build(); } - public ResponseFindReportVO fromBlacklistDTOToResponseFindReportVO(BlacklistDTO blacklistDTO) { - return ResponseFindReportVO.builder() + public ResponseFindBlacklistVO fromBlacklistDTOToResponseFindReportVO(BlacklistDTO blacklistDTO) { + return ResponseFindBlacklistVO.builder() .blackCode(blacklistDTO.getBlackCode()) .blackReason(blacklistDTO.getBlackReason()) .createdAt(blacklistDTO.getCreatedAt()) - .updatedAt(blacklistDTO.getUpdatedAt()) .memberCode(blacklistDTO.getMemberCode()) - .reportCode(blacklistDTO.getReportCode()) .adminCode(blacklistDTO.getAdminCode()) .build(); } @@ -65,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 b668b61a..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) { @@ -44,10 +44,6 @@ public List findAllBlacklistByMemberType(MemberType memberType) { List blacklistDTOList = new ArrayList<>(); -// .memberCode(blacklist.getMemberCode()) -// .reportCode(blacklist.getReportCode()) -// .adminCode(blacklist.getAdminCode()) - for (Blacklist blacklist : blacklistList) { // Blacklsit -> BlacklsitDTO blacklistDTOList.add(blacklistMapper.fromBlacklistToBlacklistDTO(blacklist)); @@ -61,12 +57,20 @@ public List findAllBlacklistByMemberType(MemberType memberType) { // 2. Member table에서 가져오기(true인 놈들) public List findAllReservedBlacklistByMemberType(MemberType memberType) { + // 모든 멤버 가져옴. List reportedMoreThanFiveMemberList = reportService.findReportCountByMemberCode(); - return reportedMoreThanFiveMemberList; + // 멤버 타입이 동일한거만 가져오기 -> 원래는 sql로 처리해야하지만 많지 않을것이기 때문에 백엔드에서 처리해도 무방하다 생각 + // + flag가 true인 사람 가져오기 + List filteredList = reportedMoreThanFiveMemberList.stream() + .filter(dto -> dto.getReportedMember().getMemberType().equals(memberType) + && dto.getReportedMember().getMemberFlag()) + .collect(Collectors.toList()); + + return filteredList; } - // 블랙이스트에서 신고당한 댓글 내역까지 모두 볼수 있는 서비스 메서드 + // 블랙리스트에서 신고당한 댓글 내역까지 모두 볼수 있는 서비스 메서드 public List findBlacklistReportComment(Long memberCode) { // 1. Report table에서 memberCode와 reportedMemberCode 가 같은거 가져오기 @@ -87,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()); + } }