Skip to content

Commit

Permalink
Merge pull request #41 from Kusitms-28th-Kukathon-F/feat/22-tumbler-main
Browse files Browse the repository at this point in the history
Feat/22 tumbler main
  • Loading branch information
hojeong2747 authored Oct 7, 2023
2 parents 9cee59d + e94c1e0 commit 3d184c6
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public interface DepartmentRepository extends JpaRepository<Department, Long> {
Optional<Department> findByUser(User user);

List<Department> findAllByCompany(Company company);

Department findByUserId(Long userId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package kusitms.server.domain.tumbler.current.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import kusitms.server.domain.common.dto.SuccessResponse;
import kusitms.server.domain.common.dto.code.SuccessCode;
import kusitms.server.domain.tumbler.current.dto.request.MainRequestDto;
import kusitms.server.domain.tumbler.current.dto.response.MainResponseDto;
import kusitms.server.domain.tumbler.current.service.TumblerCurrentService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Tag(name = "부서 메인 API", description = "부서 메인 조회 API")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/tumblers/current")
public class TumblerCurrentController {

private final TumblerCurrentService tumblerCurrentService;

@Operation(summary = "부서 메인 조회 API", description = "부서 메인 조회하기")
@ApiResponse(responseCode = "200", description = "OK",
content = @Content(schema = @Schema(implementation = MainResponseDto.class)))
@GetMapping("/{userId}")
public ResponseEntity<SuccessResponse<MainResponseDto>> getTumblerCurrent(@PathVariable Long userId) {
MainResponseDto response = tumblerCurrentService.getTumblerCurrent(userId);
return SuccessResponse.of(SuccessCode.OK, response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package kusitms.server.domain.tumbler.current.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@Getter
@Schema(description = "부서 메인 조회 요청 객체")
public class MainRequestDto {

@Schema(description = "유저 ID", example = "1")
private Long userId;

// @Schema(description = "유저 소속", example = "DEPARTMENT")
// private String userRole; // COMPANY, DEPARTMENT, CAFE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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 = "부서 메인 조회 응답 객체")
public class MainResponseDto {

@Schema(description = "이번달 부서별 텀블러 등급", example = "1")
private Integer tumblerGrade;

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

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

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

@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, 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
@@ -1,8 +1,11 @@
package kusitms.server.domain.tumbler.current.repository;

import kusitms.server.domain.department.entity.Department;
import kusitms.server.domain.tumbler.current.entity.TumblerCurrent;
import org.springframework.data.jpa.repository.JpaRepository;

public interface TumblerCurrentRepository extends JpaRepository<TumblerCurrent, Long> {

TumblerCurrent findByDepartment(Department department);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package kusitms.server.domain.tumbler.current.service;

import kusitms.server.domain.department.entity.Department;
import kusitms.server.domain.department.repository.DepartmentRepository;
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) {

// Long userId = mainRequestDto.getUserId();

Department department = departmentRepository.findByUserId(userId);
Long deptId = department.getId(); // 부서 id
String deptName = department.getDeptName(); // 부서명
Integer deptMemberCount = department.getMemberCount(); // 부서 사원 수

TumblerCurrent tumblerCurrent = tumblerCurrentRepository.findByDepartment(department);
String tumblerName = tumblerCurrent.getTumblerName(); // 텀블러 명
Integer tumblerGoal = tumblerCurrent.getTumblerGoal(); // 이번달 부서별 텀블러 목표 수
Integer tumblerCount = tumblerCurrent.getTumblerCount(); // 이번달 부서별 텀블러 적립 수
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;

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class UserController {

private final UserService userService;

@Operation(description = "유저 로그인", summary = "유저 로그인 하기")
@Operation(summary = "유저 로그인 API", description = "유저 로그인 하기")
@ApiResponse(responseCode = "200", description = "OK",
content = @Content(schema = @Schema(implementation = LoginResponseDto.class)))
@PostMapping("")
Expand Down

0 comments on commit 3d184c6

Please sign in to comment.