Skip to content

Commit

Permalink
Merge pull request #88 from team9502/feature/point
Browse files Browse the repository at this point in the history
feat: ํฌ์ธํŠธ ์ด์•ก ๋‚ด์—ญ ์กฐํšŒ์‹œ ๋‹ค์Œ ํŽ˜์ด์ง€ ์—ฌ๋ถ€ ์ถ”๊ฐ€
  • Loading branch information
EUNCHAEv1006 authored Jun 16, 2024
2 parents b74f054 + d86240f commit f672358
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import team9502.sinchulgwinong.domain.point.dto.response.PagedResponseDTO;
import team9502.sinchulgwinong.domain.point.dto.response.PointSummaryResponseDTO;
import team9502.sinchulgwinong.domain.point.dto.response.SavedPointDetailResponseDTO;
import team9502.sinchulgwinong.domain.point.dto.response.UsedPointDetailResponseDTO;
import team9502.sinchulgwinong.domain.point.service.PointService;
import team9502.sinchulgwinong.global.response.GlobalApiResponse;
import team9502.sinchulgwinong.global.security.UserDetailsImpl;

import java.util.List;

import static team9502.sinchulgwinong.global.response.SuccessCode.*;

@RestController
Expand Down Expand Up @@ -66,7 +65,7 @@ public ResponseEntity<GlobalApiResponse<PointSummaryResponseDTO>> getPointSummar
@ApiResponses({
@ApiResponse(responseCode = "200", description = "ํฌ์ธํŠธ ์ ๋ฆฝ ๋‚ด์—ญ ์กฐํšŒ ์„ฑ๊ณต",
content = @Content(mediaType = "application/json",
examples = @ExampleObject(value = "{ \"code\": \"200\", \"message\": \"์ ๋ฆฝ ํฌ์ธํŠธ ์กฐํšŒ ์„ฑ๊ณต\", \"data\": [{\"type\": \"REVIEW\", \"savedPoint\": 300, \"createdAt\": \"2024-06-11\"}, {\"type\": \"SIGNUP\", \"savedPoint\": 300, \"createdAt\": \"2024-06-11\"}] }"))),
examples = @ExampleObject(value = "{ \"code\": \"200\", \"message\": \"์ ๋ฆฝ ํฌ์ธํŠธ ์กฐํšŒ ์„ฑ๊ณต\", \"data\": [{\"type\": \"REVIEW\", \"savedPoint\": 300, \"createdAt\": \"2024-06-11\"}, {\"type\": \"SIGNUP\", \"savedPoint\": 300, \"createdAt\": \"2024-06-11\", \"hasNextPage\": false}] }"))),
@ApiResponse(responseCode = "404", description = "ํฌ์ธํŠธ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.",
content = @Content(mediaType = "application/json",
examples = @ExampleObject(value = "{ \"code\": \"404\", \"message\": \"ํฌ์ธํŠธ๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.\", \"data\": null }"))),
Expand All @@ -86,7 +85,7 @@ public ResponseEntity<GlobalApiResponse<PointSummaryResponseDTO>> getPointSummar
required = false,
schema = @Schema(type = "integer", defaultValue = "6")
)
public ResponseEntity<GlobalApiResponse<List<SavedPointDetailResponseDTO>>> getPointDetails(
public ResponseEntity<GlobalApiResponse<PagedResponseDTO<SavedPointDetailResponseDTO>>> getPointDetails(
@AuthenticationPrincipal UserDetailsImpl userDetails,
@RequestParam(value = "cursorId", required = false) Long cursorId,
@RequestParam(value = "limit", defaultValue = "6") int limit) {
Expand All @@ -95,7 +94,7 @@ public ResponseEntity<GlobalApiResponse<List<SavedPointDetailResponseDTO>>> getP
cursorId = Long.MAX_VALUE;
}

List<SavedPointDetailResponseDTO> responseDTOs = pointService.getSpDetails(userDetails, cursorId, limit);
PagedResponseDTO<SavedPointDetailResponseDTO> responseDTOs = pointService.getSpDetails(userDetails, cursorId, limit);

return ResponseEntity.status(SUCCESS_SAVED_POINT_READ.getHttpStatus())
.body(
Expand Down Expand Up @@ -129,7 +128,7 @@ public ResponseEntity<GlobalApiResponse<List<SavedPointDetailResponseDTO>>> getP
@ApiResponse(responseCode = "200", description = "ํฌ์ธํŠธ ์‚ฌ์šฉ ๋‚ด์—ญ ์กฐํšŒ ์„ฑ๊ณต",
content = @Content(mediaType = "application/json",
examples = @ExampleObject(
value = "{ \"code\": \"200\", \"message\": \"ํฌ์ธํŠธ ์‚ฌ์šฉ ๋‚ด์—ญ ์กฐํšŒ ์„ฑ๊ณต\", \"data\": [{\"type\": \"REVIEW\", \"usedPoint\": 100, \"usedAt\": \"2024-06-11\"}, {\"type\": \"BANNER\", \"usedPoint\": 50, \"usedAt\": \"2024-06-10\"}] }"
value = "{ \"code\": \"200\", \"message\": \"ํฌ์ธํŠธ ์‚ฌ์šฉ ๋‚ด์—ญ ์กฐํšŒ ์„ฑ๊ณต\", \"data\": [{\"type\": \"REVIEW\", \"usedPoint\": 100, \"usedAt\": \"2024-06-11\", \"hasNextPage\": true}, {\"type\": \"BANNER\", \"usedPoint\": 50, \"usedAt\": \"2024-06-10\", \"hasNextPage\": false}] }"
)
)
),
Expand All @@ -144,7 +143,7 @@ public ResponseEntity<GlobalApiResponse<List<SavedPointDetailResponseDTO>>> getP
)
)
})
public ResponseEntity<GlobalApiResponse<List<UsedPointDetailResponseDTO>>> getUsedPointDetails(
public ResponseEntity<GlobalApiResponse<PagedResponseDTO<UsedPointDetailResponseDTO>>> getUsedPointDetails(
@AuthenticationPrincipal UserDetailsImpl userDetails,
@RequestParam(value = "cursorId", required = false) Long cursorId,
@RequestParam(value = "limit", defaultValue = "6") int limit) {
Expand All @@ -153,7 +152,7 @@ public ResponseEntity<GlobalApiResponse<List<UsedPointDetailResponseDTO>>> getUs
cursorId = Long.MAX_VALUE;
}

List<UsedPointDetailResponseDTO> responseDTOs = pointService.getUpDetails(userDetails, cursorId, limit);
PagedResponseDTO<UsedPointDetailResponseDTO> responseDTOs = pointService.getUpDetails(userDetails, cursorId, limit);

return ResponseEntity.status(SUCCESS_USED_POINT_READ.getHttpStatus())
.body(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package team9502.sinchulgwinong.domain.point.dto.response;

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

import java.util.List;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public class PagedResponseDTO<T> {

private List<T> data;

@Schema(description = "๋‹ค์Œ ํŽ˜์ด์ง€ ์กด์žฌ ์—ฌ๋ถ€", example = "true")
private boolean hasNextPage;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import team9502.sinchulgwinong.domain.companyUser.entity.CompanyUser;
import team9502.sinchulgwinong.domain.companyUser.repository.CompanyUserRepository;
import team9502.sinchulgwinong.domain.point.CommonPoint;
import team9502.sinchulgwinong.domain.point.dto.response.PagedResponseDTO;
import team9502.sinchulgwinong.domain.point.dto.response.PointSummaryResponseDTO;
import team9502.sinchulgwinong.domain.point.dto.response.SavedPointDetailResponseDTO;
import team9502.sinchulgwinong.domain.point.dto.response.UsedPointDetailResponseDTO;
Expand All @@ -18,7 +18,6 @@
import team9502.sinchulgwinong.domain.point.repository.SavedPointRepository;
import team9502.sinchulgwinong.domain.point.repository.UsedPointRepository;
import team9502.sinchulgwinong.domain.user.entity.User;
import team9502.sinchulgwinong.domain.user.repository.UserRepository;
import team9502.sinchulgwinong.global.exception.ApiException;
import team9502.sinchulgwinong.global.exception.ErrorCode;
import team9502.sinchulgwinong.global.security.UserDetailsImpl;
Expand All @@ -30,8 +29,6 @@
@RequiredArgsConstructor
public class PointService {

private final UserRepository userRepository;
private final CompanyUserRepository companyUserRepository;
private final PointRepository pointRepository;
private final SavedPointRepository savedPointRepository;
private final UsedPointRepository usedPointRepository;
Expand Down Expand Up @@ -137,33 +134,47 @@ public PointSummaryResponseDTO getPointSummary(UserDetailsImpl userDetails) {
}

@Transactional(readOnly = true)
public List<SavedPointDetailResponseDTO> getSpDetails(UserDetailsImpl userDetails, Long cursorId, int limit) throws ApiException {
public PagedResponseDTO<SavedPointDetailResponseDTO> getSpDetails(UserDetailsImpl userDetails, Long cursorId, int limit) throws ApiException {

Long pointId = getPointId(userDetails);

if (cursorId == null) {
cursorId = Long.MAX_VALUE;
}
List<SavedPoint> savedPoints = savedPointRepository.findSavedPointsWithCursor(pointId, cursorId, limit);
List<SavedPoint> savedPoints = savedPointRepository.findSavedPointsWithCursor(pointId, cursorId, limit + 1);
boolean hasNextPage = savedPoints.size() > limit;

return savedPoints.stream()
if (hasNextPage) {
savedPoints.remove(savedPoints.size() - 1);
}

List<SavedPointDetailResponseDTO> dtoList = savedPoints.stream()
.map(sp -> new SavedPointDetailResponseDTO(sp.getSpType(), sp.getSpAmount(), sp.getCreatedAt().toLocalDate()))
.collect(Collectors.toList());

return new PagedResponseDTO<>(dtoList, hasNextPage);
}

@Transactional(readOnly = true)
public List<UsedPointDetailResponseDTO> getUpDetails(UserDetailsImpl userDetails, Long cursorId, int limit) throws ApiException {
public PagedResponseDTO<UsedPointDetailResponseDTO> getUpDetails(UserDetailsImpl userDetails, Long cursorId, int limit) throws ApiException {

Long pointId = getPointId(userDetails);

if (cursorId == null) {
cursorId = Long.MAX_VALUE;
}
List<UsedPoint> usedPoints = usedPointRepository.findUsedPointsWithCursor(pointId, cursorId, limit);
List<UsedPoint> usedPoints = usedPointRepository.findUsedPointsWithCursor(pointId, cursorId, limit + 1);
boolean hasNextPage = usedPoints.size() > limit;

return usedPoints.stream()
if (hasNextPage) {
usedPoints.remove(usedPoints.size() - 1);
}

List<UsedPointDetailResponseDTO> dtoList = usedPoints.stream()
.map(up -> new UsedPointDetailResponseDTO(up.getUpType(), up.getUpAmount(), up.getCreatedAt().toLocalDate()))
.collect(Collectors.toList());

return new PagedResponseDTO<>(dtoList, hasNextPage);
}

/*
Expand Down

0 comments on commit f672358

Please sign in to comment.