-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/58/shared refrigerator #59
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
Conversation
|
Caution Review failedThe pull request is closed. Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughImplements refrigerator sharing and real-time updates: converts MemberโRefrigerator to a many-to-one relationship, adds RefrigeratorInvitation entity and services (command/query), extends follow APIs to include invitation status, introduces WebSocket STOMP (with JWT interceptor), and updates converters/DTOs and controllers to support invitations and broadcast ingredient updates. Changes
sequenceDiagram
participant Client as Web Client
participant WS as STOMP Endpoint (/ws-stomp)
participant StompHandler as StompHandler (JWT)
participant Controller as RefrigeratorInvitationController
participant CmdService as RefrigeratorInvitationCommandService
participant InviteRepo as RefrigeratorInvitationRepository
participant RefrigRepo as RefrigeratorRepository
participant MemberRepo as MemberRepository
Client->>WS: CONNECT (Authorization: Bearer <token>)
WS->>StompHandler: preSend(CONNECT)
StompHandler-->>WS: VALID / REJECT
Client->>Controller: POST /api/refrigerators/invitations/{nickname}/send
Controller->>CmdService: sendInvitation(inviter, nickname)
CmdService->>MemberRepo: findByNickname(nickname)
MemberRepo-->>CmdService: invitee
CmdService->>InviteRepo: findByInviterAndInviteeAndStatus(...)
InviteRepo-->>CmdService: Optional.empty()/existing
CmdService->>InviteRepo: save(new RefrigeratorInvitation(...))
CmdService-->>Controller: success
Controller-->>Client: ApiResponse(success)
Note over CmdService,RefrigRepo: On accept flow, CmdService transfers member between refrigerators and may delete empty refrigerator, then updates invitation status and broadcasts via SimpMessagingTemplate to /sub/refrigerator/{id}
Estimated code review effort๐ฏ 4 (Complex) | โฑ๏ธ ~50 minutes
Possibly related PRs
Poem
โจ Finishing touches
๐งช Generate unit tests (beta)
๐ Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro ๐ Files selected for processing (26)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello @chan0831, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! ์ด PR์ ๊ณต์ ๋์ฅ๊ณ ๊ธฐ๋ฅ์ ๋์ ํ์ฌ ์ฌ๋ฌ ์ฌ์ฉ์๊ฐ ํ๋์ ๋์ฅ๊ณ ๋ฅผ ํจ๊ป ๊ด๋ฆฌํ ์ ์๋๋ก ํฉ๋๋ค. ์ด๋ฅผ ์ํด ํต์ฌ ์ํฐํฐ ๊ด๊ณ๋ฅผ ์ฌ์ ์ํ๊ณ , ์ด๋ ๋ฐ์ก, ์๋ฝ, ๊ฑฐ์ , ์ทจ์ ๋ฑ ์ด๋ ๋ผ์ดํ์ฌ์ดํด์ ๊ด๋ฆฌํ๋ ์์คํ ์ ๊ตฌ์ถํ์ต๋๋ค. ๋ํ, WebSocket์ ํ์ฉํ์ฌ ๋์ฅ๊ณ ๋ด์ฉ๋ฌผ ๋ณ๊ฒฝ ์ ๋ชจ๋ ๊ณต์ ๋ฉค๋ฒ์๊ฒ ์ค์๊ฐ์ผ๋ก ์ ๋ฐ์ดํธ๋ฅผ ์ ๊ณตํจ์ผ๋ก์จ ํ์ ๊ฒฝํ์ ํฅ์์์ผฐ์ต๋๋ค. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with ๐ and ๐ on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
๊ณต์ ๋์ฅ๊ณ ๊ธฐ๋ฅ ๊ตฌํ์ ์ํ PR ์ ๋ณด์์ต๋๋ค. ์ ๋ฐ์ ์ผ๋ก ๊ธฐ๋ฅ ๊ตฌํ์ด ์ ์ด๋ฃจ์ด์ง ๊ฒ ๊ฐ์ต๋๋ค. ํนํ ์น์์ผ์ ์ด์ฉํ ์ค์๊ฐ ์
๋ฐ์ดํธ์ ์ด๋ ๊ธฐ๋ฅ ๊ตฌํ์ด ์ธ์์ ์
๋๋ค. ๋ช ๊ฐ์ง ๊ฐ์ ์ ๊ณผ ์ ์ฌ์ ์ธ ์ํ์ ๋ํด ๋ฆฌ๋ทฐ ์ฝ๋ฉํธ๋ฅผ ๋จ๊ฒผ์ผ๋ ํ์ธ ๋ถํ๋๋ฆฝ๋๋ค. ์ฃผ์ ๋ด์ฉ์ผ๋ก๋ Refrigerator ์ํฐํฐ์ CascadeType ์ค์ , NullPointerException ๋ฐ์ ๊ฐ๋ฅ์ฑ, ์ฝ๋ ์ค๋ณต, ๊ทธ๋ฆฌ๊ณ API ์๋ํฌ์ธํธ ์ค๊ณ์ ๋ํ ์ ์์ด ์์ต๋๋ค.
src/main/java/novaminds/gradproj/domain/refrigerator/entity/Refrigerator.java
Outdated
Show resolved
Hide resolved
...minds/gradproj/domain/refrigerator/service/command/RefrigeratorInvitationCommandService.java
Outdated
Show resolved
Hide resolved
| public void registerStompEndpoints(StompEndpointRegistry registry) { | ||
| // ์น์์ผ ์ฐ๊ฒฐ ์ฃผ์: ws://localhost:8080/ws-stomp | ||
| registry.addEndpoint("/ws-stomp") | ||
| .setAllowedOriginPatterns("*") // CORS ํ์ฉ |
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.
.setAllowedOriginPatterns("*")๋ฅผ ์ฌ์ฉํ๋ฉด ๋ชจ๋ ์ถ์ฒ(origin)์์์ ์น์์ผ ์ฐ๊ฒฐ์ ํ์ฉํ๊ฒ ๋ฉ๋๋ค. ๊ฐ๋ฐ ์ค์๋ ํธ๋ฆฌํ ์ ์์ง๋ง, ํ๋ก๋์
ํ๊ฒฝ์์๋ ๋ณด์์ ์ํํ ์ ์์ต๋๋ค. ํ๋ก ํธ์๋ ์ ํ๋ฆฌ์ผ์ด์
์ ํน์ ์ถ์ฒ๋ง ํ์ฉํ๋๋ก ์ ํํ์ฌ, ํ๊ฐ๋์ง ์์ ์น์ฌ์ดํธ๊ฐ ์น์์ผ ์๋ํฌ์ธํธ์ ์ฐ๊ฒฐํ๋ ๊ฒ์ ๋ฐฉ์งํ๋ ๊ฒ์ด ์ข์ต๋๋ค.
| .setAllowedOriginPatterns("*") // CORS ํ์ฉ | |
| .setAllowedOriginPatterns("https://your-frontend-domain.com") // TODO: ํ๋ก๋์ ํ๊ฒฝ์ ๋ง๊ฒ ๋๋ฉ์ธ์ ์ ํํด์ฃผ์ธ์. |
| public void rejectInvitation(Member invitee, Long invitationId) { | ||
| // ์ด๋ ์กฐํ | ||
| RefrigeratorInvitation invitation = invitationRepository.findById(invitationId) | ||
| .orElseThrow(() -> new GeneralException(ErrorStatus.INVITATION_NOT_FOUND)); | ||
|
|
||
| // ์ด๋๋ฐ์ ์ฌ๋์ด ๋ง๋์ง ํ์ธ | ||
| if (!invitation.getInvitee().getLoginId().equals(invitee.getLoginId())) { | ||
| throw new GeneralException(ErrorStatus.INVITATION_NOT_AUTHORIZED); | ||
| } | ||
|
|
||
| // ์ด๋ฏธ ์ฒ๋ฆฌ๋ ์ด๋์ธ์ง ํ์ธ | ||
| if (invitation.getStatus() != InvitationStatus.PENDING) { | ||
| throw new GeneralException(ErrorStatus.INVITATION_ALREADY_PROCESSED); | ||
| } | ||
|
|
||
| // ์ด๋ ๊ฑฐ์ | ||
| invitation.reject(); | ||
| } |
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.
acceptInvitation, rejectInvitation, cancelInvitation ๋ฉ์๋ ์ ๋ฐ์ ๊ฑธ์ณ ์ด๋ ์ ๋ณด๋ฅผ ์กฐํํ๊ณ ์ ํจ์ฑ์ ๊ฒ์ฌํ๋ (์กด์ฌ ์ฌ๋ถ, ๊ถํ, ์ํ ํ์ธ) ๋ก์ง์ด ์ค๋ณต๋๊ณ ์์ต๋๋ค. ์ด๋ ๊ฒ ์ฝ๋๊ฐ ์ค๋ณต๋๋ฉด ํฅํ ์ ์ง๋ณด์๊ฐ ์ด๋ ค์์ง ์ ์์ต๋๋ค. ์ด ๊ณตํต ๋ก์ง์ ๋ณ๋์ private ํฌํผ ๋ฉ์๋๋ก ์ถ์ถํ๋ ๊ฒ์ ๊ณ ๋ คํด๋ณด์ธ์.
์๋ฅผ ๋ค์ด, ๋ค์๊ณผ ๊ฐ์ ํฌํผ ๋ฉ์๋๋ฅผ ๋ง๋ค ์ ์์ต๋๋ค:
private RefrigeratorInvitation findAndValidateInvitation(Long invitationId, Member member, boolean isInvitee) {
RefrigeratorInvitation invitation = invitationRepository.findById(invitationId)
.orElseThrow(() -> new GeneralException(ErrorStatus.INVITATION_NOT_FOUND));
Member principal = isInvitee ? invitation.getInvitee() : invitation.getInviter();
if (!principal.getLoginId().equals(member.getLoginId())) {
throw new GeneralException(ErrorStatus.INVITATION_NOT_AUTHORIZED);
}
if (invitation.getStatus() != InvitationStatus.PENDING) {
throw new GeneralException(ErrorStatus.INVITATION_ALREADY_PROCESSED);
}
return invitation;
}์ด๋ ๊ฒ ํ๋ฉด rejectInvitation ๋ฉ์๋๋ ๋ค์๊ณผ ๊ฐ์ด ๊ฐ๊ฒฐํด์ง๋๋ค:
public void rejectInvitation(Member invitee, Long invitationId) {
RefrigeratorInvitation invitation = findAndValidateInvitation(invitationId, invitee, true);
invitation.reject();
}| @PostMapping("/{nickname}/send") | ||
| public ApiResponse<String> sendInvitation( | ||
| @CurrentUser Member member, | ||
| @PathVariable String nickname | ||
| ) { | ||
| invitationCommandService.sendInvitation(member, nickname); | ||
| return ApiResponse.onSuccess("์ด๋๋ฅผ ๋ณด๋์ต๋๋ค."); | ||
| } |
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.
sendInvitation ์๋ํฌ์ธํธ๊ฐ ์ด๋๋ฐ๋ ์ฌ๋์ nickname์ URL ๊ฒฝ๋ก ๋ณ์(@PathVariable)๋ก ๋ฐ๊ณ ์์ต๋๋ค. ์ด ๋ฐฉ์๋ ๋์์ ํ์ง๋ง, ๋ฆฌ์์ค(์ด๋)๋ฅผ ์์ฑํ๋ POST ์์ฒญ์์๋ ์ผ๋ฐ์ ์ผ๋ก ์์ฒญ ๋ณธ๋ฌธ(@RequestBody)์ ์ฌ์ฉํ๋ ๊ฒ์ด ๋ ํ์ค์ ์ธ REST API ์ค๊ณ ๋ฐฉ์์
๋๋ค.
ํนํ ํ์ฌ RefrigeratorRequestDTO.InvitationRequest๋ผ๋ DTO๊ฐ ์ ์๋์ด ์์ง๋ง ์ฌ์ฉ๋์ง ์๊ณ ์์ต๋๋ค. ์ด DTO๋ฅผ ํ์ฉํ์ฌ API์ ์ผ๊ด์ฑ์ ๋์ด๋ ๊ฒ์ด ์ข์ต๋๋ค.
์๋ํฌ์ธํธ๋ฅผ POST /api/refrigerators/invitations๋ก ๋ณ๊ฒฝํ๊ณ , ๋ฉ์๋ ์๊ทธ๋์ฒ๋ฅผ ๋ค์๊ณผ ๊ฐ์ด ์์ ํ๋ ๊ฒ์ ๊ณ ๋ คํด๋ณด์ธ์:
@PostMapping
public ApiResponse<String> sendInvitation(
@CurrentUser Member member,
@RequestBody @Valid RefrigeratorRequestDTO.InvitationRequest request
) {
invitationCommandService.sendInvitation(member, request.getInviteeNickname());
return ApiResponse.onSuccess("์ด๋๋ฅผ ๋ณด๋์ต๋๋ค.");
}์ด๋ ๊ฒ ํ๋ฉด API๊ฐ ๋ ์ผ๊ด์ฑ ์์ด์ง๊ณ , ๋์ค์ ์ด๋ ์์ฒญ์ ํ๋ผ๋ฏธํฐ๊ฐ ์ถ๊ฐ๋ ๊ฒฝ์ฐ ํ์ฅํ๊ธฐ์๋ ์ฉ์ดํฉ๋๋ค.
โฆommand/RefrigeratorInvitationCommandService.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
โฆfrigerator.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
๐ ๋ณ๊ฒฝ์ฌํญ
๊ณต์ ๋์ฅ๊ณ
๐ ๊ด๋ จ ์ด์
โ ์ฒดํฌ๋ฆฌ์คํธ
๐ ํน์ด์ฌํญ
Summary by CodeRabbit
New Features
Chores
โ๏ธ Tip: You can customize this high-level summary in your review settings.