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

✨ 기능 추가: VOCService -> countVOCByCategory 추가 #192

Merged
merged 5 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}