-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from Kusitms-28th-Kukathon-F/feat/22-tumbler-main
Feat/22 tumbler main
- Loading branch information
Showing
7 changed files
with
158 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/kusitms/server/domain/tumbler/current/controller/TumblerCurrentController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/kusitms/server/domain/tumbler/current/dto/request/MainRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
44 changes: 44 additions & 0 deletions
44
src/main/java/kusitms/server/domain/tumbler/current/dto/response/MainResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/java/kusitms/server/domain/tumbler/current/repository/TumblerCurrentRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/kusitms/server/domain/tumbler/current/service/TumblerCurrentService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters