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

✨ 기능 추가 / 수정: 멤버 타입에 따른 블랙리스트 필터링 메서드 추가 #184

Merged
merged 9 commits into from
Nov 14, 2024
Merged
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package intbyte4.learnsmate.blacklist.controller;

import intbyte4.learnsmate.blacklist.domain.dto.BlacklistDTO;
import intbyte4.learnsmate.blacklist.domain.dto.BlacklistFilterRequestDTO;
import intbyte4.learnsmate.blacklist.domain.dto.BlacklistReportCommentDTO;
import intbyte4.learnsmate.blacklist.domain.vo.request.RequestFilterBlacklistMemberVO;
import intbyte4.learnsmate.blacklist.domain.vo.request.RequestSaveBlacklistVO;
import intbyte4.learnsmate.blacklist.domain.vo.response.ResponseFindBlacklistVO;
import intbyte4.learnsmate.blacklist.domain.vo.response.ResponseFindReservedBlacklistOneVO;
Expand All @@ -13,7 +15,6 @@
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.*;
Expand Down Expand Up @@ -181,4 +182,26 @@ public ResponseEntity<String> addMemberToBlacklist(

return ResponseEntity.status(HttpStatus.OK).body("블랙리스트 등록 성공");
}

@Operation(summary = "학생 - 블랙리스트 필터링 기능 추가")
@GetMapping("/filter/student")
public ResponseEntity<?> filterBlackStudent(@RequestBody RequestFilterBlacklistMemberVO vo){
BlacklistFilterRequestDTO dto = blacklistMapper.fromFilterMemberVOtoFilterMemberDTO(vo);
dto.setMemberType(MemberType.STUDENT);

List<BlacklistDTO> blacklistDTOList = blacklistService.filterBlacklistMember(dto);

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

@Operation(summary = "강사 - 블랙리스트 필터링 기능 추가")
@GetMapping("/filter/tutor")
public ResponseEntity<?> filterBlackTutor(@RequestBody RequestFilterBlacklistMemberVO vo){
BlacklistFilterRequestDTO dto = blacklistMapper.fromFilterMemberVOtoFilterMemberDTO(vo);
dto.setMemberType(MemberType.TUTOR);

List<BlacklistDTO> blacklistDTOList = blacklistService.filterBlacklistMember(dto);

return ResponseEntity.status(HttpStatus.OK).body(blacklistDTOList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@
public class BlacklistDTO {

private Long blackCode;
private Long memberCode;
private String memberName;
private String memberEmail;
private String blackReason;

private LocalDateTime createdAt;
private Long memberCode;

private Long adminCode;
private String adminName;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package intbyte4.learnsmate.blacklist.domain.dto;

import intbyte4.learnsmate.member.domain.MemberType;
import lombok.*;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ToString
public class BlacklistFilterRequestDTO {
private Long memberCode;
private String memberName;
private String memberEmail;
private MemberType memberType;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런 어노테이션도 있었네요..

public class RequestFilterBlacklistMemberVO {
private Long memberCode;
private String memberName;
private String memberEmail;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
@ToString
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class ResponseFindBlacklistVO {

private Long blackCode;
private Long memberCode;
private String memberName;
private String memberEmail;
private String blackReason;

private LocalDateTime createdAt;
private Long memberCode;

private Long adminCode;
private String adminName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import intbyte4.learnsmate.admin.domain.entity.Admin;
import intbyte4.learnsmate.blacklist.domain.dto.BlacklistDTO;
import intbyte4.learnsmate.blacklist.domain.dto.BlacklistFilterRequestDTO;
import intbyte4.learnsmate.blacklist.domain.dto.BlacklistReportCommentDTO;
import intbyte4.learnsmate.blacklist.domain.entity.Blacklist;
import intbyte4.learnsmate.blacklist.domain.vo.request.RequestFilterBlacklistMemberVO;
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 @@ -23,20 +25,35 @@ public class BlacklistMapper {
public BlacklistDTO fromBlacklistToBlacklistDTO(Blacklist blacklist) {
return BlacklistDTO.builder()
.blackCode(blacklist.getBlackCode())
.memberCode(blacklist.getMember().getMemberCode())
.memberName(blacklist.getMember().getMemberName())
.memberEmail(blacklist.getMember().getMemberEmail())
.blackReason(blacklist.getBlackReason())
.createdAt(blacklist.getCreatedAt())
.memberCode(blacklist.getMember().getMemberCode())
.adminCode(blacklist.getAdmin().getAdminCode())
.adminName(blacklist.getAdmin().getAdminName())
.build();
}

public ResponseFindBlacklistVO fromBlacklistDTOToResponseFindReportVO(BlacklistDTO blacklistDTO) {
public ResponseFindBlacklistVO fromBlacklistDTOToResponseFindReportVO(BlacklistDTO dto) {
return ResponseFindBlacklistVO.builder()
.blackCode(blacklistDTO.getBlackCode())
.blackReason(blacklistDTO.getBlackReason())
.createdAt(blacklistDTO.getCreatedAt())
.memberCode(blacklistDTO.getMemberCode())
.adminCode(blacklistDTO.getAdminCode())
.blackCode(dto.getBlackCode())
.memberCode(dto.getMemberCode())
.memberName(dto.getMemberName())
.memberEmail(dto.getMemberEmail())
.blackReason(dto.getBlackReason())
.createdAt(dto.getCreatedAt())
.adminCode(dto.getAdminCode())
.adminName(dto.getAdminName())
.build();
}

public Blacklist fromBlacklistDTOtoBlacklist(BlacklistDTO dto, Member member, Admin admin) {
return Blacklist.builder()
.createdAt(LocalDateTime.now())
.blackReason(dto.getBlackReason())
.admin(admin)
.member(member)
.build();
}

Expand Down Expand Up @@ -65,12 +82,12 @@ public List<ResponseFindReservedBlacklistOneVO> fromBlacklistReportCommentDTOToR
.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)
public BlacklistFilterRequestDTO fromFilterMemberVOtoFilterMemberDTO(RequestFilterBlacklistMemberVO vo) {
return BlacklistFilterRequestDTO.builder()
.memberCode(vo.getMemberCode())
.memberName(vo.getMemberName())
.memberEmail(vo.getMemberEmail())
.build();
}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
package intbyte4.learnsmate.blacklist.repository;

import intbyte4.learnsmate.blacklist.domain.dto.BlacklistDTO;
import intbyte4.learnsmate.blacklist.domain.entity.Blacklist;
import intbyte4.learnsmate.member.domain.MemberType;
import org.springframework.context.annotation.Primary;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface BlacklistRepository extends JpaRepository<Blacklist, Long> {
@Primary
public interface BlacklistRepository extends JpaRepository<Blacklist, Long>, BlacklistRepositoryCustom {

@Query("SELECT b FROM blacklist b " +
"JOIN member m ON b.member.memberCode = m.memberCode " +
@Query("SELECT new intbyte4.learnsmate.blacklist.domain.dto.BlacklistDTO(" +
"b.blackCode, m.memberCode, m.memberName, m.memberEmail, b.blackReason, b.createdAt, a.adminCode, a.adminName" +
") " +
"FROM blacklist b " +
"JOIN b.member m " +
"LEFT JOIN b.admin a " +
"WHERE m.memberType = :memberType")
List<Blacklist> findAllBlacklistByMemberType(MemberType memberType);
List<BlacklistDTO> findAllBlacklistByMemberType(@Param("memberType") MemberType memberType);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package intbyte4.learnsmate.blacklist.repository;

import intbyte4.learnsmate.blacklist.domain.dto.BlacklistFilterRequestDTO;
import intbyte4.learnsmate.blacklist.domain.entity.Blacklist;

import java.util.List;

public interface BlacklistRepositoryCustom {
List<Blacklist> searchBy(BlacklistFilterRequestDTO request);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package intbyte4.learnsmate.blacklist.repository;

import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import intbyte4.learnsmate.blacklist.domain.dto.BlacklistFilterRequestDTO;
import intbyte4.learnsmate.blacklist.domain.entity.Blacklist;
import intbyte4.learnsmate.blacklist.domain.entity.QBlacklist;
import intbyte4.learnsmate.member.domain.MemberType;
import lombok.RequiredArgsConstructor;

import java.util.List;

@RequiredArgsConstructor
public class BlacklistRepositoryImpl implements BlacklistRepositoryCustom {

private final JPAQueryFactory queryFactory;

@Override
public List<Blacklist> searchBy(BlacklistFilterRequestDTO request) {
QBlacklist blacklist = QBlacklist.blacklist;

BooleanBuilder builder = new BooleanBuilder()
.and(eqMemberCode(request.getMemberCode()))
.and(likeMemberName(request.getMemberName()))
.and(likeMemberEmail(request.getMemberEmail())
.and(eqMemberType(request.getMemberType())));

return queryFactory
.selectFrom(blacklist)
.where(builder)
.fetch();
}

// memberCode 검색 조건
private BooleanExpression eqMemberCode(Long memberCode) {
return memberCode == null ? null : QBlacklist.blacklist.member.memberCode.eq(memberCode);
}

// memberName 검색 조건
private BooleanExpression likeMemberName(String memberName) {
return memberName == null ? null : QBlacklist.blacklist.member.memberName.containsIgnoreCase(memberName);
}

// memberEmail 검색 조건
private BooleanExpression likeMemberEmail(String memberEmail) {
return memberEmail == null ? null : QBlacklist.blacklist.member.memberEmail.containsIgnoreCase(memberEmail);
}

// memberType 검색 조건 (학생 또는 강사)
private BooleanExpression eqMemberType(MemberType memberType) {
return memberType == null ? null : QBlacklist.blacklist.member.memberType.eq(memberType);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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.BlacklistFilterRequestDTO;
import intbyte4.learnsmate.blacklist.domain.dto.BlacklistReportCommentDTO;
import intbyte4.learnsmate.blacklist.domain.entity.Blacklist;
import intbyte4.learnsmate.blacklist.mapper.BlacklistMapper;
Expand Down Expand Up @@ -40,14 +41,7 @@ public class BlacklistService {
// 1. flag는 볼필요 없음. -> 학생, 강사만 구분해야함.
public List<BlacklistDTO> findAllBlacklistByMemberType(MemberType memberType) {

List<Blacklist> blacklistList = blacklistRepository.findAllBlacklistByMemberType(memberType);

List<BlacklistDTO> blacklistDTOList = new ArrayList<>();

for (Blacklist blacklist : blacklistList) {
// Blacklsit -> BlacklsitDTO
blacklistDTOList.add(blacklistMapper.fromBlacklistToBlacklistDTO(blacklist));
}
List<BlacklistDTO> blacklistDTOList = blacklistRepository.findAllBlacklistByMemberType(memberType);

return blacklistDTOList;
}
Expand Down Expand Up @@ -112,4 +106,15 @@ public void addMemberToBlacklist(BlacklistDTO dto) {
// 5. 회원 flag false로 수정
memberService.deleteMember(dto.getMemberCode());
}

// 블랙리스트 필터링 메서드
public List<BlacklistDTO> filterBlacklistMember(BlacklistFilterRequestDTO dto){
List<Blacklist> blacklistList = blacklistRepository.searchBy(dto);

List<BlacklistDTO> blacklistDTOList = blacklistList.stream()
.map(blacklistMapper::fromBlacklistToBlacklistDTO)
.collect(Collectors.toList());

return blacklistDTOList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class MemberRepositoryImpl implements MemberRepositoryCustom {
private final JPAQueryFactory queryFactory;

@Override
public List<Member> searchBy(MemberFilterRequestDTO request) {
public List<Member> searchBy(MemberFilterRequestDTO request) {
QMember member = QMember.member;

BooleanBuilder builder = new BooleanBuilder()
Expand Down