Skip to content

Commit

Permalink
Feat: 회원 적립금 조회(#38)
Browse files Browse the repository at this point in the history
close: #38
  • Loading branch information
mummhy0811 committed May 8, 2024
1 parent a06c5d2 commit add06ae
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/hanaro/starbucks/dto/member/PointResDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.hanaro.starbucks.dto.member;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class PointResDto {
private int point;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,4 +13,7 @@
public interface MemberRepository extends JpaRepository<Member, Integer> {
Optional<Member> 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);
}
8 changes: 8 additions & 0 deletions src/main/java/com/hanaro/starbucks/service/MemberService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}
}

0 comments on commit add06ae

Please sign in to comment.