From 89124eebf8d20b945ed31ea81af8901835db20af Mon Sep 17 00:00:00 2001 From: ghdcksgml1 Date: Sat, 4 Nov 2023 20:26:26 +0900 Subject: [PATCH 1/9] =?UTF-8?q?chore(#93):=20aws=20s3=20=EB=AA=A8=EB=93=88?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- heachi-core/housework-api/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/heachi-core/housework-api/build.gradle b/heachi-core/housework-api/build.gradle index 24c2ce7c..0075a0b2 100644 --- a/heachi-core/housework-api/build.gradle +++ b/heachi-core/housework-api/build.gradle @@ -12,6 +12,7 @@ dependencies { implementation project(':heachi-support:common') implementation project(':heachi-support:logging') implementation project(':heachi-support:external-clients') + implementation project(':heachi-support:aws-s3') // aws s3 모듈 implementation project(':heachi-domain-mysql') implementation project(':heachi-domain-redis') From 513f127049f900d1e8c1e00075fc4a797b066a53 Mon Sep 17 00:00:00 2001 From: ghdcksgml1 Date: Sat, 4 Nov 2023 20:27:08 +0900 Subject: [PATCH 2/9] =?UTF-8?q?feat(#93):=20=EC=BF=BC=EB=A6=AC=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/GroupMemberRepositoryImpl.java | 17 +++++++++++++++ .../HouseworkTodoRepositoryImpl.java | 21 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/group/member/repository/GroupMemberRepositoryImpl.java b/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/group/member/repository/GroupMemberRepositoryImpl.java index 29732d79..827a5fab 100644 --- a/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/group/member/repository/GroupMemberRepositoryImpl.java +++ b/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/group/member/repository/GroupMemberRepositoryImpl.java @@ -9,9 +9,11 @@ import org.springframework.stereotype.Component; import java.util.List; +import java.util.Optional; import static com.heachi.mysql.define.group.info.QGroupInfo.*; import static com.heachi.mysql.define.group.member.QGroupMember.groupMember; +import static com.heachi.mysql.define.housework.todo.QHouseworkTodo.houseworkTodo; import static com.heachi.mysql.define.user.QUser.user; @Component @@ -55,4 +57,19 @@ public List findGroupMemberListByGroupMemberIdList(List group .and(groupMember.status.eq(GroupMemberStatus.ACCEPT))) .fetch(); } + + @Override + public Optional findGroupMemberByUserEmailAndTodoId(String email, Long todoId) { + + return Optional.ofNullable(queryFactory + .selectFrom(groupMember) + .innerJoin(groupMember.user, user) + .where(groupMember.groupInfo.id.eq( + JPAExpressions.select(groupInfo.id) + .from(houseworkTodo) + .innerJoin(houseworkTodo.groupInfo, groupInfo) + .where(houseworkTodo.id.eq(todoId))) + .and(user.email.eq(email))) + .fetchOne()); + } } diff --git a/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/housework/todo/repository/HouseworkTodoRepositoryImpl.java b/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/housework/todo/repository/HouseworkTodoRepositoryImpl.java index 14dcd4a6..06652359 100644 --- a/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/housework/todo/repository/HouseworkTodoRepositoryImpl.java +++ b/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/housework/todo/repository/HouseworkTodoRepositoryImpl.java @@ -1,5 +1,6 @@ package com.heachi.mysql.define.housework.todo.repository; +import com.heachi.mysql.define.housework.todo.HouseworkTodo; import com.heachi.mysql.define.housework.todo.repository.response.HouseworkTodoCount; import com.querydsl.core.types.Projections; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -7,10 +8,14 @@ import org.springframework.stereotype.Component; import java.time.LocalDate; +import java.util.Arrays; import java.util.List; +import java.util.Optional; import static com.heachi.mysql.define.group.info.QGroupInfo.groupInfo; +import static com.heachi.mysql.define.group.member.QGroupMember.groupMember; import static com.heachi.mysql.define.housework.todo.QHouseworkTodo.houseworkTodo; +import static com.heachi.mysql.define.user.QUser.user; import static com.querydsl.core.group.GroupBy.groupBy; import static com.querydsl.core.group.GroupBy.list; @@ -37,4 +42,20 @@ public List findHouseworkTodoCountByGroupInfoIdList(List findHouseworkTodoByIdAndGroupMemberId(Long todoId, Long groupMemberId) { + HouseworkTodo findHouseworkTodo = queryFactory + .selectFrom(houseworkTodo) + .where(houseworkTodo.id.eq(todoId)) + .fetchOne(); + + if (findHouseworkTodo != null) { + return Arrays.stream(findHouseworkTodo.getHouseworkMember().split(",")) + .map(Long::parseLong) + .anyMatch(gmId -> gmId.equals(groupMemberId)) ? Optional.of(findHouseworkTodo) : Optional.empty(); + } else { + return Optional.empty(); + } + } } From fea9bfb0f4cf27fe0b314ce8747685bae50a72a0 Mon Sep 17 00:00:00 2001 From: ghdcksgml1 Date: Sat, 4 Nov 2023 20:27:20 +0900 Subject: [PATCH 3/9] =?UTF-8?q?test(#93):=20=EC=BF=BC=EB=A6=AC=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/GroupMemberRepositoryTest.java | 64 ++++++++++++++ .../HouseworkTodoRepositoryTest.java | 83 ++++++++++++++++--- 2 files changed, 136 insertions(+), 11 deletions(-) diff --git a/heachi-domain-mysql/src/test/java/com/heachi/mysql/define/group/member/repository/GroupMemberRepositoryTest.java b/heachi-domain-mysql/src/test/java/com/heachi/mysql/define/group/member/repository/GroupMemberRepositoryTest.java index 21ddb240..5149fde9 100644 --- a/heachi-domain-mysql/src/test/java/com/heachi/mysql/define/group/member/repository/GroupMemberRepositoryTest.java +++ b/heachi-domain-mysql/src/test/java/com/heachi/mysql/define/group/member/repository/GroupMemberRepositoryTest.java @@ -6,6 +6,14 @@ import com.heachi.mysql.define.group.member.GroupMember; import com.heachi.mysql.define.group.member.constant.GroupMemberRole; import com.heachi.mysql.define.group.member.constant.GroupMemberStatus; +import com.heachi.mysql.define.housework.category.HouseworkCategory; +import com.heachi.mysql.define.housework.category.repository.HouseworkCategoryRepository; +import com.heachi.mysql.define.housework.info.HouseworkInfo; +import com.heachi.mysql.define.housework.info.repository.HouseworkInfoRepository; +import com.heachi.mysql.define.housework.member.HouseworkMember; +import com.heachi.mysql.define.housework.member.repository.HouseworkMemberRepository; +import com.heachi.mysql.define.housework.todo.HouseworkTodo; +import com.heachi.mysql.define.housework.todo.repository.HouseworkTodoRepository; import com.heachi.mysql.define.user.User; import com.heachi.mysql.define.user.constant.UserPlatformType; import com.heachi.mysql.define.user.constant.UserRole; @@ -17,6 +25,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import java.time.LocalDate; + import static org.assertj.core.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*; @@ -32,8 +42,24 @@ class GroupMemberRepositoryTest extends TestConfig { @Autowired private GroupInfoRepository groupInfoRepository; + @Autowired + private HouseworkCategoryRepository houseworkCategoryRepository; + + @Autowired + private HouseworkInfoRepository houseworkInfoRepository; + + @Autowired + private HouseworkTodoRepository houseworkTodoRepository; + + @Autowired + private HouseworkMemberRepository houseworkMemberRepository; + @AfterEach void tearDown() { + houseworkTodoRepository.deleteAllInBatch(); + houseworkMemberRepository.deleteAllInBatch(); + houseworkInfoRepository.deleteAllInBatch(); + houseworkCategoryRepository.deleteAllInBatch(); groupMemberRepository.deleteAllInBatch(); groupInfoRepository.deleteAllInBatch(); userRepository.deleteAllInBatch(); @@ -53,4 +79,42 @@ void existsGroupMemberByUserEmailAndGroupInfoId() { // then assertThat(result).isTrue(); } + + @Test + @DisplayName("Email과 todoId를 통해 GroupMember를 조회한다.") + void findGroupMemberByUserEmailAndTodoId() { + // given + User user = userRepository.save(generateUser()); + User user2 = userRepository.save(generateCustomUser("ghdcksgml1@naver.com", "010-1111-1111")); + User user3 = userRepository.save(generateCustomUser("ghdcksgml2@naver.com", "010-2222-2222")); + GroupInfo groupInfo = groupInfoRepository.save(generateGroupInfo(user)); + GroupInfo groupInfo2 = groupInfoRepository.save(generateGroupInfo(user2)); + GroupInfo groupInfo3 = groupInfoRepository.save(generateGroupInfo(user3)); + GroupMember groupMember = groupMemberRepository.save(generateGroupMember(user, groupInfo)); + groupMemberRepository.save(generateGroupMember(user2, groupInfo)); + groupMemberRepository.save(generateGroupMember(user3, groupInfo)); + groupMemberRepository.save(generateGroupMember(user, groupInfo3)); + groupMemberRepository.save(generateGroupMember(user3, groupInfo2)); + + HouseworkCategory houseworkCategory = houseworkCategoryRepository.save(generateHouseworkCategory()); + HouseworkInfo houseworkInfo = houseworkInfoRepository.save(generateHouseworkInfo(houseworkCategory)); + HouseworkInfo houseworkInfo2 = houseworkInfoRepository.save(generateHouseworkInfo(houseworkCategory)); + HouseworkInfo houseworkInfo3 = houseworkInfoRepository.save(generateHouseworkInfo(houseworkCategory)); + + HouseworkMember houseworkMember = houseworkMemberRepository.save(generateHouseworkMember(groupMember, houseworkInfo)); + HouseworkInfo findHouseworkInfo = houseworkInfoRepository.findHouseworkInfoByIdJoinFetchHouseworkMembers(houseworkInfo.getId()).get(); + HouseworkInfo findHouseworkInfo2 = houseworkInfoRepository.findHouseworkInfoByIdJoinFetchHouseworkMembers(houseworkInfo2.getId()).get(); + HouseworkInfo findHouseworkInfo3 = houseworkInfoRepository.findHouseworkInfoByIdJoinFetchHouseworkMembers(houseworkInfo3.getId()).get(); + + HouseworkTodo houseworkTodo = houseworkTodoRepository.save(generateHouseworkTodo(findHouseworkInfo, groupInfo, LocalDate.now())); + HouseworkTodo houseworkTodo2 = houseworkTodoRepository.save(generateHouseworkTodo(findHouseworkInfo2, groupInfo2, LocalDate.now())); + HouseworkTodo houseworkTodo3 = houseworkTodoRepository.save(generateHouseworkTodo(findHouseworkInfo3, groupInfo3, LocalDate.now())); + + // when + GroupMember findGroupMember = groupMemberRepository.findGroupMemberByUserEmailAndTodoId(user.getEmail(), houseworkTodo.getId()).get(); + + // then + assertThat(findGroupMember.getId()).isEqualTo(groupMember.getId()); + assertThat(findGroupMember.getUser().getId()).isEqualTo(user.getId()); + } } \ No newline at end of file diff --git a/heachi-domain-mysql/src/test/java/com/heachi/mysql/define/housework/todo/repository/HouseworkTodoRepositoryTest.java b/heachi-domain-mysql/src/test/java/com/heachi/mysql/define/housework/todo/repository/HouseworkTodoRepositoryTest.java index 80dea722..c87036ac 100644 --- a/heachi-domain-mysql/src/test/java/com/heachi/mysql/define/housework/todo/repository/HouseworkTodoRepositoryTest.java +++ b/heachi-domain-mysql/src/test/java/com/heachi/mysql/define/housework/todo/repository/HouseworkTodoRepositoryTest.java @@ -20,6 +20,7 @@ import com.heachi.mysql.define.user.constant.UserPlatformType; import com.heachi.mysql.define.user.constant.UserRole; import com.heachi.mysql.define.user.repository.UserRepository; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -61,34 +62,57 @@ class HouseworkTodoRepositoryTest extends TestConfig { @Autowired private HouseworkMemberRepository houseworkMemberRepository; + @AfterEach + void tearDown() { + houseworkTodoRepository.deleteAllInBatch(); + houseworkMemberRepository.deleteAllInBatch(); + houseworkInfoRepository.deleteAllInBatch(); + houseworkCategoryRepository.deleteAllInBatch(); + groupMemberRepository.deleteAllInBatch(); + groupInfoRepository.deleteAllInBatch(); + userRepository.deleteAllInBatch(); + } + @Test - @DisplayName("GroupInfoId와 Date를 이용해 값을 맵으로 조회한다.") - void findByGroupInfoAndDateReturnSetTest() { + @DisplayName("groupInfoId 리스트를 받아 해당 그룹들의 오늘 날짜의 HouseworkTodo의 개수를 셀 수 있는 DTO를 반환해준다.") + void findHouseworkTodoCountByGroupInfoIdList() { // given User user = userRepository.save(generateUser()); + User user2 = userRepository.save(generateCustomUser("ghdcksgml1@naver.com", "010-1111-1111")); + User user3 = userRepository.save(generateCustomUser("ghdcksgml2@naver.com", "010-2222-2222")); GroupInfo groupInfo = groupInfoRepository.save(generateGroupInfo(user)); + GroupInfo groupInfo2 = groupInfoRepository.save(generateGroupInfo(user2)); + GroupInfo groupInfo3 = groupInfoRepository.save(generateGroupInfo(user3)); GroupMember groupMember = groupMemberRepository.save(generateGroupMember(user, groupInfo)); + groupMemberRepository.save(generateGroupMember(user2, groupInfo)); + groupMemberRepository.save(generateGroupMember(user3, groupInfo)); + groupMemberRepository.save(generateGroupMember(user, groupInfo3)); + groupMemberRepository.save(generateGroupMember(user3, groupInfo2)); HouseworkCategory houseworkCategory = houseworkCategoryRepository.save(generateHouseworkCategory()); HouseworkInfo houseworkInfo = houseworkInfoRepository.save(generateHouseworkInfo(houseworkCategory)); + HouseworkInfo houseworkInfo2 = houseworkInfoRepository.save(generateHouseworkInfo(houseworkCategory)); + HouseworkInfo houseworkInfo3 = houseworkInfoRepository.save(generateHouseworkInfo(houseworkCategory)); HouseworkMember houseworkMember = houseworkMemberRepository.save(generateHouseworkMember(groupMember, houseworkInfo)); HouseworkInfo findHouseworkInfo = houseworkInfoRepository.findHouseworkInfoByIdJoinFetchHouseworkMembers(houseworkInfo.getId()).get(); + HouseworkInfo findHouseworkInfo2 = houseworkInfoRepository.findHouseworkInfoByIdJoinFetchHouseworkMembers(houseworkInfo2.getId()).get(); + HouseworkInfo findHouseworkInfo3 = houseworkInfoRepository.findHouseworkInfoByIdJoinFetchHouseworkMembers(houseworkInfo3.getId()).get(); - HouseworkTodo houseworkTodo = houseworkTodoRepository.save(generateHouseworkTodo(findHouseworkInfo, groupInfo, LocalDate.of(2022, 10, 10))); + HouseworkTodo houseworkTodo = houseworkTodoRepository.save(generateHouseworkTodo(findHouseworkInfo, groupInfo, LocalDate.now())); + HouseworkTodo houseworkTodo2 = houseworkTodoRepository.save(generateHouseworkTodo(findHouseworkInfo2, groupInfo2, LocalDate.now())); + HouseworkTodo houseworkTodo3 = houseworkTodoRepository.save(generateHouseworkTodo(findHouseworkInfo3, groupInfo3, LocalDate.now())); // when - Map result = houseworkTodoRepository.findByGroupInfoAndDate(groupInfo.getId(), LocalDate.of(2022, 10, 10)) - .stream() - .collect(Collectors.toMap(obj -> obj.getId(), obj -> obj)); + List houseworkTodoCountByGroupInfoIdList = houseworkTodoRepository.findHouseworkTodoCountByGroupInfoIdList(List.of(groupInfo.getId(), groupInfo2.getId(), groupInfo3.getId())); // then - assertThat(result.get(1L).getDate()).isEqualTo(LocalDate.of(2022, 10, 10)); + assertThat(houseworkTodoCountByGroupInfoIdList.size()).isEqualTo(3); } @Test - @DisplayName("groupInfoId 리스트를 받아 해당 그룹들의 오늘 날짜의 HouseworkTodo의 개수를 셀 수 있는 DTO를 반환해준다.") - void findHouseworkTodoCountByGroupInfoIdList() { + @DisplayName("todoId와 email을 통해 해당 그룹원이 해당 집안일의 담당자인지 확인한다.") + void findHouseworkTodoByIdAndGroupMemberId() { // given User user = userRepository.save(generateUser()); User user2 = userRepository.save(generateCustomUser("ghdcksgml1@naver.com", "010-1111-1111")); @@ -117,9 +141,46 @@ void findHouseworkTodoCountByGroupInfoIdList() { HouseworkTodo houseworkTodo3 = houseworkTodoRepository.save(generateHouseworkTodo(findHouseworkInfo3, groupInfo3, LocalDate.now())); // when - List houseworkTodoCountByGroupInfoIdList = houseworkTodoRepository.findHouseworkTodoCountByGroupInfoIdList(List.of(groupInfo.getId(), groupInfo2.getId(), groupInfo3.getId())); + HouseworkTodo findTodo = houseworkTodoRepository.findHouseworkTodoByIdAndGroupMemberId(houseworkTodo.getId(), groupMember.getId()).get(); // then - assertThat(houseworkTodoCountByGroupInfoIdList.size()).isEqualTo(3); + assertThat(findTodo.getHouseworkMember()).isEqualTo(String.valueOf(groupMember.getId())); + } + + @Test + @DisplayName("todoId로 조회는 되지만 groupMemberId가 맞지 않는 경우 Optional.empty()를 반환한다.") + void findHouseworkTodoByIdAndGroupMemberIdFail() { + // given + User user = userRepository.save(generateUser()); + User user2 = userRepository.save(generateCustomUser("ghdcksgml1@naver.com", "010-1111-1111")); + User user3 = userRepository.save(generateCustomUser("ghdcksgml2@naver.com", "010-2222-2222")); + GroupInfo groupInfo = groupInfoRepository.save(generateGroupInfo(user)); + GroupInfo groupInfo2 = groupInfoRepository.save(generateGroupInfo(user2)); + GroupInfo groupInfo3 = groupInfoRepository.save(generateGroupInfo(user3)); + GroupMember groupMember = groupMemberRepository.save(generateGroupMember(user, groupInfo)); + groupMemberRepository.save(generateGroupMember(user2, groupInfo)); + groupMemberRepository.save(generateGroupMember(user3, groupInfo)); + groupMemberRepository.save(generateGroupMember(user, groupInfo3)); + groupMemberRepository.save(generateGroupMember(user3, groupInfo2)); + + HouseworkCategory houseworkCategory = houseworkCategoryRepository.save(generateHouseworkCategory()); + HouseworkInfo houseworkInfo = houseworkInfoRepository.save(generateHouseworkInfo(houseworkCategory)); + HouseworkInfo houseworkInfo2 = houseworkInfoRepository.save(generateHouseworkInfo(houseworkCategory)); + HouseworkInfo houseworkInfo3 = houseworkInfoRepository.save(generateHouseworkInfo(houseworkCategory)); + + HouseworkMember houseworkMember = houseworkMemberRepository.save(generateHouseworkMember(groupMember, houseworkInfo)); + HouseworkInfo findHouseworkInfo = houseworkInfoRepository.findHouseworkInfoByIdJoinFetchHouseworkMembers(houseworkInfo.getId()).get(); + HouseworkInfo findHouseworkInfo2 = houseworkInfoRepository.findHouseworkInfoByIdJoinFetchHouseworkMembers(houseworkInfo2.getId()).get(); + HouseworkInfo findHouseworkInfo3 = houseworkInfoRepository.findHouseworkInfoByIdJoinFetchHouseworkMembers(houseworkInfo3.getId()).get(); + + HouseworkTodo houseworkTodo = houseworkTodoRepository.save(generateHouseworkTodo(findHouseworkInfo, groupInfo, LocalDate.now())); + HouseworkTodo houseworkTodo2 = houseworkTodoRepository.save(generateHouseworkTodo(findHouseworkInfo2, groupInfo2, LocalDate.now())); + HouseworkTodo houseworkTodo3 = houseworkTodoRepository.save(generateHouseworkTodo(findHouseworkInfo3, groupInfo3, LocalDate.now())); + + // when + var findTodo = houseworkTodoRepository.findHouseworkTodoByIdAndGroupMemberId(houseworkTodo.getId(), 2L); + + // then + assertThat(findTodo.isEmpty()).isTrue(); } } \ No newline at end of file From 10847b584e9b68cc5a594abc6b165247587bfe01 Mon Sep 17 00:00:00 2001 From: ghdcksgml1 Date: Sat, 4 Nov 2023 20:27:43 +0900 Subject: [PATCH 4/9] =?UTF-8?q?feat(#93):=20=EC=BF=BC=EB=A6=AC=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=EB=93=9C=20interface=EC=97=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../group/member/repository/GroupMemberRepositoryCustom.java | 4 ++++ .../todo/repository/HouseworkTodoRepositoryCustom.java | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/group/member/repository/GroupMemberRepositoryCustom.java b/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/group/member/repository/GroupMemberRepositoryCustom.java index f4279896..84cfaa79 100644 --- a/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/group/member/repository/GroupMemberRepositoryCustom.java +++ b/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/group/member/repository/GroupMemberRepositoryCustom.java @@ -3,6 +3,7 @@ import com.heachi.mysql.define.group.member.GroupMember; import java.util.List; +import java.util.Optional; public interface GroupMemberRepositoryCustom { @@ -15,4 +16,7 @@ public interface GroupMemberRepositoryCustom { // 그룹 멤버의 ID 리스트에 해당하는 그룹멤버들을 조회한다. (그룹원인 경우만 = ACCEPT) - 집안일 추가시 담당자 지정을 위해 필요 public List findGroupMemberListByGroupMemberIdList(List groupMemberIdList); + // Email과 todoId를 통해 GroupMember를 조회한다. + public Optional findGroupMemberByUserEmailAndTodoId(String email, Long todoId); + } diff --git a/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/housework/todo/repository/HouseworkTodoRepositoryCustom.java b/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/housework/todo/repository/HouseworkTodoRepositoryCustom.java index 6373b50f..323813d1 100644 --- a/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/housework/todo/repository/HouseworkTodoRepositoryCustom.java +++ b/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/housework/todo/repository/HouseworkTodoRepositoryCustom.java @@ -1,11 +1,16 @@ package com.heachi.mysql.define.housework.todo.repository; +import com.heachi.mysql.define.housework.todo.HouseworkTodo; import com.heachi.mysql.define.housework.todo.repository.response.HouseworkTodoCount; import java.util.List; +import java.util.Optional; public interface HouseworkTodoRepositoryCustom { // groupInfoId 리스트를 받아 해당 그룹들의 오늘 날짜의 HouseworkTodo의 개수를 셀 수 있는 DTO를 반환하는 쿼리 public List findHouseworkTodoCountByGroupInfoIdList(List groupInfoIdList); + + // todoId와 groupMemberId를 통해 해당 그룹원이 해당 집안일의 담당자인지 확인한다. + public Optional findHouseworkTodoByIdAndGroupMemberId(Long todoId, Long groupMemberId); } From 7ba3671a8e3730b8ceb67714f19a46974183a608 Mon Sep 17 00:00:00 2001 From: ghdcksgml1 Date: Sat, 4 Nov 2023 20:28:19 +0900 Subject: [PATCH 5/9] refactor(#93): verifierTodo String -> Long --- .../mysql/define/housework/todo/QHouseworkTodo.java | 2 +- .../mysql/define/housework/todo/HouseworkTodo.java | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/heachi-domain-mysql/src/main/generated/com/heachi/mysql/define/housework/todo/QHouseworkTodo.java b/heachi-domain-mysql/src/main/generated/com/heachi/mysql/define/housework/todo/QHouseworkTodo.java index 699a32e3..9f8fc523 100644 --- a/heachi-domain-mysql/src/main/generated/com/heachi/mysql/define/housework/todo/QHouseworkTodo.java +++ b/heachi-domain-mysql/src/main/generated/com/heachi/mysql/define/housework/todo/QHouseworkTodo.java @@ -56,7 +56,7 @@ public class QHouseworkTodo extends EntityPathBase { public final DateTimePath verificationTime = createDateTime("verificationTime", java.time.LocalDateTime.class); - public final StringPath verifierId = createString("verifierId"); + public final NumberPath verifierId = createNumber("verifierId", Long.class); public QHouseworkTodo(String variable) { this(HouseworkTodo.class, forVariable(variable), INITS); diff --git a/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/housework/todo/HouseworkTodo.java b/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/housework/todo/HouseworkTodo.java index e7f22876..fa749900 100644 --- a/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/housework/todo/HouseworkTodo.java +++ b/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/housework/todo/HouseworkTodo.java @@ -69,7 +69,7 @@ public class HouseworkTodo extends BaseEntity { private String verificationPhotoURL; // 다른 사용자가 확인할 수 있는 인증 사진 URL @Column(name = "VERIFIER_ID") - private String verifierId; // 해당 집안일을 인증해준 사용자 + private Long verifierId; // 해당 집안일을 인증한 사용자 (GroupMemberId) @Column(name = "VERIFICATION_TIME") private LocalDateTime verificationTime; // 인증된 시각 @@ -77,7 +77,7 @@ public class HouseworkTodo extends BaseEntity { @Builder private HouseworkTodo(HouseworkInfo houseworkInfo, GroupInfo groupInfo, String houseworkMember, String category, String title, String detail, Integer idx, HouseworkTodoStatus status, LocalDate date, - LocalTime endTime, String verificationPhotoURL, String verifierId, LocalDateTime verificationTime) { + LocalTime endTime, String verificationPhotoURL, Long verifierId, LocalDateTime verificationTime) { this.houseworkInfo = houseworkInfo; this.groupInfo = groupInfo; this.houseworkMember = houseworkMember; @@ -93,6 +93,13 @@ private HouseworkTodo(HouseworkInfo houseworkInfo, GroupInfo groupInfo, String h this.verificationTime = verificationTime; } + // 집안일 인증 + public void verifyHousework(String verificationPhotoURL, Long verifierId) { + this.verificationPhotoURL = verificationPhotoURL; + this.verifierId = verifierId; + this.verificationTime = LocalDateTime.now(); + } + public static HouseworkTodo makeTodoReferInfo(HouseworkInfo houseworkInfo, GroupInfo groupInfo, LocalDate date) { return HouseworkTodo.builder() From 8fbf097d57f4b1416519260f51ba31b9ca8b08e8 Mon Sep 17 00:00:00 2001 From: ghdcksgml1 Date: Sat, 4 Nov 2023 20:29:05 +0900 Subject: [PATCH 6/9] =?UTF-8?q?feat(#93):=20verifyTodo=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../housework/todo/TodoController.java | 20 ++++++++++++++++ .../todo/request/VerifyTodoRequest.java | 22 ++++++++++++++++++ .../service/housework/todo/TodoService.java | 23 +++++++++++++++++++ .../request/VerifyTodoServiceRequest.java | 18 +++++++++++++++ .../housework/todo/response/TodoResponse.java | 4 ++-- .../common/exception/ExceptionMessage.java | 1 + 6 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 heachi-core/housework-api/src/main/java/com/heachi/housework/api/controller/housework/todo/request/VerifyTodoRequest.java create mode 100644 heachi-core/housework-api/src/main/java/com/heachi/housework/api/service/housework/todo/request/VerifyTodoServiceRequest.java diff --git a/heachi-core/housework-api/src/main/java/com/heachi/housework/api/controller/housework/todo/TodoController.java b/heachi-core/housework-api/src/main/java/com/heachi/housework/api/controller/housework/todo/TodoController.java index c65a2ec6..c3127e64 100644 --- a/heachi-core/housework-api/src/main/java/com/heachi/housework/api/controller/housework/todo/TodoController.java +++ b/heachi-core/housework-api/src/main/java/com/heachi/housework/api/controller/housework/todo/TodoController.java @@ -2,9 +2,13 @@ import com.heachi.admin.common.response.JsonResult; import com.heachi.external.clients.auth.response.UserInfoResponse; +import com.heachi.housework.api.controller.housework.todo.request.VerifyTodoRequest; import com.heachi.housework.api.service.auth.AuthExternalService; import com.heachi.housework.api.service.housework.todo.TodoService; import com.heachi.housework.api.service.housework.todo.request.TodoSelectRequest; +import com.heachi.housework.api.service.housework.todo.request.VerifyTodoServiceRequest; +import com.heachi.s3.api.service.AwsS3Service; +import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; @@ -19,6 +23,7 @@ public class TodoController { private final AuthExternalService authExternalService; private final TodoService todoService; + private final AwsS3Service awsS3Service; // Todo List 가져오기 @GetMapping("/{groupId}") @@ -30,4 +35,19 @@ public JsonResult selectTodo(@RequestHeader(name = "Authorization") String au return JsonResult.successOf(todoService.cachedSelectTodo( TodoSelectRequest.builder().groupId(groupId).date(date).build())); } + + // 집안일 인증하기 + @PostMapping("/verify") + public JsonResult verifyTodo(@RequestHeader(name = "Authorization") String authorization, + @Valid @ModelAttribute(name = "verifyTodoRequest") VerifyTodoRequest verifyTodoRequest) { + UserInfoResponse userInfo = authExternalService.userAuthenticateAndGroupMatch(authorization, verifyTodoRequest.getGroupId()); + String uploadedImageURL = awsS3Service.uploadImage(verifyTodoRequest.getFile()); + todoService.verifyTodo(VerifyTodoServiceRequest.builder() + .verifyImageURL(uploadedImageURL) + .todoId(verifyTodoRequest.getTodoId()) + .email(userInfo.getEmail()) + .build()); + + return JsonResult.successOf("사진이 정상적으로 저장되었습니다."); + } } diff --git a/heachi-core/housework-api/src/main/java/com/heachi/housework/api/controller/housework/todo/request/VerifyTodoRequest.java b/heachi-core/housework-api/src/main/java/com/heachi/housework/api/controller/housework/todo/request/VerifyTodoRequest.java new file mode 100644 index 00000000..0354600c --- /dev/null +++ b/heachi-core/housework-api/src/main/java/com/heachi/housework/api/controller/housework/todo/request/VerifyTodoRequest.java @@ -0,0 +1,22 @@ +package com.heachi.housework.api.controller.housework.todo.request; + +import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; +import org.springframework.web.multipart.MultipartFile; + +@Getter +@ToString +@AllArgsConstructor +public class VerifyTodoRequest { + @NotNull + private MultipartFile file; // (필수) 사진 + @NotNull + private Long todoId; // (필수) 집안일 아이디 + @NotNull + private Long groupId; // (필수) 그룹 아이디 + private String comment; // (선택) 사진에 대한 설명 +} diff --git a/heachi-core/housework-api/src/main/java/com/heachi/housework/api/service/housework/todo/TodoService.java b/heachi-core/housework-api/src/main/java/com/heachi/housework/api/service/housework/todo/TodoService.java index 24ed3962..3f87a8b8 100644 --- a/heachi-core/housework-api/src/main/java/com/heachi/housework/api/service/housework/todo/TodoService.java +++ b/heachi-core/housework-api/src/main/java/com/heachi/housework/api/service/housework/todo/TodoService.java @@ -1,8 +1,12 @@ package com.heachi.housework.api.service.housework.todo; +import com.heachi.admin.common.exception.ExceptionMessage; +import com.heachi.admin.common.exception.group.member.GroupMemberException; +import com.heachi.admin.common.exception.housework.HouseworkException; import com.heachi.admin.common.utils.CachingStrategy; import com.heachi.admin.common.utils.DayOfWeekUtils; import com.heachi.housework.api.service.housework.todo.request.TodoSelectRequest; +import com.heachi.housework.api.service.housework.todo.request.VerifyTodoServiceRequest; import com.heachi.housework.api.service.housework.todo.response.TodoResponse; import com.heachi.mysql.define.group.member.GroupMember; import com.heachi.mysql.define.group.member.repository.GroupMemberRepository; @@ -87,6 +91,25 @@ public List selectTodo(TodoSelectRequest request) { .collect(Collectors.toList()); } + @Transactional + public void verifyTodo(VerifyTodoServiceRequest request) { + // groupMemberId 가져오기 + GroupMember groupMember = groupMemberRepository.findGroupMemberByUserEmailAndTodoId(request.getEmail(), request.getTodoId()).orElseThrow(() -> { + log.warn(">>>> 매칭되는 groupMember를 찾지 못했습니다."); + + throw new GroupMemberException(ExceptionMessage.GROUP_MEMBER_NOT_FOUND); + }); + + HouseworkTodo houseworkTodo = houseworkTodoRepository.findHouseworkTodoByIdAndGroupMemberId(request.getTodoId(), groupMember.getId()).orElseThrow(() -> { + log.warn(">>>> 해당 그룹멤버는 집안일의 담당자가 아닙니다."); + + throw new HouseworkException(ExceptionMessage.HOUSEWORK_TODO_PERMISSION_DENIED); + }); + + // 담당자가 맞다면, 업데이트 + houseworkTodo.verifyHousework(request.getVerifyImageURL(), groupMember.getId()); + } + private TodoList caching(TodoSelectRequest req, List todoResponseList) { return todoListRepository.save(TodoList.builder() // List => TodoList 후 save diff --git a/heachi-core/housework-api/src/main/java/com/heachi/housework/api/service/housework/todo/request/VerifyTodoServiceRequest.java b/heachi-core/housework-api/src/main/java/com/heachi/housework/api/service/housework/todo/request/VerifyTodoServiceRequest.java new file mode 100644 index 00000000..d7f8bad7 --- /dev/null +++ b/heachi-core/housework-api/src/main/java/com/heachi/housework/api/service/housework/todo/request/VerifyTodoServiceRequest.java @@ -0,0 +1,18 @@ +package com.heachi.housework.api.service.housework.todo.request; + +import lombok.Builder; +import lombok.Getter; + +@Getter +public class VerifyTodoServiceRequest { + private Long todoId; // 집안일 아이디 + private String email; // 인증 요청 이메일 + private String verifyImageURL; // 인증 사진 + + @Builder + private VerifyTodoServiceRequest(Long todoId, String email, String verifyImageURL) { + this.todoId = todoId; + this.email = email; + this.verifyImageURL = verifyImageURL; + } +} diff --git a/heachi-core/housework-api/src/main/java/com/heachi/housework/api/service/housework/todo/response/TodoResponse.java b/heachi-core/housework-api/src/main/java/com/heachi/housework/api/service/housework/todo/response/TodoResponse.java index 76b5c94d..cffe2eb0 100644 --- a/heachi-core/housework-api/src/main/java/com/heachi/housework/api/service/housework/todo/response/TodoResponse.java +++ b/heachi-core/housework-api/src/main/java/com/heachi/housework/api/service/housework/todo/response/TodoResponse.java @@ -30,13 +30,13 @@ public class TodoResponse { private LocalDate date; private LocalTime endTime; private String verificationPhotoURL; - private String verifierId; + private Long verifierId; private LocalDateTime verificationTime; @Builder private TodoResponse(Long id, List houseworkMembers, String category, String title, String detail, Integer idx, HouseworkTodoStatus status, LocalDate date, LocalTime endTime, - String verificationPhotoURL, String verifierId, LocalDateTime verificationTime) { + String verificationPhotoURL, Long verifierId, LocalDateTime verificationTime) { this.id = id; this.houseworkMembers = houseworkMembers; this.category = category; diff --git a/heachi-support/common/src/main/java/com/heachi/admin/common/exception/ExceptionMessage.java b/heachi-support/common/src/main/java/com/heachi/admin/common/exception/ExceptionMessage.java index ce087029..97e31769 100644 --- a/heachi-support/common/src/main/java/com/heachi/admin/common/exception/ExceptionMessage.java +++ b/heachi-support/common/src/main/java/com/heachi/admin/common/exception/ExceptionMessage.java @@ -60,6 +60,7 @@ public enum ExceptionMessage { HOUSEWORK_ADD_FAIL("집안일 추가에 실패했습니다."), HOUSEWORK_ADD_PERMISSION_DENIED("집안일을 추가할 권한이 없습니다."), HOUSEWORK_CATEGORY_NOT_FOUND("집안일 카테고리 정보를 찾을 수 없습니다."), + HOUSEWORK_TODO_PERMISSION_DENIED("해당 집안일의 담당자가 아닙니다."), ; private final String text; From 29635d6b9674f0a22a83d0d26e165c8fb2d6c943 Mon Sep 17 00:00:00 2001 From: ghdcksgml1 Date: Sat, 4 Nov 2023 20:29:22 +0900 Subject: [PATCH 7/9] =?UTF-8?q?test(#93):=20verify=20Todo=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../housework/todo/TodoServiceTest.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/heachi-core/housework-api/src/test/java/com/heachi/housework/api/service/housework/todo/TodoServiceTest.java b/heachi-core/housework-api/src/test/java/com/heachi/housework/api/service/housework/todo/TodoServiceTest.java index 4cabd517..357209cd 100644 --- a/heachi-core/housework-api/src/test/java/com/heachi/housework/api/service/housework/todo/TodoServiceTest.java +++ b/heachi-core/housework-api/src/test/java/com/heachi/housework/api/service/housework/todo/TodoServiceTest.java @@ -2,6 +2,7 @@ import com.heachi.housework.TestConfig; import com.heachi.housework.api.service.housework.todo.request.TodoSelectRequest; +import com.heachi.housework.api.service.housework.todo.request.VerifyTodoServiceRequest; import com.heachi.housework.api.service.housework.todo.response.TodoResponse; import com.heachi.housework.api.service.housework.todo.response.TodoUser; import com.heachi.mysql.define.group.info.GroupInfo; @@ -14,6 +15,7 @@ import com.heachi.mysql.define.housework.info.repository.HouseworkInfoRepository; import com.heachi.mysql.define.housework.member.HouseworkMember; import com.heachi.mysql.define.housework.member.repository.HouseworkMemberRepository; +import com.heachi.mysql.define.housework.todo.HouseworkTodo; import com.heachi.mysql.define.housework.todo.constant.HouseworkTodoStatus; import com.heachi.mysql.define.housework.todo.repository.HouseworkTodoRepository; import com.heachi.mysql.define.user.User; @@ -179,4 +181,49 @@ void test4() { assertThat(result.getTodoList().size()).isEqualTo(2); System.out.println("result = " + result); } + + @Test + @DisplayName("Todo 담당자가 사진을 업로드하면 정상적으로 사진이 저장된다.") + void test5() { + // given + User user = userRepository.save(generateUser()); + User user2 = userRepository.save(generateCustomUser("ghdcksgml1@naver.com", "010-1111-1111")); + User user3 = userRepository.save(generateCustomUser("ghdcksgml2@naver.com", "010-2222-2222")); + GroupInfo groupInfo = groupInfoRepository.save(generateGroupInfo(user)); + GroupInfo groupInfo2 = groupInfoRepository.save(generateGroupInfo(user2)); + GroupInfo groupInfo3 = groupInfoRepository.save(generateGroupInfo(user3)); + GroupMember groupMember = groupMemberRepository.save(generateGroupMember(user, groupInfo)); + groupMemberRepository.save(generateGroupMember(user2, groupInfo)); + groupMemberRepository.save(generateGroupMember(user3, groupInfo)); + groupMemberRepository.save(generateGroupMember(user, groupInfo3)); + groupMemberRepository.save(generateGroupMember(user3, groupInfo2)); + + HouseworkCategory houseworkCategory = houseworkCategoryRepository.save(generateHouseworkCategory()); + HouseworkInfo houseworkInfo = houseworkInfoRepository.save(generateHouseworkInfo(houseworkCategory)); + HouseworkInfo houseworkInfo2 = houseworkInfoRepository.save(generateHouseworkInfo(houseworkCategory)); + HouseworkInfo houseworkInfo3 = houseworkInfoRepository.save(generateHouseworkInfo(houseworkCategory)); + + HouseworkMember houseworkMember = houseworkMemberRepository.save(generateHouseworkMember(groupMember, houseworkInfo)); + HouseworkInfo findHouseworkInfo = houseworkInfoRepository.findHouseworkInfoByIdJoinFetchHouseworkMembers(houseworkInfo.getId()).get(); + HouseworkInfo findHouseworkInfo2 = houseworkInfoRepository.findHouseworkInfoByIdJoinFetchHouseworkMembers(houseworkInfo2.getId()).get(); + HouseworkInfo findHouseworkInfo3 = houseworkInfoRepository.findHouseworkInfoByIdJoinFetchHouseworkMembers(houseworkInfo3.getId()).get(); + + HouseworkTodo houseworkTodo = houseworkTodoRepository.save(generateHouseworkTodo(findHouseworkInfo, groupInfo, LocalDate.now())); + HouseworkTodo houseworkTodo2 = houseworkTodoRepository.save(generateHouseworkTodo(findHouseworkInfo2, groupInfo2, LocalDate.now())); + HouseworkTodo houseworkTodo3 = houseworkTodoRepository.save(generateHouseworkTodo(findHouseworkInfo3, groupInfo3, LocalDate.now())); + + String uploadedImageURL = "abcd.sfsa"; + + // when + todoService.verifyTodo(VerifyTodoServiceRequest.builder() + .verifyImageURL(uploadedImageURL) + .todoId(houseworkTodo.getId()) + .email(user.getEmail()) + .build()); + HouseworkTodo findHouseworkTodo = houseworkTodoRepository.findById(houseworkTodo.getId()).get(); + + // then + assertThat(findHouseworkTodo.getVerificationPhotoURL()).isEqualTo(uploadedImageURL); + assertThat(findHouseworkTodo.getVerificationTime()).isNotNull(); + } } \ No newline at end of file From 2ccd7f1689f3f2d327ae7acc71b0de7f77652d12 Mon Sep 17 00:00:00 2001 From: ghdcksgml1 Date: Sat, 4 Nov 2023 20:56:43 +0900 Subject: [PATCH 8/9] =?UTF-8?q?fix(#93):=20string=EC=9D=98=20=EA=B8=B8?= =?UTF-8?q?=EC=9D=B4=EA=B0=80=200=EC=9D=BC=EB=95=8C=20=EC=98=A4=EB=A5=98?= =?UTF-8?q?=EB=B0=9C=EC=83=9D=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../housework/todo/repository/HouseworkTodoRepositoryImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/housework/todo/repository/HouseworkTodoRepositoryImpl.java b/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/housework/todo/repository/HouseworkTodoRepositoryImpl.java index 06652359..1d29d8e2 100644 --- a/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/housework/todo/repository/HouseworkTodoRepositoryImpl.java +++ b/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/housework/todo/repository/HouseworkTodoRepositoryImpl.java @@ -50,7 +50,7 @@ public Optional findHouseworkTodoByIdAndGroupMemberId(Long todoId .where(houseworkTodo.id.eq(todoId)) .fetchOne(); - if (findHouseworkTodo != null) { + if (findHouseworkTodo != null && !findHouseworkTodo.getHouseworkMember().isEmpty()) { return Arrays.stream(findHouseworkTodo.getHouseworkMember().split(",")) .map(Long::parseLong) .anyMatch(gmId -> gmId.equals(groupMemberId)) ? Optional.of(findHouseworkTodo) : Optional.empty(); From dd9989b6cf9ba82708d841ee54520858b35e21a7 Mon Sep 17 00:00:00 2001 From: ghdcksgml1 Date: Sun, 5 Nov 2023 16:44:53 +0900 Subject: [PATCH 9/9] =?UTF-8?q?fix(#93):=20Merge=20Conflict=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0=20=ED=9B=84=20=EB=B9=8C=EB=93=9C=20=EC=98=A4=EB=A5=98?= =?UTF-8?q?=EB=82=98=EB=8A=94=20=EB=B6=80=EB=B6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../group/member/repository/GroupMemberRepositoryImpl.java | 7 ++++--- .../info/repository/HouseworkInfoRepositoryImpl.java | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/group/member/repository/GroupMemberRepositoryImpl.java b/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/group/member/repository/GroupMemberRepositoryImpl.java index d3ceff90..496c9aaa 100644 --- a/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/group/member/repository/GroupMemberRepositoryImpl.java +++ b/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/group/member/repository/GroupMemberRepositoryImpl.java @@ -70,13 +70,14 @@ public Optional findGroupMemberByUserEmailAndTodoId(String email, L .from(houseworkTodo) .innerJoin(houseworkTodo.groupInfo, groupInfo) .where(houseworkTodo.id.eq(todoId))) - .and(user.email.eq(email))); + .and(user.email.eq(email))) + .fetchOne()); } @Override public Optional findGroupMemberByGroupMemberIdAndGroupInfoId(Long groupMemberId, Long groupId) { // select gm from groupMember gm where gm.id= :groupMemberId and gm.groupInfo.id= :groupId - return Optional.of(queryFactory.selectFrom(groupMember) + return Optional.ofNullable(queryFactory.selectFrom(groupMember) .innerJoin(groupMember.groupInfo, groupInfo).fetchJoin() .where(groupMember.id.eq(groupMemberId) .and(groupMember.groupInfo.id.eq(groupId))) @@ -85,7 +86,7 @@ public Optional findGroupMemberByGroupMemberIdAndGroupInfoId(Long g @Override public Optional findGroupMemberByUserEmailAndGroupInfoId(String userEmail, Long groupId) { - return Optional.of(queryFactory.selectFrom(groupMember) + return Optional.ofNullable(queryFactory.selectFrom(groupMember) .innerJoin(groupMember.user, user).fetchJoin() .innerJoin(groupMember.groupInfo, groupInfo).fetchJoin() .where(groupMember.user.email.eq(userEmail) diff --git a/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/housework/info/repository/HouseworkInfoRepositoryImpl.java b/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/housework/info/repository/HouseworkInfoRepositoryImpl.java index d057e1fd..e61f0b66 100644 --- a/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/housework/info/repository/HouseworkInfoRepositoryImpl.java +++ b/heachi-domain-mysql/src/main/java/com/heachi/mysql/define/housework/info/repository/HouseworkInfoRepositoryImpl.java @@ -24,7 +24,7 @@ public class HouseworkInfoRepositoryImpl implements HouseworkInfoRepositoryCusto @Override public Optional findHouseworkInfoByIdJoinFetchHouseworkMembers(Long houseworkInfoId) { - return Optional.of(queryFactory.selectFrom(houseworkInfo) + return Optional.ofNullable(queryFactory.selectFrom(houseworkInfo) .leftJoin(houseworkInfo.houseworkMembers, houseworkMember).fetchJoin() .innerJoin(houseworkInfo.houseworkCategory, houseworkCategory).fetchJoin() .where(houseworkInfo.id.eq(houseworkInfoId))