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/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..4c63abf --- /dev/null +++ b/src/main/java/kusitms/server/domain/tumbler/current/dto/response/MainResponseDto.java @@ -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 rankList = new ArrayList<>(); + + @Builder + 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/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..d128a7d --- /dev/null +++ b/src/main/java/kusitms/server/domain/tumbler/current/service/TumblerCurrentService.java @@ -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 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; + + } + + +} 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("")