From add06ae52990c946207974ea9bdf4a5ad85ae999 Mon Sep 17 00:00:00 2001 From: mummhy0811 Date: Wed, 8 May 2024 13:35:52 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20=ED=9A=8C=EC=9B=90=20=EC=A0=81=EB=A6=BD?= =?UTF-8?q?=EA=B8=88=20=EC=A1=B0=ED=9A=8C(#38)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit close: #38 --- .../hanaro/starbucks/controller/MemberController.java | 9 +++++---- .../com/hanaro/starbucks/dto/member/PointResDto.java | 10 ++++++++++ .../hanaro/starbucks/repository/MemberRepository.java | 5 +++++ .../com/hanaro/starbucks/service/MemberService.java | 8 ++++++++ 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/hanaro/starbucks/dto/member/PointResDto.java diff --git a/src/main/java/com/hanaro/starbucks/controller/MemberController.java b/src/main/java/com/hanaro/starbucks/controller/MemberController.java index 8d73808..b739b0e 100644 --- a/src/main/java/com/hanaro/starbucks/controller/MemberController.java +++ b/src/main/java/com/hanaro/starbucks/controller/MemberController.java @@ -1,10 +1,7 @@ package com.hanaro.starbucks.controller; import com.hanaro.starbucks.config.JwtUtil; -import com.hanaro.starbucks.dto.member.LoginReqDto; -import com.hanaro.starbucks.dto.member.MemberResDto; -import com.hanaro.starbucks.dto.member.SignupReqDto; -import com.hanaro.starbucks.dto.member.MemberUpdateReqDto; +import com.hanaro.starbucks.dto.member.*; import com.hanaro.starbucks.service.MemberService; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -65,4 +62,8 @@ public void deleteUser(@PathVariable int userIdx){ memberService.deleteUser(userIdx); } + @GetMapping("/{userIdx}/points") + public PointResDto getUserPoint(@PathVariable int userIdx){ + return memberService.getUserPoint(userIdx); + } } diff --git a/src/main/java/com/hanaro/starbucks/dto/member/PointResDto.java b/src/main/java/com/hanaro/starbucks/dto/member/PointResDto.java new file mode 100644 index 0000000..65147e4 --- /dev/null +++ b/src/main/java/com/hanaro/starbucks/dto/member/PointResDto.java @@ -0,0 +1,10 @@ +package com.hanaro.starbucks.dto.member; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class PointResDto { + private int point; +} diff --git a/src/main/java/com/hanaro/starbucks/repository/MemberRepository.java b/src/main/java/com/hanaro/starbucks/repository/MemberRepository.java index 816c268..2febbaa 100644 --- a/src/main/java/com/hanaro/starbucks/repository/MemberRepository.java +++ b/src/main/java/com/hanaro/starbucks/repository/MemberRepository.java @@ -1,7 +1,9 @@ package com.hanaro.starbucks.repository; +import com.hanaro.starbucks.dto.member.PointResDto; import com.hanaro.starbucks.entity.Member; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; import java.util.List; @@ -11,4 +13,7 @@ public interface MemberRepository extends JpaRepository { Optional findByUserId(String userId); boolean existsByUserId(String userId); + + @Query("Select new com.hanaro.starbucks.dto.member.PointResDto(m.userPoint) from Member m where m.userIdx = :userIdx") + PointResDto findPointByUserIdx(int userIdx); } diff --git a/src/main/java/com/hanaro/starbucks/service/MemberService.java b/src/main/java/com/hanaro/starbucks/service/MemberService.java index ef478b3..9891c94 100644 --- a/src/main/java/com/hanaro/starbucks/service/MemberService.java +++ b/src/main/java/com/hanaro/starbucks/service/MemberService.java @@ -1,6 +1,7 @@ package com.hanaro.starbucks.service; import com.hanaro.starbucks.dto.member.MemberResDto; +import com.hanaro.starbucks.dto.member.PointResDto; import com.hanaro.starbucks.dto.member.SignupReqDto; import com.hanaro.starbucks.dto.member.MemberUpdateReqDto; import com.hanaro.starbucks.entity.Member; @@ -81,4 +82,11 @@ public void updateUser(int userIdx, MemberUpdateReqDto user){ public void deleteUser(int userIdx){ memberRepository.deleteById(userIdx); } + public PointResDto getUserPoint(int userIdx){ + PointResDto dto = memberRepository.findPointByUserIdx(userIdx); + if(dto==null){ + throw new IllegalArgumentException("존재하지 않는 회원입니다."); + } + return dto; + } }