Skip to content

Feat/week/4#31

Open
tomchaccom wants to merge 20 commits intoApptiveDev:김명성from
tomchaccom:week3
Open

Feat/week/4#31
tomchaccom wants to merge 20 commits intoApptiveDev:김명성from
tomchaccom:week3

Conversation

@tomchaccom
Copy link
Copy Markdown

변경점 👍

  • JWT 인증 인터셉터 추가 (로그인, 회원가입만 허용)
  • 피드백 반영(좋아요 로직 변경, 생성자 변경, 변경감지로 엔티티 저장)
  • validation 에러 메시지 구체화(추상화되어 있어 어느 필드에서 문제가 발생하는지 알기 힘들었음)

버그 해결 💊

  • 스프링 시큐리티 의존성 등록 후 인터셉터 동작시, 요청이 DispatcherServlet에 도달했음에도 401 에러가 발생되었음
    -> SecurityConfig를 추가해서 login 리다이렉트 방지 후 인터셉터 적용

  • JWT_SECRET을 등록하는 과정에서 .env에 입력해둔 JWT_SECRET을 @value가 읽지 못하는 문제발생
    -> dotenv-java 의존성을 통해서 변수를 읽고 할당하도록 설정

스크린샷 🖼

회원가입

image

로그인

image

토큰 없이 API 요청했을 경우

image

토큰을 가지고 요청

image

@tomchaccom tomchaccom changed the title Week3 feat : week 4 Nov 27, 2025
@tomchaccom tomchaccom requested a review from sinsehwan November 27, 2025 13:40
@tomchaccom tomchaccom self-assigned this Nov 27, 2025
@tomchaccom tomchaccom changed the title feat : week 4 Feat/Week/4 Nov 27, 2025
@tomchaccom tomchaccom changed the title Feat/Week/4 Feat/week/4 Nov 27, 2025
Copy link
Copy Markdown
Contributor

@sinsehwan sinsehwan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다! 기본적인 백엔드 개발 흐름을 잘 이해하고 계신 것 같네요 고민의 흔적들이 보여서 좋았습니다. 그동안 고생하셨습니다!

Comment on lines -64 to +67
return ResponseEntity.status(HttpStatus.OK).body(commentService.getCommentById(post_id, comment_id));
return ResponseEntity.ok(commentService.getCommentById(post_id, comment_id));

}catch (EntityNotFoundException e){
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
return ResponseEntity.notFound().build();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

피드백 반영 좋습니다!

Comment on lines +14 to +19
@Table(
name = "heart",
indexes = {
@Index(name ="idx_heart_post_liked", columnList = "post_id , like_status")
}
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분 생각을 좀 더 해봤는데, Heart 엔티티의 liked속성이 false라면 튜플이 존재하지 않는 상태랑 차이가 없을 것 같아요 그리고 index의 경우 속성이 중복되지 않을수록 이점이 큰데 현재는 like속성도 사실상 boolean이라 상태가 2가지밖에 없네요 그래서 제 생각에는 index를 아예 없애버리고 heart 객체가 존재 -> 좋아요, heart 객체가 없음 -> 좋아요 x 이렇게 구성하면 토글 로직도 간단하게 떨어질 것 같아요

Comment on lines +14 to +19
private final String secret;// 실제 프로젝트에서는 환경변수로 관리
private final long EXPIRATION = 1000L * 60 * 60; // 1시간

public JwtUtil(@Value("${jwt.secret}") String secret) {
this.secret = secret;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

잘 구성해주셨네요! 다만 현재 구조에서는 1시간마다 재인증 해야 하는 구조라 리프레시 토큰도 추후에 도입해보면 좋을 것 같습니다!

Comment on lines +12 to +16
@NotBlank(message = "이메일은 공백 또는 null 값은 허용하지 않습니다")
@Email(message ="올바른 이메일 양식이 아닙니다")
String email,

@NotBlank(message = "공백 또는 null 값은 허용하지 않습니다")
@NotBlank(message = "비밀번호는 공백 또는 null 값은 허용하지 않습니다")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋습니다! message 옵션 상세히 적어둬야 나중에 프론트분들과 협업할 때 좋은 것 같더라고요

Comment on lines +18 to +22
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response,
Object handler) throws Exception {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

인터셉터 도입 및 preHandle 적용 좋습니다!


// then
verify(postRepository).findAll();
verify(heartRepository, times(2)).countByPostIdAndLike(anyLong(), eq(LikeStatus.LIKE));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트코드 업데이트 좋습니다! 인증/인가 쪽 테스트 코드도 작성해보시면 좋을 것 같아요

@tomchaccom
Copy link
Copy Markdown
Author

고생하셨습니다! 기본적인 백엔드 개발 흐름을 잘 이해하고 계신 것 같네요 고민의 흔적들이 보여서 좋았습니다. 그동안 고생하셨습니다!

스터디 기간동안 친절하게 알려주셔서 감사합니다! 그동안 고생 많으셨습니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants