-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor : ArgumentResolver -> Interceptor로 변경 #200
Changes from 8 commits
65f5ad7
cff9f6a
4c5dca7
97f1368
40b151a
45578cf
c144376
aca9fa0
4b53de1
cb4de56
3ea9b00
849c308
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.example.sinitto.common.interceptor; | ||
|
||
import com.example.sinitto.common.exception.UnauthorizedException; | ||
import com.example.sinitto.member.service.MemberTokenService; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.servlet.HandlerInterceptor; | ||
|
||
@Component | ||
public class JwtInterceptor implements HandlerInterceptor { | ||
private final MemberTokenService memberTokenService; | ||
|
||
public JwtInterceptor(MemberTokenService memberTokenService){ | ||
this.memberTokenService = memberTokenService; | ||
} | ||
@Override | ||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler){ | ||
String authorizationHeader = request.getHeader("Authorization"); | ||
if (authorizationHeader == null || !authorizationHeader.startsWith("Bearer ")) { | ||
throw new UnauthorizedException("토큰이 없거나, 헤더 형식에 맞지 않습니다."); | ||
} | ||
|
||
String token = authorizationHeader.substring(7); | ||
|
||
request.setAttribute("memberId", memberTokenService.getMemberIdByToken(token)); | ||
|
||
return true; | ||
} | ||
} |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
package com.example.sinitto.guard.controller; | ||
|
||
import com.example.sinitto.common.annotation.MemberId; | ||
import com.example.sinitto.guard.dto.GuardRequest; | ||
import com.example.sinitto.guard.dto.GuardResponse; | ||
import com.example.sinitto.guard.dto.SeniorRequest; | ||
|
@@ -25,61 +24,61 @@ public GuardController(GuardService guardService) { | |
|
||
@Operation(summary = "연결된 모든 시니어 정보 조회", description = "보호자가 등록한 모든 시니어의 정보를 요청합니다.") | ||
@GetMapping("/senior") | ||
public ResponseEntity<List<SeniorResponse>> getAllSeniors(@MemberId Long memberId) { | ||
public ResponseEntity<List<SeniorResponse>> getAllSeniors(@RequestAttribute("memberId") Long memberId) { | ||
return ResponseEntity.ok(guardService.readSeniors(memberId)); | ||
} | ||
|
||
@Operation(summary = "연결된 특정 시니어 정보 조회", description = "보호자가 등록한 특정 시니어의 정보를 요청합니다.") | ||
@GetMapping("/senior/{seniorId}") | ||
public ResponseEntity<SeniorResponse> getSenior(@MemberId Long memberId, @PathVariable Long seniorId) { | ||
public ResponseEntity<SeniorResponse> getSenior(@RequestAttribute("memberId") Long memberId, @PathVariable Long seniorId) { | ||
return ResponseEntity.ok(guardService.readOneSenior(memberId, seniorId)); | ||
} | ||
|
||
@Operation(summary = "시니어 정보 수정", description = "시니어의 정보를 수정합니다.") | ||
@PutMapping("/senior/{seniorId}") | ||
public ResponseEntity<String> updateSenior(@MemberId Long memberId, @PathVariable Long seniorId, @RequestBody SeniorRequest seniorRequest) { | ||
public ResponseEntity<String> updateSenior(@RequestAttribute("memberId") Long memberId, @PathVariable Long seniorId, @RequestBody SeniorRequest seniorRequest) { | ||
guardService.updateSenior(memberId, seniorId, seniorRequest); | ||
return ResponseEntity.ok("시니어 정보가 수정되었습니다."); | ||
} | ||
|
||
@Operation(summary = "시니어 추가", description = "보호자가 새로운 시니어를 등록합니다.") | ||
@PostMapping("/senior") | ||
public ResponseEntity<String> createSenior(@MemberId Long memberId, @RequestBody SeniorRequest seniorRequest) { | ||
public ResponseEntity<String> createSenior(@RequestAttribute("memberId") Long memberId, @RequestBody SeniorRequest seniorRequest) { | ||
guardService.createSenior(memberId, seniorRequest); | ||
return ResponseEntity.ok("새로운 시니어가 등록되었습니다."); | ||
} | ||
|
||
@Operation(summary = "시니어 삭제", description = "보호자가 시니어를 등록 해제합니다.") | ||
@DeleteMapping("/senior/{seniorId}") | ||
public ResponseEntity<String> deleteSenior(@MemberId Long memberId, @PathVariable Long seniorId) { | ||
public ResponseEntity<String> deleteSenior(@RequestAttribute("memberId") Long memberId, @PathVariable Long seniorId) { | ||
guardService.deleteSenior(memberId, seniorId); | ||
return ResponseEntity.ok("시니어가 삭제되었습니다."); | ||
} | ||
|
||
@Operation(summary = "보호자 본인 정보 조회", description = "보호자의 본인 정보를 조회합니다.") | ||
@GetMapping | ||
public ResponseEntity<GuardResponse> getGuardInfo(@MemberId Long memberId) { | ||
public ResponseEntity<GuardResponse> getGuardInfo(@RequestAttribute("memberId") Long memberId) { | ||
return ResponseEntity.ok(guardService.readGuard(memberId)); | ||
} | ||
|
||
@Operation(summary = "보호자 본인 정보 수정", description = "보호자의 본인 정보를 수정합니다.") | ||
@PutMapping | ||
public ResponseEntity<String> updateGuardInfo(@MemberId Long memberId, @RequestBody GuardRequest guardRequest) { | ||
public ResponseEntity<String> updateGuardInfo(@RequestAttribute("memberId") Long memberId, @RequestBody GuardRequest guardRequest) { | ||
guardService.updateGuard(memberId, guardRequest); | ||
return ResponseEntity.ok("보호자 정보가 수정되었습니다."); | ||
} | ||
|
||
// 현재는 jwt 안의 id를 삭제하게 구현했는데, 나중에 관리자 계정 만들면 특정 id 지정해서 삭제하게 수정해야할 듯합니다. | ||
@Operation(summary = "보호자 삭제", description = "관리자용 API입니다.") | ||
@DeleteMapping | ||
public ResponseEntity<String> deleteGuard(@MemberId Long memberId) { | ||
public ResponseEntity<String> deleteGuard(@RequestAttribute("memberId") Long memberId) { | ||
guardService.deleteGuard(memberId); | ||
return ResponseEntity.ok("보호자가 삭제되었습니다."); | ||
} | ||
|
||
@Operation(summary = "모든 보호자 조회", description = "관리자용 API입니다.") | ||
@GetMapping("/all") | ||
public ResponseEntity<List<GuardResponse>> getAllGuards(@MemberId Long memberId) { | ||
public ResponseEntity<List<GuardResponse>> getAllGuards(@RequestAttribute("memberId") Long memberId) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 메서드에서는 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 관리자용은 나중에 따로 보안을 적용해서 제거하는게 옳다고 생각하지만, HelloCallController에 있는 memberId의 경우 제거했을 때 회원이 아니어도 조회가 가능하다고 생각되어 일단 남겨두겠습니다! |
||
return ResponseEntity.ok(guardService.readAllGuards()); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
콜백, 포인트 관련해서는 이상없이 잘 제외해주신거 같습니다!