Skip to content

Commit

Permalink
fix: 회원 정보 수정, 조회
Browse files Browse the repository at this point in the history
[before] id 를 path param 으로 얻어옴
[after] jwt 을 통해 id 를 얻어옴
  • Loading branch information
versatile0010 committed Aug 5, 2023
1 parent 2e57e93 commit f2ec502
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;


@Slf4j
@RestController
Expand All @@ -27,10 +29,11 @@ public class MemberController {
"""
회원의 상태를 TERMINATED 으로 변경합니다.
- [ROLE_MEMBER OR ROLE_ADMIN]
- path variable 로 멤버 id 담아서 보내주세요!
- access token 을 반드시 포함해서 보내주세요!
""",
security = @SecurityRequirement(name = "bearerAuth"))
public BaseResponse<PatchMemberResponse> delete(@PathVariable("member-id") Long memberId) {
public BaseResponse<PatchMemberResponse> delete(Principal principal) {
Long memberId = memberService.findMemberIdByPrincipal(principal);
Member member = memberService.findOneById(memberId);
return new BaseResponse<>(memberService.delete(member));
}
Expand All @@ -41,10 +44,11 @@ public BaseResponse<PatchMemberResponse> delete(@PathVariable("member-id") Long
"""
회원 정보를 조회합니다.
- [ROLE_MEMBER OR ROLE_ADMIN]
- path variable 로 멤버 id 담아서 보내주세요!
- access token 을 반드시 포함해서 보내주세요!
""",
security = @SecurityRequirement(name = "bearerAuth"))
public BaseResponse<GetMemberResponse> show(@PathVariable("member-id") Long memberId) {
public BaseResponse<GetMemberResponse> show(Principal principal) {
Long memberId = memberService.findMemberIdByPrincipal(principal);
Member member = memberService.findOneById(memberId);
return new BaseResponse<>(memberService.getMemberInfo(member));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.security.Principal;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -214,4 +215,8 @@ public GetMemberCouponBrandsResponse getBrands(Long memberId, int option) {
return new GetMemberCouponBrandsResponse(member, brands);
}

public Long findMemberIdByPrincipal(Principal principal) {
String email = principal.getName();
return findOneByEmail(email).getId();
}
}

0 comments on commit f2ec502

Please sign in to comment.