Skip to content

Commit 6d0ef73

Browse files
authored
[COZY-424] fix: findByRoomIdAndMateId 에러 해결
1 parent 431a043 commit 6d0ef73

File tree

8 files changed

+31
-16
lines changed

8 files changed

+31
-16
lines changed

src/main/java/com/cozymate/cozymate_server/domain/mate/repository/MateRepository.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ Optional<Mate> findByRoomIdAndMemberIdAndNotEntryStatus(@Param("roomId") Long ro
3737
boolean existsByMemberIdAndRoomStatuses(@Param("memberId") Long memberId,
3838
@Param("status1") RoomStatus status1, @Param("status2") RoomStatus status2);
3939

40-
Optional<Mate> findByMemberIdAndRoomId(Long MemberId, Long RoomId);
41-
4240
Optional<Mate> findByRoomIdAndMemberIdAndEntryStatus(Long roomId, Long memberId,
4341
EntryStatus status);
4442

@@ -74,7 +72,7 @@ List<Mate> findAllByMemberBirthDayMonthAndDayAndEntryStatus(@Param("month") int
7472
List<Mate> findFetchMemberByRoom(@Param("room") Room room,
7573
@Param("entryStatus") EntryStatus entryStatus);
7674

77-
Optional<Mate> findByMemberAndEntryStatus(Member member,EntryStatus entryStatus);
75+
Optional<Mate> findByMemberAndEntryStatus(Member member, EntryStatus entryStatus);
7876

7977
@Query("select m from Mate m join fetch m.member")
8078
List<Mate> findFetchAll();

src/main/java/com/cozymate/cozymate_server/domain/post/service/PostCommandService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.cozymate.cozymate_server.domain.feed.Feed;
55
import com.cozymate.cozymate_server.domain.feed.repository.FeedRepository;
66
import com.cozymate.cozymate_server.domain.mate.Mate;
7+
import com.cozymate.cozymate_server.domain.mate.enums.EntryStatus;
78
import com.cozymate.cozymate_server.domain.mate.repository.MateRepository;
89
import com.cozymate.cozymate_server.domain.member.Member;
910
import com.cozymate.cozymate_server.domain.post.Post;
@@ -37,8 +38,8 @@ public class PostCommandService {
3738

3839
public Long createPost(Member member, PostCreateDTO postCreateDTO) {
3940

40-
Mate mate = mateRepository.findByMemberIdAndRoomId(member.getId(),
41-
postCreateDTO.getRoomId()).orElseThrow(
41+
Mate mate = mateRepository.findByRoomIdAndMemberIdAndEntryStatus(postCreateDTO.getRoomId(),
42+
member.getId(), EntryStatus.JOINED).orElseThrow(
4243
() -> new GeneralException(ErrorStatus._MATE_OR_ROOM_NOT_FOUND)
4344
);
4445

src/main/java/com/cozymate/cozymate_server/domain/postcomment/service/PostCommentCommandService.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.cozymate.cozymate_server.domain.postcomment.service;
22

33
import com.cozymate.cozymate_server.domain.mate.Mate;
4+
import com.cozymate.cozymate_server.domain.mate.enums.EntryStatus;
45
import com.cozymate.cozymate_server.domain.mate.repository.MateRepository;
56
import com.cozymate.cozymate_server.domain.member.Member;
67
import com.cozymate.cozymate_server.domain.post.Post;
@@ -30,7 +31,8 @@ public class PostCommentCommandService {
3031
public Long createPostComment(Member member,
3132
PostCommentCreateDTO postCommentCreateDTO) {
3233

33-
Mate commenter = mateRepository.findByMemberIdAndRoomId(member.getId(), postCommentCreateDTO.getRoomId()).orElseThrow(
34+
Mate commenter = mateRepository.findByRoomIdAndMemberIdAndEntryStatus(
35+
postCommentCreateDTO.getRoomId(), member.getId(), EntryStatus.JOINED).orElseThrow(
3436
() -> new GeneralException(ErrorStatus._MATE_OR_ROOM_NOT_FOUND)
3537
);
3638

@@ -47,15 +49,17 @@ public Long createPostComment(Member member,
4749
public Long updatePostComment(Member member,
4850
PostCommentUpdateDTO postCommentUpdateDTO) {
4951

50-
if (!mateRepository.existsByMemberIdAndRoomId(member.getId(), postCommentUpdateDTO.getRoomId())) {
52+
if (!mateRepository.existsByMemberIdAndRoomId(member.getId(),
53+
postCommentUpdateDTO.getRoomId())) {
5154
throw new GeneralException(ErrorStatus._MATE_OR_ROOM_NOT_FOUND);
5255
}
5356

54-
if(!postRepository.existsById(postCommentUpdateDTO.getPostId())){
57+
if (!postRepository.existsById(postCommentUpdateDTO.getPostId())) {
5558
throw new GeneralException(ErrorStatus._POST_NOT_FOUND);
5659
}
5760

58-
PostComment postComment = postCommentRepository.findById(postCommentUpdateDTO.getCommentId()).orElseThrow(
61+
PostComment postComment = postCommentRepository.findById(
62+
postCommentUpdateDTO.getCommentId()).orElseThrow(
5963
() -> new GeneralException(ErrorStatus._POST_COMMENT_NOT_FOUND)
6064
);
6165

@@ -70,7 +74,7 @@ public void deletePostComment(Member member, Long roomId, Long postId, Long comm
7074
throw new GeneralException(ErrorStatus._MATE_OR_ROOM_NOT_FOUND);
7175
}
7276

73-
if(!postRepository.existsById(postId)){
77+
if (!postRepository.existsById(postId)) {
7478
throw new GeneralException(ErrorStatus._POST_NOT_FOUND);
7579
}
7680

src/main/java/com/cozymate/cozymate_server/domain/role/service/RoleCommandService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.cozymate.cozymate_server.domain.role.service;
22

33
import com.cozymate.cozymate_server.domain.mate.Mate;
4+
import com.cozymate.cozymate_server.domain.mate.enums.EntryStatus;
45
import com.cozymate.cozymate_server.domain.mate.repository.MateRepository;
56
import com.cozymate.cozymate_server.domain.member.Member;
67
import com.cozymate.cozymate_server.domain.role.Role;
@@ -132,7 +133,7 @@ private int getDayBitmask(List<String> repeatDayStringList) {
132133
* @return Mate
133134
*/
134135
private Mate getMate(Long memberId, Long roomId) {
135-
return mateRepository.findByMemberIdAndRoomId(memberId, roomId)
136+
return mateRepository.findByRoomIdAndMemberIdAndEntryStatus(roomId, memberId, EntryStatus.JOINED)
136137
.orElseThrow(() -> new GeneralException(ErrorStatus._MATE_NOT_FOUND));
137138
}
138139

src/main/java/com/cozymate/cozymate_server/domain/roomlog/service/RoomLogQueryService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.cozymate.cozymate_server.domain.roomlog.service;
22

33
import com.cozymate.cozymate_server.domain.mate.Mate;
4+
import com.cozymate.cozymate_server.domain.mate.enums.EntryStatus;
45
import com.cozymate.cozymate_server.domain.mate.repository.MateRepository;
56
import com.cozymate.cozymate_server.domain.member.Member;
67
import com.cozymate.cozymate_server.domain.roomlog.RoomLog;
@@ -34,7 +35,8 @@ public PageResponseDto<List<RoomLogDetailResponseDto>> getRoomLogList(
3435
int size) {
3536

3637
// 본인 방에 속한건지 확인
37-
Mate mate = mateRepository.findByMemberIdAndRoomId(member.getId(), roomId)
38+
Mate mate = mateRepository.findByRoomIdAndMemberIdAndEntryStatus(roomId, member.getId(),
39+
EntryStatus.JOINED)
3840
.orElseThrow(() -> new GeneralException(ErrorStatus._MATE_OR_ROOM_NOT_FOUND));
3941

4042
Pageable pageable = PageRequest.of(page, size);

src/main/java/com/cozymate/cozymate_server/domain/rule/service/RuleCommandService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.cozymate.cozymate_server.domain.rule.service;
22

33
import com.cozymate.cozymate_server.domain.mate.Mate;
4+
import com.cozymate.cozymate_server.domain.mate.enums.EntryStatus;
45
import com.cozymate.cozymate_server.domain.mate.repository.MateRepository;
56
import com.cozymate.cozymate_server.domain.member.Member;
67
import com.cozymate.cozymate_server.domain.rule.Rule;
@@ -106,7 +107,8 @@ private void checkMaxRuleCount(Long roomId) {
106107
* @return Mate
107108
*/
108109
private Mate findMateByMemberIdAndRoomId(Member member, Long roomId) {
109-
return mateRepository.findByMemberIdAndRoomId(member.getId(), roomId)
110+
return mateRepository.findByRoomIdAndMemberIdAndEntryStatus(roomId, member.getId(),
111+
EntryStatus.JOINED)
110112
.orElseThrow(() -> new GeneralException(ErrorStatus._MATE_OR_ROOM_NOT_FOUND));
111113
}
112114

src/main/java/com/cozymate/cozymate_server/domain/rule/service/RuleQueryService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.cozymate.cozymate_server.domain.rule.service;
22

33
import com.cozymate.cozymate_server.domain.mate.Mate;
4+
import com.cozymate.cozymate_server.domain.mate.enums.EntryStatus;
45
import com.cozymate.cozymate_server.domain.mate.repository.MateRepository;
56
import com.cozymate.cozymate_server.domain.member.Member;
67
import com.cozymate.cozymate_server.domain.rule.Rule;
@@ -48,7 +49,8 @@ public List<RuleDetailResponseDTO> getRule(Member member, Long roomId) {
4849
* @return Mate
4950
*/
5051
private Mate findMateByMemberIdAndRoomId(Member member, Long roomId) {
51-
return mateRepository.findByMemberIdAndRoomId(member.getId(), roomId)
52+
return mateRepository.findByRoomIdAndMemberIdAndEntryStatus(roomId, member.getId(),
53+
EntryStatus.JOINED)
5254
.orElseThrow(() -> new GeneralException(ErrorStatus._MATE_OR_ROOM_NOT_FOUND));
5355
}
5456

src/main/java/com/cozymate/cozymate_server/domain/todo/service/TodoCommandService.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.cozymate.cozymate_server.domain.fcm.dto.FcmPushTargetDto.GroupWithOutMeTargetDto;
44
import com.cozymate.cozymate_server.domain.fcm.service.FcmPushService;
55
import com.cozymate.cozymate_server.domain.mate.Mate;
6+
import com.cozymate.cozymate_server.domain.mate.enums.EntryStatus;
67
import com.cozymate.cozymate_server.domain.mate.repository.MateRepository;
78
import com.cozymate.cozymate_server.domain.member.Member;
89
import com.cozymate.cozymate_server.domain.notificationlog.enums.NotificationType;
@@ -181,7 +182,8 @@ public void updateTodoContent(Member member, Long roomId, Long todoId,
181182
}
182183

183184
private Mate getMate(Long memberId, Long roomId) {
184-
return mateRepository.findByMemberIdAndRoomId(memberId, roomId)
185+
return mateRepository.findByRoomIdAndMemberIdAndEntryStatus(roomId, memberId,
186+
EntryStatus.JOINED)
185187
.orElseThrow(() -> new GeneralException(ErrorStatus._MATE_NOT_FOUND));
186188
}
187189

@@ -238,6 +240,7 @@ private void allTodoCompleteNotification(Mate mate) {
238240

239241
/**
240242
* 투두 타입 분류, GROUP, SINGLE을 분류함
243+
*
241244
* @param todoIdList 투두 ID 리스트
242245
* @return TodoType
243246
*/
@@ -252,7 +255,8 @@ private TodoType classifyTodoType(List<Long> todoIdList) {
252255

253256
/**
254257
* 할당자 리스트가 모두 호출한 사람과 같은 방에 있는지 확인
255-
* @param mate 호출한 사람
258+
*
259+
* @param mate 호출한 사람
256260
* @param mateIdList 할당자 리스트
257261
*/
258262
private void checkMateIdListIsSameRoomWithMate(Mate mate, List<Long> mateIdList) {
@@ -265,6 +269,7 @@ private void checkMateIdListIsSameRoomWithMate(Mate mate, List<Long> mateIdList)
265269

266270
/**
267271
* 최대 할당자 수 체크
272+
*
268273
* @param mateIdList 할당자 리스트
269274
*/
270275
private void checkMaxAssignee(List<Long> mateIdList) {

0 commit comments

Comments
 (0)