Skip to content
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

[BE] feat: 컨트롤러에서 리졸버를 통해 세션 저장 정보를 사용 #1094

Merged
merged 16 commits into from
Feb 14, 2025

Conversation

Kimprodp
Copy link
Contributor


🚀 어떤 기능을 구현했나요 ?

  • 요청 헤더에서 세션을 가져와서 회원/비회원 정보 객체를 생성하여 컨트롤러 파라미터로 전달하는 리졸버를 구현했습니다.
  • 리졸버 구현 후 컨트롤러에 적용하면서, 일부 api를 수정했습니다.

🔥 어떻게 해결했나요 ?

  • api 요청 시, 회원/비회원 세션이 필수 또는 선택인 경우가 존재합니다.
  • 각 리졸버(회원, 비회원)에서 요청 헤더에서 세션을 찾고, SessionManger를 통해 저장 정보를 가져옵니다.
  • 이때 세션 어노테이션이 필수이나, 세션 정보가 존재하지 않으면 예외가 발생합니다.
  • 세션 어노테이션이 필수가 아닐 경우, 세션 정보가 존재하지 않으면 null을 반환합니다.
  • 어노테이션 속성에 관계없이 세션 정보가 존재한다면, dto 객체를 생성하여 반환합니다.

여기서 Member로 생성하여 반환하지 않는 이유는, 각 도메인에서 Member를 직접적으로 사용할 필요 없이 id만을 사용하기 때문에 굳이 다른 패키지의 객체를 전송할 필요가 없다고 생각했습니다. 내부 필드가 하나여도 dto를 통해 감싸서 전달하는 것이 안전해 보입니다.

  • 수정하면서 aop 로직이 필요한 부분 TODO로 남겨놓았습니다. (산초 작업 시, 일치하는지 확인해주세요)

📝 어떤 부분에 집중해서 리뷰해야 할까요?

📚 참고 자료, 할 말

  • 이번꺼 빠르게 머지되면, 세부 구현 필요한 부분들 바로 진행할게요. (조회 부분에서 스키마 수정이 필요해보여서 따로 작업하려 합니다)
  • 이전 리뷰 내용에 대한 것들은 코멘트 달아놓을게요!
  • 머지되면 api 관련해서 수정 필요한 부분들 따로 모아서 PR 올려보겠습니다.

Copy link

github-actions bot commented Feb 12, 2025

Test Results

166 tests  +7   163 ✅ +7   5s ⏱️ -1s
 61 suites +1     3 💤 ±0 
 61 files   +1     0 ❌ ±0 

Results for commit 2c015ee. ± Comparison against base commit 073cec3.

This pull request removes 4 and adds 11 tests. Note that renamed tests count towards both.
reviewme.review.service.ReviewDetailLookupServiceTest ‑ 리뷰_그룹에_해당하지_않는_리뷰를_조회할_경우_예외가_발생한다()
reviewme.reviewgroup.controller.ReviewGroupSessionResolverTest ‑ 세션에_코드가_없는_경우_예외를_발생한다()
reviewme.reviewgroup.controller.ReviewGroupSessionResolverTest ‑ 세션에서_코드를_가져와_리뷰그룹으로_변환한다()
reviewme.reviewgroup.controller.ReviewGroupSessionResolverTest ‑ 세션이_존재하지_않는_경우_예외를_발생한다()
reviewme.review.service.ReviewDetailLookupServiceTest ‑ 등록되지_않은_리뷰를_조회할_경우_예외가_발생한다()
reviewme.security.resolver.GuestReviewGroupSessionResolverTest ‑ 세션을_통해_비회원_리뷰_그룹_코드를_반환한다()
reviewme.security.resolver.GuestReviewGroupSessionResolverTest ‑ 어노테이션의_속성이_false일때_세션에_저장된_데이터가_없다면_null을_반환한다()
reviewme.security.resolver.GuestReviewGroupSessionResolverTest ‑ 어노테이션의_속성이_flase일때_세션이_없다면_null을_반환한다()
reviewme.security.resolver.GuestReviewGroupSessionResolverTest ‑ 어노테이션의_속성이_true일때_세션에_저장된_데이터가_없다면_예외가_발생한다()
reviewme.security.resolver.GuestReviewGroupSessionResolverTest ‑ 어노테이션의_속성이_true일때_세션이_없다면_예외가_발생한다()
reviewme.security.resolver.LoginMemberSessionResolverTest ‑ 세션을_통해_로그인_회원을_반환한다()
reviewme.security.resolver.LoginMemberSessionResolverTest ‑ 어노테이션의_속성이_false일때_세션에_저장된_데이터가_없다면_null을_반환한다()
reviewme.security.resolver.LoginMemberSessionResolverTest ‑ 어노테이션의_속성이_flase일때_세션이_없다면_null을_반환한다()
reviewme.security.resolver.LoginMemberSessionResolverTest ‑ 어노테이션의_속성이_true일때_세션에_저장된_데이터가_없다면_예외가_발생한다()
…

♻️ This comment has been updated with latest results.

Copy link
Contributor Author

@Kimprodp Kimprodp left a comment

Choose a reason for hiding this comment

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

리졸버 관련 이전 리뷰에 대한 코멘트 추가했습니다

@Kimprodp Kimprodp changed the title [BE] feat: 컨트롤러에서 세션 저장 정보를 리졸버를 통해 가져온다. [BE] feat: 컨트롤러에서 리졸버를 통해 세션 저장 정보를 사용 Feb 13, 2025
Copy link
Contributor

@nayonsoso nayonsoso 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 15 to 18
@RequiredArgsConstructor
public class GuestReviewGroupSessionResolver implements HandlerMethodArgumentResolver {

private final SessionManager sessionManager;
Copy link
Contributor

@nayonsoso nayonsoso Feb 13, 2025

Choose a reason for hiding this comment

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

리졸버랑 어노테이션의 위치가 auth.controller여야 할지.. 고민되네요🤔
global.authentication 에 위치하게 하는건 어떤가요?
"인증"은 횡단 관심사라서, global 에 위치하는게 자연스럽다 생각해요.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

global 말고, web 패키지를 만들어서 위치하는 건 어떤가요? global은 아무 곳에도 종속되지 않고 전역으로 사용하는 느낌이어서요.

Copy link
Contributor

@nayonsoso nayonsoso Feb 13, 2025

Choose a reason for hiding this comment

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

web 이라고 하기에는 또 애매한 것 같아요😭
우리 api 를 앱이 사용할 수도 있으니까..

다른 대안으로 security 를 제안합니다!
관심사별로 모아주기도 하고, global 보다는 목적이 명확해보이는데 어떤가요?
사실 지피티가 추천해줬는데, 일반적으로 많이 쓰인다고도 하고~ 나름 일리적인 것 같아서 가져와봤어요 ㅎㅎ

Copy link
Contributor

Choose a reason for hiding this comment

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

image

디스코드에서 합의된 내용 남겨둡니당~

Copy link
Contributor Author

@Kimprodp Kimprodp 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 15 to 18
@RequiredArgsConstructor
public class GuestReviewGroupSessionResolver implements HandlerMethodArgumentResolver {

private final SessionManager sessionManager;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

global 말고, web 패키지를 만들어서 위치하는 건 어떤가요? global은 아무 곳에도 종속되지 않고 전역으로 사용하는 느낌이어서요.

Copy link
Contributor

@nayonsoso nayonsoso left a comment

Choose a reason for hiding this comment

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

변경사항 확인했습니다~ 👏👏

마지막으로 한가지! 제안이 있는데,
GuestReviewGroupSessionNotFoundException 이 예외 이름을
NotExists 로 바꾸는거 어떄요?
뭔가 GuestReviewGroupSessionNotFoundException 는 404에 해당하는것처럼 느껴져요😓

사소한거라 테드가 선택적으로 반영하고, 원할 때 머지하세용~

@Kimprodp Kimprodp merged commit 44f413b into develop Feb 14, 2025
2 checks passed
@Kimprodp
Copy link
Contributor Author

변경사항 확인했습니다~ 👏👏

마지막으로 한가지! 제안이 있는데, GuestReviewGroupSessionNotFoundException 이 예외 이름을 NotExists 로 바꾸는거 어떄요? 뭔가 GuestReviewGroupSessionNotFoundException 는 404에 해당하는것처럼 느껴져요😓

사소한거라 테드가 선택적으로 반영하고, 원할 때 머지하세용~

공감합니다~ 해당 부분까지 반영하여 머지합니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[BE] 세션 저장 정보를 리졸버를 통해 컨트롤러에 가져온다
2 participants