From 01bc392bca730d5943634267e57e7b32237314dc Mon Sep 17 00:00:00 2001 From: hojeong2747 Date: Sun, 8 Oct 2023 01:22:32 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=EB=B6=80=EC=84=9C=20=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EC=A1=B0=ED=9A=8C=20=EC=9A=94=EC=B2=AD/=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=20DTO=20=EC=83=9D=EC=84=B1=20(#22)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../current/dto/request/MainRequestDto.java | 17 +++++++++ .../current/dto/response/MainResponseDto.java | 36 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 src/main/java/kusitms/server/domain/tumbler/current/dto/request/MainRequestDto.java create mode 100644 src/main/java/kusitms/server/domain/tumbler/current/dto/response/MainResponseDto.java diff --git a/src/main/java/kusitms/server/domain/tumbler/current/dto/request/MainRequestDto.java b/src/main/java/kusitms/server/domain/tumbler/current/dto/request/MainRequestDto.java new file mode 100644 index 0000000..ea77dc1 --- /dev/null +++ b/src/main/java/kusitms/server/domain/tumbler/current/dto/request/MainRequestDto.java @@ -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 +} diff --git a/src/main/java/kusitms/server/domain/tumbler/current/dto/response/MainResponseDto.java b/src/main/java/kusitms/server/domain/tumbler/current/dto/response/MainResponseDto.java new file mode 100644 index 0000000..ed4cfdf --- /dev/null +++ b/src/main/java/kusitms/server/domain/tumbler/current/dto/response/MainResponseDto.java @@ -0,0 +1,36 @@ +package kusitms.server.domain.tumbler.current.dto.response; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@Getter +@Schema(description = "부서 메인 조회 응답 객체") +public class MainResponseDto { + + @Schema(description = "이번달 부서별 텀블러 등급", example = "1") + private Integer tumblerGrade; + + @Schema(description = "이번달 부서별 텀블러 명", example = "") + private String tumblerName; + + @Schema(description = "부서명", example = "") + private String deptName; + + @Schema(description = "이번달 부서별 텀블러 퍼센트", example = "") + private Double tumblerPercent; + + @Schema(description = "이번달 목표 수 - 현재 적립 수", example = "") + private Integer toGoalCount; + + @Builder + public MainResponseDto(Integer tumblerGrade, String tumblerName, String deptName, Double tumblerPercent, Integer toGoalCount) { + this.tumblerGrade = tumblerGrade; + this.tumblerName = tumblerName; + this.deptName = deptName; + this.tumblerPercent = tumblerPercent; + this.toGoalCount = toGoalCount; + } +} From 56586b11a1d6a9b3043a053d3ad781e754f9c429 Mon Sep 17 00:00:00 2001 From: hojeong2747 Date: Sun, 8 Oct 2023 01:23:26 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=EB=B6=80=EC=84=9C=20=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EC=A1=B0=ED=9A=8C=20API=20=EA=B5=AC=ED=98=84=20(#2?= =?UTF-8?q?2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/DepartmentRepository.java | 2 + .../controller/TumblerCurrentController.java | 33 ++++++++++++ .../repository/TumblerCurrentRepository.java | 3 ++ .../service/TumblerCurrentService.java | 50 +++++++++++++++++++ .../user/controller/UserController.java | 2 +- 5 files changed, 89 insertions(+), 1 deletion(-) create mode 100644 src/main/java/kusitms/server/domain/tumbler/current/controller/TumblerCurrentController.java create mode 100644 src/main/java/kusitms/server/domain/tumbler/current/service/TumblerCurrentService.java diff --git a/src/main/java/kusitms/server/domain/department/repository/DepartmentRepository.java b/src/main/java/kusitms/server/domain/department/repository/DepartmentRepository.java index 596ed27..e1a1dc0 100644 --- a/src/main/java/kusitms/server/domain/department/repository/DepartmentRepository.java +++ b/src/main/java/kusitms/server/domain/department/repository/DepartmentRepository.java @@ -12,4 +12,6 @@ public interface DepartmentRepository extends JpaRepository { Optional findByUser(User user); List findAllByCompany(Company company); + + Department findByUserId(Long userId); } diff --git a/src/main/java/kusitms/server/domain/tumbler/current/controller/TumblerCurrentController.java b/src/main/java/kusitms/server/domain/tumbler/current/controller/TumblerCurrentController.java new file mode 100644 index 0000000..14b63a8 --- /dev/null +++ b/src/main/java/kusitms/server/domain/tumbler/current/controller/TumblerCurrentController.java @@ -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> getTumblerCurrent(@PathVariable Long userId) { + MainResponseDto response = tumblerCurrentService.getTumblerCurrent(userId); + return SuccessResponse.of(SuccessCode.OK, response); + } +} diff --git a/src/main/java/kusitms/server/domain/tumbler/current/repository/TumblerCurrentRepository.java b/src/main/java/kusitms/server/domain/tumbler/current/repository/TumblerCurrentRepository.java index eaf8f40..07231d9 100644 --- a/src/main/java/kusitms/server/domain/tumbler/current/repository/TumblerCurrentRepository.java +++ b/src/main/java/kusitms/server/domain/tumbler/current/repository/TumblerCurrentRepository.java @@ -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 findByDepartment(Department department); + } diff --git a/src/main/java/kusitms/server/domain/tumbler/current/service/TumblerCurrentService.java b/src/main/java/kusitms/server/domain/tumbler/current/service/TumblerCurrentService.java new file mode 100644 index 0000000..7a5e6dc --- /dev/null +++ b/src/main/java/kusitms/server/domain/tumbler/current/service/TumblerCurrentService.java @@ -0,0 +1,50 @@ +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.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 lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@RequiredArgsConstructor +@Service +@Transactional +public class TumblerCurrentService { + + private final DepartmentRepository departmentRepository; + private final TumblerCurrentRepository tumblerCurrentRepository; + + 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(); // 이번달 부서별 텀블러 등급 + + MainResponseDto res = MainResponseDto.builder() + .tumblerGrade(tumblerGrade) + .tumblerName(tumblerName) + .deptName(deptName) + .tumblerPercent(tumblerPercent) + .toGoalCount(tumblerGoal - tumblerCount) + .build(); + + return res; + + } + + +} diff --git a/src/main/java/kusitms/server/domain/user/controller/UserController.java b/src/main/java/kusitms/server/domain/user/controller/UserController.java index a7e021f..50e13b9 100644 --- a/src/main/java/kusitms/server/domain/user/controller/UserController.java +++ b/src/main/java/kusitms/server/domain/user/controller/UserController.java @@ -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("") From e94c1e06eebd4aafe0eca1985a77967829c66f2e Mon Sep 17 00:00:00 2001 From: hojeong2747 Date: Sun, 8 Oct 2023 02:07:10 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=EB=B6=80=EC=84=9C=20=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EC=A1=B0=ED=9A=8C=20API=20=EB=9E=AD=ED=82=B9=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20(#22)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../current/dto/response/MainResponseDto.java | 18 +++++++++++++----- .../current/service/TumblerCurrentService.java | 10 +++++++++- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/main/java/kusitms/server/domain/tumbler/current/dto/response/MainResponseDto.java b/src/main/java/kusitms/server/domain/tumbler/current/dto/response/MainResponseDto.java index ed4cfdf..4c63abf 100644 --- a/src/main/java/kusitms/server/domain/tumbler/current/dto/response/MainResponseDto.java +++ b/src/main/java/kusitms/server/domain/tumbler/current/dto/response/MainResponseDto.java @@ -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 = "부서 메인 조회 응답 객체") @@ -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 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 rankList) { this.tumblerGrade = tumblerGrade; this.tumblerName = tumblerName; this.deptName = deptName; this.tumblerPercent = tumblerPercent; this.toGoalCount = toGoalCount; + this.rankList = rankList; } } diff --git a/src/main/java/kusitms/server/domain/tumbler/current/service/TumblerCurrentService.java b/src/main/java/kusitms/server/domain/tumbler/current/service/TumblerCurrentService.java index 7a5e6dc..d128a7d 100644 --- a/src/main/java/kusitms/server/domain/tumbler/current/service/TumblerCurrentService.java +++ b/src/main/java/kusitms/server/domain/tumbler/current/service/TumblerCurrentService.java @@ -2,14 +2,18 @@ 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 @@ -17,6 +21,7 @@ public class TumblerCurrentService { private final DepartmentRepository departmentRepository; private final TumblerCurrentRepository tumblerCurrentRepository; + private final TumblerHistoryService tumblerHistoryService; public MainResponseDto getTumblerCurrent(Long userId) { @@ -34,12 +39,15 @@ public MainResponseDto getTumblerCurrent(Long userId) { Double tumblerPercent = tumblerCurrent.getTumblerPercent(); // 이번달 부서별 텀블러 퍼센트 Integer tumblerGrade = tumblerCurrent.getTumblerGrade(); // 이번달 부서별 텀블러 등급 + List 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;