Skip to content

Commit

Permalink
Merge pull request #179 from LearnsMate/feature/blacklist
Browse files Browse the repository at this point in the history
✨ 기능 추가 / 수정: 블랙리스트 등록 메서드 처리
  • Loading branch information
Hellin22 authored Nov 14, 2024
2 parents 72033bb + cdfde78 commit d23fbb0
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,44 @@

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;
import intbyte4.learnsmate.blacklist.mapper.BlacklistMapper;
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<List<ResponseFindReportVO>> findAllStudentBlacklist() {
public ResponseEntity<List<ResponseFindBlacklistVO>> findAllStudentBlacklist() {

// service에서 dto 반환
List<BlacklistDTO> blacklistDTOList = blacklistService.findAllBlacklistByMemberType(MemberType.STUDENT);

List<ResponseFindReportVO> response = new ArrayList<>();
List<ResponseFindBlacklistVO> response = new ArrayList<>();

// dto -> ResponseFindReportVO로 전환해주기
// dto -> ResponseFindBlacklistVO로 전환해주기
for(BlacklistDTO blacklistDTO : blacklistDTOList) {
response.add(blacklistMapper.fromBlacklistDTOToResponseFindReportVO(blacklistDTO));
}
Expand All @@ -52,15 +48,16 @@ public ResponseEntity<List<ResponseFindReportVO>> findAllStudentBlacklist() {
}

// 2. 모든 강사 블랙리스트 조회
@Operation(summary = "직원 - 강사 블랙리스트 전체 조회")
@GetMapping("/tutor")
public ResponseEntity<List<ResponseFindReportVO>> findAllTutorBlacklist() {
public ResponseEntity<List<ResponseFindBlacklistVO>> findAllTutorBlacklist() {

// service에서 dto 반환
List<BlacklistDTO> blacklistDTOList = blacklistService.findAllBlacklistByMemberType(MemberType.TUTOR);

List<ResponseFindReportVO> response = new ArrayList<>();
List<ResponseFindBlacklistVO> response = new ArrayList<>();

// dto -> ResponseFindReportVO로 전환해주기
// dto -> ResponseFindBlacklistVO로 전환해주기
for(BlacklistDTO blacklistDTO : blacklistDTOList) {
response.add(blacklistMapper.fromBlacklistDTOToResponseFindReportVO(blacklistDTO));
}
Expand All @@ -69,8 +66,11 @@ public ResponseEntity<List<ResponseFindReportVO>> findAllTutorBlacklist() {
}

// 3. 학생 블랙리스트 단건 조회
@Operation(summary = "직원 - 학생 블랙리스트 단건 세부 조회")
@GetMapping("/student/{studentcode}")
public ResponseEntity<?> findStudentBlacklist(@PathVariable("studentcode") Long studentCode) {
public ResponseEntity<List<ResponseFindReservedBlacklistOneVO>> findStudentBlacklist(
@PathVariable("studentcode") Long studentCode
) {
// 보여줘야 하는것들
// 학생 정보 + 신고정보 + 댓글정보 -> 예비 블랙리스트하고 똑같이 하면 될거같네
List<BlacklistReportCommentDTO> dtoList = blacklistService.findBlacklistReportComment(studentCode);
Expand All @@ -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<List<ResponseFindReservedBlacklistOneVO>> findTutorBlacklist(
@PathVariable("tutorcode") Long tutorCode
) {
List<BlacklistReportCommentDTO> dtoList = blacklistService.findBlacklistReportComment(tutorCode);

List<ResponseFindReservedBlacklistOneVO> voList
Expand All @@ -93,6 +96,7 @@ public ResponseEntity<?> findTutorBlacklist(@PathVariable("tutorcode") Long tuto
}

// 직원 - 예비 블랙리스트 전체 조회(학생)
@Operation(summary = "직원 - 학생 예비 블랙리스트 전체 조회")
@GetMapping("/student/reserved")
public ResponseEntity<List<ResponseFindReservedStudentBlacklistVO>> findAllStudentReservedBlacklist() {
// dto로 받아와야하는데 어떤 dto로 받아올까?
Expand All @@ -111,6 +115,7 @@ public ResponseEntity<List<ResponseFindReservedStudentBlacklistVO>> findAllStude
}

// 직원 - 예비 블랙리스트 전체 조회(강사)
@Operation(summary = "직원 - 강사 예비 블랙리스트 전체 조회")
@GetMapping("/tutor/reserved")
public ResponseEntity<List<ResponseFindReservedTutorBlacklistVO>> findAllTutorReservedBlacklist(){
// dto로 받아와야하는데 어떤 dto로 받아올까?
Expand All @@ -130,8 +135,11 @@ public ResponseEntity<List<ResponseFindReservedTutorBlacklistVO>> findAllTutorRe
}

// 학생 예비 블랙리스트 단건 조회
@Operation(summary = "직원 - 학생 예비 블랙리스트 단건 세부 조회")
@GetMapping("/student/reserved/{studentcode}")
public ResponseEntity<List<ResponseFindReservedBlacklistOneVO>> findStudentReservedBlacklist(@PathVariable("studentcode") Long studentCode) {
public ResponseEntity<List<ResponseFindReservedBlacklistOneVO>> findStudentReservedBlacklist(
@PathVariable("studentcode") Long studentCode
) {
// 결국 예비 블랙리스트가 없어서 계산해서 가져와야함. -> Report에서 tutorcode에 해당하는 모든 Report 가져오고
// -> 그 report 안에 있는 comment code를 통해서 comment도 가져와야함.
List<BlacklistReportCommentDTO> dtoList = blacklistService.findBlacklistReportComment(studentCode);
Expand All @@ -143,8 +151,11 @@ public ResponseEntity<List<ResponseFindReservedBlacklistOneVO>> findStudentReser
}

// 강사 예비 블랙리스트 단건 조회
@Operation(summary = "직원 - 강사 예비 블랙리스트 단건 세부 조회")
@GetMapping("/tutor/reserved/{tutorcode}")
public ResponseEntity<List<ResponseFindReservedBlacklistOneVO>> findTutorReservedBlacklist(@PathVariable("tutorcode") Long tutorCode) {
public ResponseEntity<List<ResponseFindReservedBlacklistOneVO>> findTutorReservedBlacklist(
@PathVariable("tutorcode") Long tutorCode
) {
// 결국 예비 블랙리스트가 없어서 계산해서 가져와야함. -> Report에서 tutorcode에 해당하는 모든 Report 가져오고
// -> 그 report 안에 있는 comment code를 통해서 comment도 가져와야함.
List<BlacklistReportCommentDTO> dtoList = blacklistService.findBlacklistReportComment(tutorCode);
Expand All @@ -154,4 +165,20 @@ public ResponseEntity<List<ResponseFindReservedBlacklistOneVO>> findTutorReserve

return ResponseEntity.status(HttpStatus.OK).body(voList);
}

// 멤버 예비 블랙리스트 -> 블랙리스트 "등록" 메서드
@Operation(summary = "직원 - 예비 블랙리스트 블랙리스트 등록")
@PostMapping("/{membercode}")
public ResponseEntity<String> 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("블랙리스트 등록 성공");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

This file was deleted.

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

Expand All @@ -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();
}
Expand Down Expand Up @@ -65,4 +64,13 @@ public List<ResponseFindReservedBlacklistOneVO> 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();
}
}
Loading

0 comments on commit d23fbb0

Please sign in to comment.