Skip to content

Commit

Permalink
feat: #89 회원 식별 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
hydrationn committed May 15, 2024
1 parent 129aa84 commit c01fff1
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.t3t.frontserver.pointdetail.adaptor;

import com.t3t.frontserver.auth.util.SecurityContextUtils;
import com.t3t.frontserver.common.exception.ApiDataFetchException;
import com.t3t.frontserver.model.response.BaseResponse;
import com.t3t.frontserver.pointdetail.client.UserPointDetailApiClient;
import com.t3t.frontserver.pointdetail.model.response.PointDetailResponse;
import feign.FeignException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;

@Slf4j
@Component
@RequiredArgsConstructor
public class UserPointDetailAdaptor {
private final UserPointDetailApiClient userPointDetailApiClient;

public List<PointDetailResponse> getPointDetailByPointDetailType(Long memberId, String pointDetailType) {
try {
ResponseEntity<BaseResponse<List<PointDetailResponse>>> response = userPointDetailApiClient.getPointDetailByPointDetailType(memberId, pointDetailType);
if (response.getStatusCode() == HttpStatus.OK) {
return Objects.requireNonNull(response.getBody()).getData();
}
return null;
} catch (FeignException e) {
log.error(e.getMessage());
throw new ApiDataFetchException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public interface UserPointDetailApiClient {
* @param pointDetailType 조회할 포인트 타입(사용/적립)
* @author hydrationn(박수화)
*/
@GetMapping("/t3t/bookstore/mypage/point-details")
public ResponseEntity<BaseResponse<List<PointDetailResponse>>> getPointDetailByPointDetailType(@RequestParam(name = "pointDetailType", required = false) String pointDetailType);
@GetMapping("/t3t/bookstore/member/{memberId}/point-details")
ResponseEntity<BaseResponse<List<PointDetailResponse>>> getPointDetailByPointDetailType(@PathVariable("memberId") Long memberId,
@RequestParam(name = "pointDetailType", required = false) String pointDetailType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.t3t.frontserver.model.response.BaseResponse;
import com.t3t.frontserver.pointdetail.client.UserPointDetailApiClient;
import com.t3t.frontserver.pointdetail.model.response.PointDetailResponse;
import com.t3t.frontserver.pointdetail.service.UserPointDetailService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
Expand All @@ -18,7 +19,7 @@
@Controller
@RequiredArgsConstructor
public class UserPointDetailController {
private final UserPointDetailApiClient userPointDetailApiClient;
private final UserPointDetailService userPointDetailService;

/**
* 회원 포인트 사용/적립 내역 페이지 뷰 반환
Expand All @@ -33,20 +34,9 @@ public String pointDetailView(Model model, @Valid @RequestParam(value = "pointDe
return "redirect:/login";
}

ResponseEntity<BaseResponse<List<PointDetailResponse>>> response = userPointDetailApiClient.getPointDetailByPointDetailType(pointDetailType); // 모든 내역을 가져오는 API 호출
Long memberId = SecurityContextUtils.getMemberId();

List<PointDetailResponse> pointDetails;

if (pointDetailType == null) {
// parameter가 null인 경우 모든 내역 반환
pointDetails = Objects.requireNonNull(response.getBody()).getData();
} else {
// pointDetailType(used, saved)에 해당하는 내역만 반환
pointDetails = Objects.requireNonNull(response.getBody()).getData()
.stream()
.filter(pointDetail -> pointDetail.getPointDetailType().equals(pointDetailType))
.collect(Collectors.toList());
}
List<PointDetailResponse> pointDetails = userPointDetailService.getPointDetailByPointDetailType(memberId, pointDetailType); // 모든 내역을 가져오는 API 호출

model.addAttribute("pointDetails", pointDetails);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.t3t.frontserver.pointdetail.service;

import com.t3t.frontserver.auth.util.SecurityContextUtils;
import com.t3t.frontserver.pointdetail.adaptor.UserPointDetailAdaptor;
import com.t3t.frontserver.pointdetail.model.response.PointDetailResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class UserPointDetailService {
private final UserPointDetailAdaptor userPointDetailAdaptor;

public List<PointDetailResponse> getPointDetailByPointDetailType(Long memberId, String pointDetailType) {
return userPointDetailAdaptor.getPointDetailByPointDetailType(memberId, pointDetailType);
}
}

0 comments on commit c01fff1

Please sign in to comment.