-
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f0ed32c
β¨feat: 곡μ λμ₯κ³ μ¬μ©μ μν μΉμμΌ μμ‘΄μ± μΆκ°
MODUGGAGI ad5a6cb
β¨feat: 곡μ λμ₯κ³ μ¬μ©μ μν λμ₯κ³ μ λ©€λ²μ μ€ν€λ§ λ³κ²½
MODUGGAGI 71f9ab0
β¨feat: λμ₯κ³ μ΄λ μλ¬ μν μΆκ°
MODUGGAGI 5ae8701
β¨feat: μΉμμΌ μ¬μ©μ μν μ€μ μΆκ°
MODUGGAGI 5bf2022
β¨feat: 곡μ λμ₯κ³ μ΄λλ₯Ό μν κΈ°λ₯ μΆκ°
MODUGGAGI b9d686f
β¨feat: μΉμμΌμ ν΅ν νλ‘ νΈμ μλ‘κ³ μΉ¨ μμ² μ λ¬
MODUGGAGI 3b63c68
β¨feat: Memberλ₯Ό κ³ μκ°μ²΄ μμ μμ μ κ±°
MODUGGAGI 262caad
β¨feat: μΉμμΌ μ€μ μ μν id κ° μ λ¬ λ° SecurityConfigμμ κ²½λ‘ νμ©
MODUGGAGI 7af4e89
refactor: λ‘κ·Έμ 리리
MODUGGAGI f965ae7
β¨feat: νλ‘μ° λͺ©λ‘ 보기
MODUGGAGI 2e49f64
Update src/main/java/novaminds/gradproj/domain/refrigerator/service/cβ¦
chan0831 9871677
Update src/main/java/novaminds/gradproj/domain/refrigerator/entity/Reβ¦
chan0831 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/novaminds/gradproj/config/WebSocketConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package novaminds.gradproj.config; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import novaminds.gradproj.global.websocket.StompHandler; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.messaging.simp.config.ChannelRegistration; | ||
| import org.springframework.messaging.simp.config.MessageBrokerRegistry; | ||
| import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; | ||
| import org.springframework.web.socket.config.annotation.StompEndpointRegistry; | ||
| import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; | ||
|
|
||
| @Configuration | ||
| @EnableWebSocketMessageBroker | ||
| @RequiredArgsConstructor | ||
| public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { | ||
|
|
||
| private final StompHandler stompHandler; | ||
|
|
||
| @Override | ||
| public void configureMessageBroker(MessageBrokerRegistry config) { | ||
| // ꡬλ (sub) κ²½λ‘ μ€μ : ν΄λΌμ΄μΈνΈκ° λ©μμ§λ₯Ό λ°μ κ²½λ‘μ prefix | ||
| config.enableSimpleBroker("/sub"); | ||
|
|
||
| // λ°ν(pub) κ²½λ‘ μ€μ : ν΄λΌμ΄μΈνΈκ° λ©μμ§λ₯Ό λ³΄λΌ λ μ¬μ©ν prefix | ||
| config.setApplicationDestinationPrefixes("/pub"); | ||
| } | ||
|
|
||
| @Override | ||
| public void registerStompEndpoints(StompEndpointRegistry registry) { | ||
| // μΉμμΌ μ°κ²° μ£Όμ: ws://localhost:8080/ws-stomp | ||
| registry.addEndpoint("/ws-stomp") | ||
| .setAllowedOriginPatterns("*") // CORS νμ© | ||
| .withSockJS(); | ||
| } | ||
|
|
||
| @Override | ||
| public void configureClientInboundChannel(ChannelRegistration registration) { | ||
| // JWT μΈμ¦μ μν μΈν°μ ν° μΆκ° | ||
| registration.interceptors(stompHandler); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/novaminds/gradproj/domain/member/repository/FollowRepositoryCustom.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package novaminds.gradproj.domain.member.repository; | ||
|
|
||
| import novaminds.gradproj.domain.member.entity.Follow; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface FollowRepositoryCustom { | ||
|
|
||
| // νλ‘μ λͺ©λ‘ μ‘°ν (N+1 λ°©μ§λ₯Ό μν fetch join) | ||
| List<Follow> findFollowersWithMemberByLoginId(String loginId); | ||
|
|
||
| // νλ‘μ λͺ©λ‘ μ‘°ν (N+1 λ°©μ§λ₯Ό μν fetch join) | ||
| List<Follow> findFollowingsWithMemberByLoginId(String loginId); | ||
| } |
39 changes: 39 additions & 0 deletions
39
src/main/java/novaminds/gradproj/domain/member/repository/FollowRepositoryCustomImpl.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package novaminds.gradproj.domain.member.repository; | ||
|
|
||
| import com.querydsl.jpa.impl.JPAQueryFactory; | ||
| import lombok.RequiredArgsConstructor; | ||
| import novaminds.gradproj.domain.member.entity.Follow; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static novaminds.gradproj.domain.member.entity.QFollow.follow; | ||
| import static novaminds.gradproj.domain.member.entity.QMember.member; | ||
| import static novaminds.gradproj.domain.refrigerator.entity.QRefrigerator.refrigerator; | ||
|
|
||
| @Repository | ||
| @RequiredArgsConstructor | ||
| public class FollowRepositoryCustomImpl implements FollowRepositoryCustom { | ||
|
|
||
| private final JPAQueryFactory queryFactory; | ||
|
|
||
| @Override | ||
| public List<Follow> findFollowersWithMemberByLoginId(String loginId) { | ||
| return queryFactory | ||
| .selectFrom(follow) | ||
| .join(follow.follower, member).fetchJoin() | ||
| .join(member.refrigerator, refrigerator).fetchJoin() | ||
| .where(follow.following.loginId.eq(loginId)) | ||
| .fetch(); | ||
| } | ||
|
|
||
| @Override | ||
| public List<Follow> findFollowingsWithMemberByLoginId(String loginId) { | ||
| return queryFactory | ||
| .selectFrom(follow) | ||
| .join(follow.following, member).fetchJoin() | ||
| .join(member.refrigerator, refrigerator).fetchJoin() | ||
| .where(follow.follower.loginId.eq(loginId)) | ||
| .fetch(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 172 additions & 0 deletions
172
src/main/java/novaminds/gradproj/domain/member/service/query/FollowQueryService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| package novaminds.gradproj.domain.member.service.query; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import novaminds.gradproj.domain.member.entity.Follow; | ||
| import novaminds.gradproj.domain.member.entity.Member; | ||
| import novaminds.gradproj.domain.member.repository.FollowRepository; | ||
| import novaminds.gradproj.domain.member.web.dto.MemberResponseDTO; | ||
| import novaminds.gradproj.domain.refrigerator.entity.RefrigeratorInvitation; | ||
| import novaminds.gradproj.domain.refrigerator.repository.RefrigeratorInvitationRepository; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| @Service | ||
| public class FollowQueryService { | ||
|
|
||
| private final FollowRepository followRepository; | ||
| private final RefrigeratorInvitationRepository refrigeratorInvitationRepository; | ||
|
|
||
| public MemberResponseDTO.FollowersResponse getFollowers(Member currentMember) { | ||
| // λλ₯Ό νλ‘μ°νλ μ¬λλ€ μ‘°ν (fetch joinμΌλ‘ N+1 λ°©μ§) | ||
| List<Follow> followers = followRepository.findFollowersWithMemberByLoginId(currentMember.getLoginId()); | ||
|
|
||
| // λ΄κ° νλ‘μ°νλ μ¬λλ€μ loginIdλ₯Ό SetμΌλ‘ (λ§ν νμΈμ©) | ||
| Set<String> myFollowingIds = followRepository.findByFollowerLoginId(currentMember.getLoginId()) | ||
| .stream() | ||
| .map(follow -> follow.getFollowing().getLoginId()) | ||
| .collect(Collectors.toSet()); | ||
|
|
||
| // λμ λμ₯κ³ ID | ||
| Long myRefrigeratorId = currentMember.getRefrigerator().getId(); | ||
|
|
||
| // νλ‘μ λ©€λ² λ¦¬μ€νΈ | ||
| List<Member> followerMembers = followers.stream() | ||
| .map(Follow::getFollower) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| // λ΄κ° λ³΄λΈ PENDING μ΄λ μ‘°ν (batch) | ||
| List<RefrigeratorInvitation> pendingInvitations = refrigeratorInvitationRepository | ||
| .findByInviterAndInviteeInAndStatus( | ||
| currentMember, | ||
| followerMembers, | ||
| RefrigeratorInvitation.InvitationStatus.PENDING | ||
| ); | ||
|
|
||
| // PENDING μ΄λλ₯Ό λ°μ μ¬λλ€μ loginIdλ₯Ό SetμΌλ‘ | ||
| Set<String> pendingInviteeIds = pendingInvitations.stream() | ||
| .map(invitation -> invitation.getInvitee().getLoginId()) | ||
| .collect(Collectors.toSet()); | ||
|
|
||
| // DTO λ³ν | ||
| List<MemberResponseDTO.FollowMemberInfo> followerInfos = followers.stream() | ||
| .map(follow -> { | ||
| Member followerMember = follow.getFollower(); | ||
| MemberResponseDTO.FollowMemberInfo.InvitationStatus status = | ||
| determineInvitationStatus( | ||
| followerMember, | ||
| myFollowingIds, | ||
| myRefrigeratorId, | ||
| pendingInviteeIds | ||
| ); | ||
|
|
||
| return MemberResponseDTO.FollowMemberInfo.builder() | ||
| .nickname(followerMember.getNickname()) | ||
| .profileImgUrl(followerMember.getProfileImage()) | ||
| .invitationStatus(status) | ||
| .build(); | ||
| }) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| return MemberResponseDTO.FollowersResponse.builder() | ||
| .followers(followerInfos) | ||
| .build(); | ||
| } | ||
|
|
||
| public MemberResponseDTO.FollowingsResponse getFollowings(Member currentMember) { | ||
| // λ΄κ° νλ‘μ°νλ μ¬λλ€ μ‘°ν (fetch joinμΌλ‘ N+1 λ°©μ§) | ||
| List<Follow> followings = followRepository.findFollowingsWithMemberByLoginId(currentMember.getLoginId()); | ||
|
|
||
| // λλ₯Ό νλ‘μ°νλ μ¬λλ€μ loginIdλ₯Ό SetμΌλ‘ (λ§ν νμΈμ©) | ||
| Set<String> myFollowerIds = followRepository.findByFollowingLoginId(currentMember.getLoginId()) | ||
| .stream() | ||
| .map(follow -> follow.getFollower().getLoginId()) | ||
| .collect(Collectors.toSet()); | ||
|
|
||
| // λμ λμ₯κ³ ID | ||
| Long myRefrigeratorId = currentMember.getRefrigerator().getId(); | ||
|
|
||
| // νλ‘μ λ©€λ² λ¦¬μ€νΈ | ||
| List<Member> followingMembers = followings.stream() | ||
| .map(Follow::getFollowing) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| // λ΄κ° λ³΄λΈ PENDING μ΄λ μ‘°ν (batch) | ||
| List<RefrigeratorInvitation> pendingInvitations = refrigeratorInvitationRepository | ||
| .findByInviterAndInviteeInAndStatus( | ||
| currentMember, | ||
| followingMembers, | ||
| RefrigeratorInvitation.InvitationStatus.PENDING | ||
| ); | ||
|
|
||
| // PENDING μ΄λλ₯Ό λ°μ μ¬λλ€μ loginIdλ₯Ό SetμΌλ‘ | ||
| Set<String> pendingInviteeIds = pendingInvitations.stream() | ||
| .map(invitation -> invitation.getInvitee().getLoginId()) | ||
| .collect(Collectors.toSet()); | ||
|
|
||
| // DTO λ³ν | ||
| List<MemberResponseDTO.FollowMemberInfo> followingInfos = followings.stream() | ||
| .map(follow -> { | ||
| Member followingMember = follow.getFollowing(); | ||
| MemberResponseDTO.FollowMemberInfo.InvitationStatus status = | ||
| determineInvitationStatus( | ||
| followingMember, | ||
| myFollowerIds, | ||
| myRefrigeratorId, | ||
| pendingInviteeIds | ||
| ); | ||
|
|
||
| return MemberResponseDTO.FollowMemberInfo.builder() | ||
| .nickname(followingMember.getNickname()) | ||
| .profileImgUrl(followingMember.getProfileImage()) | ||
| .invitationStatus(status) | ||
| .build(); | ||
| }) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| return MemberResponseDTO.FollowingsResponse.builder() | ||
| .followings(followingInfos) | ||
| .build(); | ||
| } | ||
|
|
||
| /** | ||
| * μ΄λ μνλ₯Ό κ²°μ νλ λ©μλ | ||
| * | ||
| * @param targetMember λμ λ©€λ² | ||
| * @param mutualCheckSet λ§ν νμΈμ μν Set (νλ‘μ λͺ©λ‘μ΄λ©΄ λ΄ νλ‘μ Set, νλ‘μ λͺ©λ‘μ΄λ©΄ λ΄ νλ‘μ Set) | ||
| * @param myRefrigeratorId λμ λμ₯κ³ ID | ||
| * @param pendingInviteeIds PENDING μν μ΄λλ₯Ό λ°μ μ¬λλ€μ loginId Set | ||
| * @return InvitationStatus | ||
| */ | ||
| private MemberResponseDTO.FollowMemberInfo.InvitationStatus determineInvitationStatus( | ||
| Member targetMember, | ||
| Set<String> mutualCheckSet, | ||
| Long myRefrigeratorId, | ||
| Set<String> pendingInviteeIds | ||
| ) { | ||
| // λ§νμ΄ μλλ©΄ NOT_MUTUAL | ||
| if (!mutualCheckSet.contains(targetMember.getLoginId())) { | ||
| return MemberResponseDTO.FollowMemberInfo.InvitationStatus.NOT_MUTUAL; | ||
| } | ||
|
|
||
| // λ§νμ΄λ©΄ μΆκ° 쑰건 νμΈ | ||
| // 1. κ°μ λμ₯κ³ μ¬μ© μ€μΈμ§ νμΈ | ||
| if (targetMember.getRefrigerator().getId().equals(myRefrigeratorId)) { | ||
| return MemberResponseDTO.FollowMemberInfo.InvitationStatus.ALREADY_SAME_REFRIGERATOR; | ||
| } | ||
|
|
||
| // 2. μ΄λ―Έ μ΄λμ₯ 보λλμ§ νμΈ | ||
| if (pendingInviteeIds.contains(targetMember.getLoginId())) { | ||
| return MemberResponseDTO.FollowMemberInfo.InvitationStatus.INVITATION_PENDING; | ||
| } | ||
|
|
||
| // 3. λ λ€ μλλ©΄ μ΄λ κ°λ₯ | ||
| return MemberResponseDTO.FollowMemberInfo.InvitationStatus.MUTUAL_FOLLOW_INVITE; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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)μμμ μΉμμΌ μ°κ²°μ νμ©νκ² λ©λλ€. κ°λ° μ€μλ νΈλ¦¬ν μ μμ§λ§, νλ‘λμ νκ²½μμλ 보μμ μνν μ μμ΅λλ€. νλ‘ νΈμλ μ ν리μΌμ΄μ μ νΉμ μΆμ²λ§ νμ©νλλ‘ μ ννμ¬, νκ°λμ§ μμ μΉμ¬μ΄νΈκ° μΉμμΌ μλν¬μΈνΈμ μ°κ²°νλ κ²μ λ°©μ§νλ κ²μ΄ μ’μ΅λλ€.