Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…kend into feature/lecture
  • Loading branch information
JoJeHuni committed Nov 14, 2024
2 parents 50edbc5 + 31f13f8 commit 17c1c77
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package intbyte4.learnsmate.voc.controller;

import intbyte4.learnsmate.common.exception.CommonException;
import intbyte4.learnsmate.member.domain.dto.MemberDTO;
import intbyte4.learnsmate.voc.domain.dto.VOCDTO;
import intbyte4.learnsmate.voc.domain.vo.response.ResponseFindVOCVO;
import intbyte4.learnsmate.voc.mapper.VOCMapper;
Expand All @@ -10,10 +11,7 @@
import lombok.extern.slf4j.Slf4j;
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;
Expand Down Expand Up @@ -79,4 +77,22 @@ public ResponseEntity<List<ResponseFindVOCVO>> listAnsweredVOC(@PathVariable("me
.collect(Collectors.toList());
return ResponseEntity.status(HttpStatus.OK).body(response);
}

@Operation(summary = "VOC 필터링")
@PostMapping("/filter")
public ResponseEntity<List<VOCDTO>> filterVOC(@RequestBody VOCDTO vocDTO, MemberDTO memberDTO) {
log.info("VOC 필터링 요청 수신");
try {
List<VOCDTO> filteredVOCList = vocService.filterVOC(vocDTO, memberDTO);

log.info("VOC 필터링 성공, 필터링된 데이터 수: {}", filteredVOCList.size());
return ResponseEntity.ok(filteredVOCList);
} catch (CommonException e) {
log.error("VOC 필터링 실패: {}", e.getMessage());
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
} catch (Exception e) {
log.error("예상치 못한 오류 발생", e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package intbyte4.learnsmate.voc.service;

import intbyte4.learnsmate.member.domain.dto.MemberDTO;
import intbyte4.learnsmate.voc.domain.dto.VOCDTO;

import java.util.List;
Expand All @@ -14,4 +15,6 @@ public interface VOCService {
List<VOCDTO> findUnansweredVOCByMember(Long memberCode);

List<VOCDTO> findAnsweredVOCByMember(Long memberCode);

List<VOCDTO> filterVOC(VOCDTO vocDTO, MemberDTO memberDTO);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import intbyte4.learnsmate.common.exception.CommonException;
import intbyte4.learnsmate.common.exception.StatusEnum;
import intbyte4.learnsmate.member.domain.dto.MemberDTO;
import intbyte4.learnsmate.voc.domain.VOC;
import intbyte4.learnsmate.voc.domain.dto.VOCDTO;
import intbyte4.learnsmate.voc.mapper.VOCMapper;
Expand Down Expand Up @@ -67,4 +68,22 @@ public List<VOCDTO> findAnsweredVOCByMember(Long memberCode) {
.map(vocMapper::fromEntityToDTO)
.collect(Collectors.toList());
}

@Override
public List<VOCDTO> filterVOC(VOCDTO vocDTO, MemberDTO memberDTO) {
log.info("VOC 필터링 요청: {}", vocDTO);
List<VOC> filteredVOCList = vocRepository.searchBy(vocDTO, memberDTO);

if (filteredVOCList.isEmpty()) {
log.info("필터 조건에 맞는 VOC가 없습니다.");
throw new CommonException(StatusEnum.VOC_NOT_FOUND);
}

List<VOCDTO> vocDTOList = filteredVOCList.stream()
.map(vocMapper::fromEntityToDTO)
.collect(Collectors.toList());

log.info("필터링된 VOC 수: {}", vocDTOList.size());
return vocDTOList;
}
}

0 comments on commit 17c1c77

Please sign in to comment.