Skip to content

Commit

Permalink
fix: LoginUser aop 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Sangyoo committed Jan 27, 2023
1 parent c3828cb commit 36a5533
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ public ResponseEntity getMapDetails(@PathVariable(value = "member-id", required
List<Post> postList = attraction.getPosts();
AttractionMapsDetailResponseDto response
= AttractionMapsDetailResponseDto.builder()
.attractionId(attraction.getAttractionId())
.attractionName(attraction.getAttractionName())
.attractionAddress(attraction.getAttractionAddress())
.fixedImage(attraction.getFixedImage())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@Setter
@NoArgsConstructor
public class AttractionMapsDetailResponseDto {
private Long attractionId;
private String attractionName;
private String attractionAddress;
private String fixedImage;
Expand All @@ -21,7 +22,8 @@ public class AttractionMapsDetailResponseDto {


@Builder
public AttractionMapsDetailResponseDto(String attractionName, String attractionAddress, String fixedImage, Long numOfPosts, Long likes, Long saves) {
public AttractionMapsDetailResponseDto(Long attractionId, String attractionName, String attractionAddress, String fixedImage, Long numOfPosts, Long likes, Long saves) {
this.attractionId = attractionId;
this.attractionName = attractionName;
this.attractionAddress = attractionAddress;
this.fixedImage = fixedImage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public ResponseEntity<DataResponseDto<?>> patchComment(Member loginUser,
@RequestBody @Valid CommentDto.Patch commentPatchDto) {
Comment comment = commentService.verifyClientId(loginUser.getMemberId(), commentId);
comment.setCommentContent(commentPatchDto.getCommentContent());

commentService.updateComment(comment);
CommentResponseDto commentResponseDto = mapper.commentToCommentResponseDto(comment);

return ResponseEntity.ok(new DataResponseDto<>(commentResponseDto));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class CommentService {
public Comment createComment(Comment comment){
return commentRepository.save(comment);
}

public Comment updateComment(Comment comment){ return commentRepository.save(comment);}
@Transactional(readOnly = true)
public Comment findComment(long commentId){
return findVerifiedComment(commentId);
Expand Down
17 changes: 5 additions & 12 deletions server/src/main/java/com/main36/pikcha/global/aop/LoginAspect.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,25 @@ public class LoginAspect {
private final MemberService memberService;

@Around("@annotation(com.main36.pikcha.global.aop.LoginUserEmail)")
public Object getUserEmail(ProceedingJoinPoint joinPoint) {
public Object getUserEmail(ProceedingJoinPoint joinPoint) throws Throwable {

HttpServletRequest request = ((ServletRequestAttributes) requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
Object[] args = joinPoint.getArgs();
String email = jwtParser.getLoginUserEmail(request);
args[0] = email;

try {
return joinPoint.proceed(args);
} catch (Throwable e) {
throw new BusinessLogicException(ExceptionCode.TOKEN_EXPIRED);
}
return joinPoint.proceed(args);

}

@Around("@annotation(com.main36.pikcha.global.aop.LoginUser)")
public Object getUser(ProceedingJoinPoint joinPoint) {
public Object getUser(ProceedingJoinPoint joinPoint) throws Throwable {
HttpServletRequest request = ((ServletRequestAttributes) requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();

Object[] args = joinPoint.getArgs();
Member loginUser = memberService.getLoginMember(request);
args[0] = loginUser;

try {
return joinPoint.proceed(args);
} catch (Throwable e) {
throw new BusinessLogicException(ExceptionCode.TOKEN_EXPIRED);
}
return joinPoint.proceed(args);
}
}

0 comments on commit 36a5533

Please sign in to comment.