Skip to content

Commit

Permalink
✨ 기능 추가 / 수정: 블랙리스트 등록 메서드 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellin22 committed Nov 14, 2024
1 parent c03b01c commit cdfde78
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")
Expand Down Expand Up @@ -121,7 +115,7 @@ public ResponseEntity<List<ResponseFindReservedStudentBlacklistVO>> findAllStude
}

// 직원 - 예비 블랙리스트 전체 조회(강사)
@Operation(summary = "직원 - 학생 예비 블랙리스트 전체 조회")
@Operation(summary = "직원 - 강사 예비 블랙리스트 전체 조회")
@GetMapping("/tutor/reserved")
public ResponseEntity<List<ResponseFindReservedTutorBlacklistVO>> findAllTutorReservedBlacklist(){
// dto로 받아와야하는데 어떤 dto로 받아올까?
Expand Down Expand Up @@ -157,7 +151,7 @@ public ResponseEntity<List<ResponseFindReservedBlacklistOneVO>> findStudentReser
}

// 강사 예비 블랙리스트 단건 조회
@Operation(summary = "직원 - 직원 예비 블랙리스트 단건 세부 조회")
@Operation(summary = "직원 - 강사 예비 블랙리스트 단건 세부 조회")
@GetMapping("/tutor/reserved/{tutorcode}")
public ResponseEntity<List<ResponseFindReservedBlacklistOneVO>> findTutorReservedBlacklist(
@PathVariable("tutorcode") Long tutorCode
Expand All @@ -171,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
@@ -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.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 Down Expand Up @@ -61,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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -8,34 +11,31 @@
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;
import java.util.List;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
public class BlacklistService {

private final BlacklistRepository blacklistRepository;
private final BlacklistMapper blacklistMapper;
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<BlacklistDTO> findAllBlacklistByMemberType(MemberType memberType) {
Expand Down Expand Up @@ -91,4 +91,25 @@ public List<BlacklistReportCommentDTO> 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());
}
}

0 comments on commit cdfde78

Please sign in to comment.