Skip to content

Commit

Permalink
Merge pull request #192 from LearnsMate/feature/voc
Browse files Browse the repository at this point in the history
✨ 기능 추가: VOCService -> countVOCByCategory 추가
  • Loading branch information
JoJeHuni authored Nov 15, 2024
2 parents b9a8155 + e132a50 commit f3d1c70
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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.ResponseCountByCategoryVO;
import intbyte4.learnsmate.voc.domain.vo.response.ResponseFindVOCVO;
import intbyte4.learnsmate.voc.mapper.VOCMapper;
import intbyte4.learnsmate.voc.service.VOCService;
Expand All @@ -15,6 +16,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RestController("vocController")
Expand Down Expand Up @@ -78,6 +80,20 @@ public ResponseEntity<List<ResponseFindVOCVO>> listAnsweredVOC(@PathVariable("me
return ResponseEntity.status(HttpStatus.OK).body(response);
}

@Operation(summary = "직원 - VOC 카테고리 별 개수 조회")
@GetMapping("/count-by-category")
public ResponseEntity<List<ResponseCountByCategoryVO>> countVOCByCategory() {
Map<Integer, Long> categoryCountMap = vocService.countVOCByCategory();
List<ResponseCountByCategoryVO> response = categoryCountMap.entrySet().stream()
.map(entry -> ResponseCountByCategoryVO.builder()
.vocCategoryCode(entry.getKey())
.vocCount(entry.getValue())
.build())
.collect(Collectors.toList());

return ResponseEntity.ok(response);
}

@Operation(summary = "VOC 필터링")
@PostMapping("/filter")
public ResponseEntity<List<VOCDTO>> filterVOC(@RequestBody VOCDTO vocDTO, MemberDTO memberDTO) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package intbyte4.learnsmate.voc.domain.vo.response;

import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import lombok.*;

@Getter
@ToString
@EqualsAndHashCode
@AllArgsConstructor
@NoArgsConstructor
@Builder
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class ResponseCountByCategoryVO {
private int vocCategoryCode;
private Long vocCount;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ public interface VOCRepository extends JpaRepository<VOC, Long>, VOCRepositoryCu
"WHERE v.member.memberCode = :memberCode " +
"AND v.vocAnswerStatus = true")
List<VOC> findAnsweredVOCByMember(@Param("memberCode") Long memberCode);

long countByVocCategory_VocCategoryCode(Integer vocCategoryCode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import intbyte4.learnsmate.voc.domain.dto.VOCDTO;

import java.util.List;
import java.util.Map;

public interface VOCService {
List<VOCDTO> findAllByVOC();
Expand All @@ -17,4 +18,6 @@ public interface VOCService {
List<VOCDTO> findAnsweredVOCByMember(Long memberCode);

List<VOCDTO> filterVOC(VOCDTO vocDTO, MemberDTO memberDTO);

Map<Integer, Long> countVOCByCategory();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
import intbyte4.learnsmate.voc.domain.dto.VOCDTO;
import intbyte4.learnsmate.voc.mapper.VOCMapper;
import intbyte4.learnsmate.voc.repository.VOCRepository;
import intbyte4.learnsmate.voc_category.domain.dto.VocCategoryDTO;
import intbyte4.learnsmate.voc_category.service.VocCategoryService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
Expand All @@ -22,6 +26,7 @@ public class VOCServiceImpl implements VOCService {

private final VOCRepository vocRepository;
private final VOCMapper vocMapper;
private final VocCategoryService vocCategoryService;

@Override
public List<VOCDTO> findAllByVOC() {
Expand Down Expand Up @@ -86,4 +91,19 @@ public List<VOCDTO> filterVOC(VOCDTO vocDTO, MemberDTO memberDTO) {
log.info("필터링된 VOC 수: {}", vocDTOList.size());
return vocDTOList;
}

@Override
public Map<Integer, Long> countVOCByCategory(){
List<VocCategoryDTO> vocCategoryDTOList = vocCategoryService.findAll();

Map<Integer, Long> categoryCountMap = new HashMap<>();

vocCategoryDTOList.forEach(category -> {
int categoryCode = category.getVocCategoryCode();
long count = vocRepository.countByVocCategory_VocCategoryCode(categoryCode);
categoryCountMap.put(categoryCode, count);
});

return categoryCountMap;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package intbyte4.learnsmate.voc_category.service;

import intbyte4.learnsmate.voc_category.domain.VocCategory;
import intbyte4.learnsmate.voc_category.domain.dto.VocCategoryDTO;

import java.util.List;

public interface VocCategoryService {
VocCategory findByVocCategoryCode(Integer vocCategoryCode);

List<VocCategoryDTO> findAll();
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package intbyte4.learnsmate.voc_category.service;

import intbyte4.learnsmate.voc_category.domain.VocCategory;
import intbyte4.learnsmate.voc_category.domain.dto.VocCategoryDTO;
import intbyte4.learnsmate.voc_category.repository.VocCategoryRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service("vocCategoryService")
@RequiredArgsConstructor
Expand All @@ -18,4 +22,13 @@ public VocCategory findByVocCategoryCode(Integer vocCategoryCode) {
log.info("vocCategory 조회 중: {}", vocCategoryCode);
return vocCategoryRepository.findById(vocCategoryCode).orElseThrow(() -> new RuntimeException("vocCategoryCode not found"));
}

public List<VocCategoryDTO> findAll() {
return vocCategoryRepository.findAll().stream()
.map(vocCategory -> VocCategoryDTO.builder()
.vocCategoryCode(vocCategory.getVocCategoryCode())
.vocCategoryName(vocCategory.getVocCategoryName())
.build())
.collect(Collectors.toList());
}
}

0 comments on commit f3d1c70

Please sign in to comment.