Skip to content

Commit

Permalink
Merge pull request #143 from Team-HMH/feat/#142-get-point-status-list
Browse files Browse the repository at this point in the history
  • Loading branch information
jumining authored May 27, 2024
2 parents 371dc0b + be9b251 commit fdf9951
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 7 deletions.
21 changes: 21 additions & 0 deletions src/main/java/sopt/org/hmh/domain/point/controller/PointApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,37 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import java.time.LocalDate;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PatchMapping;
import sopt.org.hmh.domain.point.dto.response.ChallengePointStatusListResponse;
import sopt.org.hmh.domain.point.dto.response.EarnPointResponse;
import sopt.org.hmh.domain.point.dto.response.UsagePointResponse;
import sopt.org.hmh.domain.point.dto.response.UsePointResponse;
import sopt.org.hmh.domain.point.exception.PointSuccess;
import sopt.org.hmh.global.auth.UserId;
import sopt.org.hmh.global.auth.jwt.JwtConstants;
import sopt.org.hmh.global.common.response.BaseResponse;

@Tag(name = "포인트 관련 API")
@SecurityRequirement(name = JwtConstants.AUTHORIZATION)
public interface PointApi {

@Operation(
summary = "포인트 수령 여부 리스트 조회 API",
responses = {
@ApiResponse(
responseCode = "200",
description = "포인트 사용에 성공하였습니다."),
@ApiResponse(
responseCode = "400",
description = "잘못된 요청입니다.",
content = @Content),
@ApiResponse(
responseCode = "500",
description = "서버 내부 오류입니다.",
content = @Content)})
ResponseEntity<BaseResponse<ChallengePointStatusListResponse>> orderGetChallengePointStatusList(
@Parameter(hidden = true) Long userId);

@Operation(
summary = "포인트 사용 API",
responses = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package sopt.org.hmh.domain.point.controller;

import java.time.LocalDate;
import java.util.List;

import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import sopt.org.hmh.domain.point.dto.response.EarnPointResponse;
import sopt.org.hmh.domain.point.dto.response.UsagePointResponse;
import sopt.org.hmh.domain.point.dto.response.UsePointResponse;
import sopt.org.hmh.domain.challenge.domain.Challenge;
import sopt.org.hmh.domain.point.dto.response.*;
import sopt.org.hmh.domain.point.exception.PointSuccess;
import sopt.org.hmh.domain.point.service.PointFacade;
import sopt.org.hmh.global.auth.UserId;
Expand All @@ -23,6 +24,18 @@ public class PointController implements PointApi {

private final PointFacade pointFacade;

@Override
@GetMapping("/list")
public ResponseEntity<BaseResponse<ChallengePointStatusListResponse>> orderGetChallengePointStatusList(
@UserId final Long userId
) {
return ResponseEntity
.status(PointSuccess.GET_CHALLENGE_POINT_STATUS_LIST_SUCCESS.getHttpStatus())
.body(BaseResponse.success(PointSuccess.GET_CHALLENGE_POINT_STATUS_LIST_SUCCESS,
pointFacade.getChallengePointStatusList(userId)));

}

@Override
@PatchMapping("/use")
public ResponseEntity<BaseResponse<UsePointResponse>> orderUsagePointAndChallengeFailed(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package sopt.org.hmh.domain.point.dto.response;

import java.util.List;

public record ChallengePointStatusListResponse(
Integer point,
Integer period,
List<ChallengePointStatusResponse> challengePointStatuses
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package sopt.org.hmh.domain.point.dto.response;

import sopt.org.hmh.domain.dailychallenge.domain.Status;

import java.time.LocalDate;

public record ChallengePointStatusResponse(
LocalDate challengeDate,
Status status
) {
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package sopt.org.hmh.domain.point.dto.response;


public record EarnPointResponse(
Integer userPoint
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public enum PointSuccess implements SuccessBase {
POINT_USAGE_SUCCESS(HttpStatus.OK, "포인트 사용에 성공하였습니다"),
POINT_EARN_SUCCESS(HttpStatus.OK, "포인트 받기에 성공하였습니다"),
GET_USAGE_POINT_SUCCESS(HttpStatus.OK, "사용할 포인트 반환에 성공하였습니다"),
GET_CHALLENGE_POINT_STATUS_LIST_SUCCESS(HttpStatus.OK, "챌린지 포인트 수령 여부 리스트 조회에 성공하였습니다."),
;

private final HttpStatus status;
Expand Down
26 changes: 23 additions & 3 deletions src/main/java/sopt/org/hmh/domain/point/service/PointFacade.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package sopt.org.hmh.domain.point.service;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import sopt.org.hmh.domain.challenge.domain.Challenge;
import sopt.org.hmh.domain.challenge.domain.ChallengeConstants;
import sopt.org.hmh.domain.point.dto.response.EarnPointResponse;
import sopt.org.hmh.domain.challenge.service.ChallengeService;
import sopt.org.hmh.domain.point.dto.response.*;
import sopt.org.hmh.domain.dailychallenge.domain.DailyChallenge;
import sopt.org.hmh.domain.dailychallenge.domain.Status;
import sopt.org.hmh.domain.dailychallenge.service.DailyChallengeService;
import sopt.org.hmh.domain.point.dto.response.UsagePointResponse;
import sopt.org.hmh.domain.point.dto.response.UsePointResponse;
import sopt.org.hmh.domain.user.domain.User;
import sopt.org.hmh.domain.user.service.UserService;

Expand All @@ -21,6 +25,7 @@ public class PointFacade {

private final UserService userService;
private final DailyChallengeService dailyChallengeService;
private final ChallengeService challengeService;

public UsePointResponse usePointAndChallengeFailed(Long userId, LocalDate challengeDate) {
DailyChallenge dailyChallenge = dailyChallengeService.findByChallengeDateAndUserIdOrThrowException(challengeDate, userId);
Expand Down Expand Up @@ -51,4 +56,19 @@ public EarnPointResponse earnPointAndChallengeEarned(Long userId, LocalDate chal
public UsagePointResponse getUsagePoint() {
return new UsagePointResponse(ChallengeConstants.USAGE_POINT);
}

public ChallengePointStatusListResponse getChallengePointStatusList(Long userId) {
Challenge challenge = challengeService.findCurrentChallengeByUserId(userId);
List<ChallengePointStatusResponse> challengePointStatusResponseList =
challenge.getHistoryDailyChallenges().stream()
.map(dailyChallenge -> new ChallengePointStatusResponse(
dailyChallenge.getChallengeDate(),
dailyChallenge.getStatus())).toList();

return new ChallengePointStatusListResponse(
userService.getUserInfo(userId).point(),
challenge.getPeriod(),
challengePointStatusResponseList
);
}
}

0 comments on commit fdf9951

Please sign in to comment.