Skip to content

Commit

Permalink
feat: 부서 메인 조회 API 랭킹 추가 (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
hojeong2747 committed Oct 7, 2023
1 parent 10223fc commit e94c1e0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package kusitms.server.domain.tumbler.current.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import kusitms.server.domain.tumbler.history.dto.response.HistoryMonthDetailResponseDto;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

@NoArgsConstructor
@Getter
@Schema(description = "부서 메인 조회 응답 객체")
Expand All @@ -13,24 +17,28 @@ public class MainResponseDto {
@Schema(description = "이번달 부서별 텀블러 등급", example = "1")
private Integer tumblerGrade;

@Schema(description = "이번달 부서별 텀블러 명", example = "")
@Schema(description = "이번달 부서별 텀블러 명", example = "AA건전지")
private String tumblerName;

@Schema(description = "부서명", example = "")
@Schema(description = "부서명", example = "A")
private String deptName;

@Schema(description = "이번달 부서별 텀블러 퍼센트", example = "")
@Schema(description = "이번달 부서별 텀블러 퍼센트", example = "50.0")
private Double tumblerPercent;

@Schema(description = "이번달 목표 수 - 현재 적립 수", example = "")
@Schema(description = "이번달 목표 수 - 현재 적립 수", example = "288")
private Integer toGoalCount;

@Schema(description = "이번달 랭킹 TOP3")
private List<HistoryMonthDetailResponseDto> rankList = new ArrayList<>();

@Builder
public MainResponseDto(Integer tumblerGrade, String tumblerName, String deptName, Double tumblerPercent, Integer toGoalCount) {
public MainResponseDto(Integer tumblerGrade, String tumblerName, String deptName, Double tumblerPercent, Integer toGoalCount, List<HistoryMonthDetailResponseDto> rankList) {
this.tumblerGrade = tumblerGrade;
this.tumblerName = tumblerName;
this.deptName = deptName;
this.tumblerPercent = tumblerPercent;
this.toGoalCount = toGoalCount;
this.rankList = rankList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@

import kusitms.server.domain.department.entity.Department;
import kusitms.server.domain.department.repository.DepartmentRepository;
import kusitms.server.domain.tumbler.current.dto.request.MainRequestDto;
import kusitms.server.domain.tumbler.current.dto.response.MainResponseDto;
import kusitms.server.domain.tumbler.current.entity.TumblerCurrent;
import kusitms.server.domain.tumbler.current.repository.TumblerCurrentRepository;
import kusitms.server.domain.tumbler.history.dto.response.HistoryMonthDetailResponseDto;
import kusitms.server.domain.tumbler.history.service.TumblerHistoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@RequiredArgsConstructor
@Service
@Transactional
public class TumblerCurrentService {

private final DepartmentRepository departmentRepository;
private final TumblerCurrentRepository tumblerCurrentRepository;
private final TumblerHistoryService tumblerHistoryService;

public MainResponseDto getTumblerCurrent(Long userId) {

Expand All @@ -34,12 +39,15 @@ public MainResponseDto getTumblerCurrent(Long userId) {
Double tumblerPercent = tumblerCurrent.getTumblerPercent(); // 이번달 부서별 텀블러 퍼센트
Integer tumblerGrade = tumblerCurrent.getTumblerGrade(); // 이번달 부서별 텀블러 등급

List<HistoryMonthDetailResponseDto> rankList = tumblerHistoryService.findDetailByMonth("202310", userId);

MainResponseDto res = MainResponseDto.builder()
.tumblerGrade(tumblerGrade)
.tumblerName(tumblerName)
.deptName(deptName)
.tumblerPercent(tumblerPercent)
.toGoalCount(tumblerGoal - tumblerCount)
.rankList(rankList)
.build();

return res;
Expand Down

0 comments on commit e94c1e0

Please sign in to comment.