From 739b88fc7df565245ceb56d98dc8aaf16cc34359 Mon Sep 17 00:00:00 2001 From: seungyoon-kim Date: Sun, 26 Jun 2022 03:42:25 +0900 Subject: [PATCH 1/2] temp --- .../housework/HouseWorkCustomRepository.java | 3 ++ .../HouseWorkCustomRepositoryImpl.java | 30 +++++++++++++ .../service/housework/HouseWorkService.java | 45 ++++++++++++++----- .../vo/houseWork/HouseWorkAndAssigneeVo.java | 4 +- .../vo/houseWork/HouseWorkDetailVo.java | 30 +++++++++++++ 5 files changed, 99 insertions(+), 13 deletions(-) create mode 100644 src/main/java/com/depromeet/fairer/vo/houseWork/HouseWorkDetailVo.java diff --git a/src/main/java/com/depromeet/fairer/repository/housework/HouseWorkCustomRepository.java b/src/main/java/com/depromeet/fairer/repository/housework/HouseWorkCustomRepository.java index 2e94f83e..f45e280f 100644 --- a/src/main/java/com/depromeet/fairer/repository/housework/HouseWorkCustomRepository.java +++ b/src/main/java/com/depromeet/fairer/repository/housework/HouseWorkCustomRepository.java @@ -1,6 +1,8 @@ package com.depromeet.fairer.repository.housework; import com.depromeet.fairer.domain.housework.HouseWork; +import com.depromeet.fairer.vo.houseWork.HouseWorkAndAssigneeVo; +import com.depromeet.fairer.vo.houseWork.HouseWorkDetailVo; import java.time.LocalDate; import java.util.List; @@ -9,6 +11,7 @@ public interface HouseWorkCustomRepository { Long getHouseWorkSuccessCount(Long memberId, LocalDate startDate, LocalDate endDate); List getHouseWorkAndAssignee(Long memberId, LocalDate localDate); + List getHouseWorkAndAssignees(Long memberId, LocalDate localDate); // List getHouseWorkList(LocalDate scheduledDate, Long memberId); diff --git a/src/main/java/com/depromeet/fairer/repository/housework/HouseWorkCustomRepositoryImpl.java b/src/main/java/com/depromeet/fairer/repository/housework/HouseWorkCustomRepositoryImpl.java index 3bec48d3..c7e15681 100644 --- a/src/main/java/com/depromeet/fairer/repository/housework/HouseWorkCustomRepositoryImpl.java +++ b/src/main/java/com/depromeet/fairer/repository/housework/HouseWorkCustomRepositoryImpl.java @@ -1,6 +1,12 @@ package com.depromeet.fairer.repository.housework; +import com.depromeet.fairer.domain.assignment.QAssignment; import com.depromeet.fairer.domain.housework.HouseWork; +import com.depromeet.fairer.domain.housework.QHouseWork; +import com.depromeet.fairer.domain.member.QMember; +import com.depromeet.fairer.vo.houseWork.HouseWorkAndAssigneeVo; +import com.depromeet.fairer.vo.houseWork.HouseWorkDetailVo; +import com.querydsl.core.types.Projections; import com.querydsl.jpa.impl.JPAQueryFactory; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; @@ -41,5 +47,29 @@ public List getHouseWorkAndAssignee(Long memberId, LocalDate localDat } + @Override + public List getHouseWorkAndAssignees(Long memberId, LocalDate localDate) { + QAssignment assignment1 = QAssignment.assignment; + QMember member = QMember.member; + QAssignment assignment2 = QAssignment.assignment; + QHouseWork houseWork = QHouseWork.houseWork; + return jpaQueryFactory.select(Projections.bean(HouseWorkDetailVo.class, + houseWork.houseWorkId, + houseWork.space, + houseWork.houseWorkName, + houseWork.scheduledTime, + houseWork.successDateTime, + houseWork.success, + member.memberId, + member.memberName, + member.profilePath)) + .from(assignment1) + .innerJoin(houseWork).on(assignment1.houseWork.houseWorkId.eq(houseWork.houseWorkId)) + .innerJoin(assignment2).on(assignment2.houseWork.houseWorkId.eq(houseWork.houseWorkId)) + .innerJoin(member).on(assignment2.member.memberId.eq(member.memberId)) + .where(houseWork.scheduledDate.eq(localDate) + .and(assignment1.member.memberId.eq(memberId))) + .fetch(); + } } \ No newline at end of file diff --git a/src/main/java/com/depromeet/fairer/service/housework/HouseWorkService.java b/src/main/java/com/depromeet/fairer/service/housework/HouseWorkService.java index e508bbaf..c56bace7 100644 --- a/src/main/java/com/depromeet/fairer/service/housework/HouseWorkService.java +++ b/src/main/java/com/depromeet/fairer/service/housework/HouseWorkService.java @@ -15,6 +15,7 @@ import com.depromeet.fairer.service.member.MemberService; import com.depromeet.fairer.service.team.TeamService; import com.depromeet.fairer.vo.houseWork.HouseWorkAndAssigneeVo; +import com.depromeet.fairer.vo.houseWork.HouseWorkDetailVo; import com.depromeet.fairer.vo.houseWork.HouseWorkUpdateVo; import com.depromeet.fairer.vo.houseWork.PooClass; import lombok.RequiredArgsConstructor; @@ -28,10 +29,7 @@ import java.time.DayOfWeek; import java.time.LocalDateTime; import java.time.temporal.TemporalAdjusters; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; @Slf4j @@ -193,8 +191,30 @@ public HouseWork getHouseWorkById(Long houseWorkId) { public PooClass getTheMemberHouseWorks(Long reqMemberId, Long memberId, LocalDate localDate) { teamService.validateSameTeam(reqMemberId, memberId); + final List houseWorkDetailVoList = houseWorkRepository.getHouseWorkAndAssignees(memberId, localDate); + + Map> houseWorkMap = houseWorkDetailVoList.stream() + .collect(Collectors.groupingBy( + HouseWorkDetailVo::getHouseWorkId, + Collectors.mapping(houseWorkDetailVo -> HouseWorkAndAssigneeVo.MemberVo.builder().memberId(houseWorkDetailVo.getMemberId()).memberName(houseWorkDetailVo.getMemberName()).profilePath(houseWorkDetailVo.getProfilePath()).build(), Collectors.toList()))); + + List response = houseWorkDetailVoList.stream().map(houseWorkDetailVo -> + HouseWorkAndAssigneeVo.builder() + .houseWorkId(houseWorkDetailVo.getHouseWorkId()) + .space(houseWorkDetailVo.getSpace()) + .houseWorkName(houseWorkDetailVo.getHouseWorkName()) + .scheduledTime(houseWorkDetailVo.getScheduledTime()) + .successDateTime(houseWorkDetailVo.getSuccessDateTime()) + .success(houseWorkDetailVo.getSuccess()) + .assignees(houseWorkMap.get(houseWorkDetailVo.getHouseWorkId())) + .build()) + .distinct().collect(Collectors.toList()); + final long successCount = response.stream().filter(HouseWorkAndAssigneeVo::getSuccess).count(); + return new PooClass(response, successCount, response.size() - successCount); + // 이 멤버 아이디로 집안일 조회 // 집안일에 할당된 assignee 리스트 가져오기 + /* final List houseWorkAndAssignee = houseWorkRepository.getHouseWorkAndAssignee(memberId, localDate); final List response = houseWorkAndAssignee.stream().map(h -> { @@ -217,14 +237,15 @@ public PooClass getTheMemberHouseWorks(Long reqMemberId, Long memberId, LocalDat final long successCount = houseWorkAndAssignee.stream().filter(HouseWork::getSuccess).count(); return new PooClass(response, successCount, houseWorkAndAssignee.size() - successCount); + */ } - @NotNull - private HouseWorkAndAssigneeVo.MemberVo makeMemberVo(Member member) { - final HouseWorkAndAssigneeVo.MemberVo memberVo = new HouseWorkAndAssigneeVo.MemberVo(); - memberVo.setMemberId(member.getMemberId()); - memberVo.setMemberName(member.getMemberName()); - memberVo.setProfilePath(member.getProfilePath()); - return memberVo; - } +// @NotNull +// private HouseWorkAndAssigneeVo.MemberVo makeMemberVo(Member member) { +// final HouseWorkAndAssigneeVo.MemberVo memberVo = new HouseWorkAndAssigneeVo.MemberVo(); +// memberVo.setMemberId(member.getMemberId()); +// memberVo.setMemberName(member.getMemberName()); +// memberVo.setProfilePath(member.getProfilePath()); +// return memberVo; +// } } \ No newline at end of file diff --git a/src/main/java/com/depromeet/fairer/vo/houseWork/HouseWorkAndAssigneeVo.java b/src/main/java/com/depromeet/fairer/vo/houseWork/HouseWorkAndAssigneeVo.java index 8392e7be..6cb1fb6c 100644 --- a/src/main/java/com/depromeet/fairer/vo/houseWork/HouseWorkAndAssigneeVo.java +++ b/src/main/java/com/depromeet/fairer/vo/houseWork/HouseWorkAndAssigneeVo.java @@ -7,6 +7,7 @@ import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer; import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer; import io.swagger.annotations.ApiModelProperty; +import lombok.Builder; import lombok.Getter; import lombok.Setter; import org.springframework.stereotype.Service; @@ -17,6 +18,7 @@ import java.util.List; @Getter @Setter +@Builder public class HouseWorkAndAssigneeVo { private Long houseWorkId; @@ -33,7 +35,7 @@ public class HouseWorkAndAssigneeVo { private Boolean success; - @Getter @Setter + @Getter @Setter @Builder public static class MemberVo{ private Long memberId; private String memberName; diff --git a/src/main/java/com/depromeet/fairer/vo/houseWork/HouseWorkDetailVo.java b/src/main/java/com/depromeet/fairer/vo/houseWork/HouseWorkDetailVo.java new file mode 100644 index 00000000..a4840e50 --- /dev/null +++ b/src/main/java/com/depromeet/fairer/vo/houseWork/HouseWorkDetailVo.java @@ -0,0 +1,30 @@ +package com.depromeet.fairer.vo.houseWork; + +import com.depromeet.fairer.domain.preset.constant.Space; +import lombok.Getter; +import lombok.Setter; + +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.List; + +@Getter +@Setter +public class HouseWorkDetailVo { + + private Long houseWorkId; + + private Space space; + + private String houseWorkName; + + private LocalTime scheduledTime; + + private LocalDateTime successDateTime; + + private Boolean success; + + private Long memberId; + private String memberName; + private String profilePath; +} From 9fe7f23bdd96398d57c3ca21ced5a0a6004be218 Mon Sep 17 00:00:00 2001 From: dongbin Shin <59786670+SDB016@users.noreply.github.com> Date: Mon, 27 Jun 2022 02:03:16 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor=20#96:=20=ED=8A=B9=EC=A0=95=20?= =?UTF-8?q?=EB=A9=A4=EB=B2=84,=20=EB=82=A0=EC=A7=9C=EB=A1=9C=20=EC=A7=91?= =?UTF-8?q?=EC=95=88=EC=9D=BC=20=EC=A1=B0=ED=9A=8C=20=EC=8B=9C=20=EC=BF=BC?= =?UTF-8?q?=EB=A6=AC=20=EB=A7=8E=EC=9D=80=20=EB=AC=B8=EC=A0=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fairer/api/HouseWorkController.java | 15 ++---- .../member/MemberCustomRepositoryImpl.java | 18 +++---- .../service/housework/HouseWorkService.java | 51 ++++--------------- .../HouseWorkAndAssigneeResponseDto.java | 30 +++++++++++ .../fairer/vo/houseWork/PooClass.java | 15 ------ 5 files changed, 53 insertions(+), 76 deletions(-) create mode 100644 src/main/java/com/depromeet/fairer/vo/houseWork/HouseWorkAndAssigneeResponseDto.java delete mode 100644 src/main/java/com/depromeet/fairer/vo/houseWork/PooClass.java diff --git a/src/main/java/com/depromeet/fairer/api/HouseWorkController.java b/src/main/java/com/depromeet/fairer/api/HouseWorkController.java index a94ec9b7..3a47f6a0 100644 --- a/src/main/java/com/depromeet/fairer/api/HouseWorkController.java +++ b/src/main/java/com/depromeet/fairer/api/HouseWorkController.java @@ -1,8 +1,5 @@ package com.depromeet.fairer.api; -import com.depromeet.fairer.domain.housework.HouseWork; -import com.depromeet.fairer.domain.member.Member; -import com.depromeet.fairer.dto.member.MemberDto; import com.depromeet.fairer.global.resolver.RequestMemberId; import com.depromeet.fairer.global.util.DateTimeUtils; import com.depromeet.fairer.service.housework.HouseWorkService; @@ -13,7 +10,7 @@ import com.depromeet.fairer.service.member.MemberService; import com.depromeet.fairer.vo.houseWork.HouseWorkUpdateVo; -import com.depromeet.fairer.vo.houseWork.PooClass; +import com.depromeet.fairer.vo.houseWork.HouseWorkAndAssigneeResponseDto; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.v3.oas.annotations.tags.Tag; @@ -27,9 +24,7 @@ import javax.validation.Valid; import java.time.LocalDate; -import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; @Slf4j @RestController @@ -75,11 +70,11 @@ public ResponseEntity deleteHouseWork( @Tag(name = "houseWorks") @ApiOperation(value = "특정 멤버의 날짜별 집안일 조회", notes = "특정 멤버의 날짜별 집안일 조회") @GetMapping("") - public ResponseEntity getTheMemberHouseWork(@RequestParam("reqDate") String reqDate, - @RequestParam("memberId") Long memberId, - @ApiIgnore @RequestMemberId Long reqMemberId) { + public ResponseEntity getTheMemberHouseWork(@RequestParam("reqDate") String reqDate, + @RequestParam("memberId") Long memberId, + @ApiIgnore @RequestMemberId Long reqMemberId) { final LocalDate localDate = DateTimeUtils.stringToLocalDate(reqDate); - final PooClass theMemberHouseWorks = houseWorkService.getTheMemberHouseWorks(reqMemberId, memberId, localDate); + final HouseWorkAndAssigneeResponseDto theMemberHouseWorks = houseWorkService.getTheMemberHouseWorks(reqMemberId, memberId, localDate); return ResponseEntity.ok(theMemberHouseWorks); } diff --git a/src/main/java/com/depromeet/fairer/repository/member/MemberCustomRepositoryImpl.java b/src/main/java/com/depromeet/fairer/repository/member/MemberCustomRepositoryImpl.java index 8e14b114..917bd02c 100644 --- a/src/main/java/com/depromeet/fairer/repository/member/MemberCustomRepositoryImpl.java +++ b/src/main/java/com/depromeet/fairer/repository/member/MemberCustomRepositoryImpl.java @@ -31,16 +31,14 @@ public List getMemberDtoListByHouseWorkId(Long houseWorkId){ @Override public List getMyTeamMembers(Long memberId) { - final QMember teamMember = new QMember("teamMember"); - final QTeam aTeam = new QTeam("ATeam"); -// return jpaQueryFactory.select(teamMember) -// .leftJoin(teamMember.team, ateam) -// .where(JPAExpressions -// .selectFrom(team) -// .leftJoin(member.team, team) -// .where(member.memberId.eq(memberId)) -// ), aTeam).fetch(); - return null; + final QMember member1 = QMember.member; + final QMember member2 = QMember.member; + final QTeam team = QTeam.team; + return jpaQueryFactory.select(member1) + .from(team) + .innerJoin(member2).on(member2.team.eq(team)) + .where(member2.memberId.eq(memberId)) + .fetch(); } } diff --git a/src/main/java/com/depromeet/fairer/service/housework/HouseWorkService.java b/src/main/java/com/depromeet/fairer/service/housework/HouseWorkService.java index c56bace7..30073a05 100644 --- a/src/main/java/com/depromeet/fairer/service/housework/HouseWorkService.java +++ b/src/main/java/com/depromeet/fairer/service/housework/HouseWorkService.java @@ -17,7 +17,7 @@ import com.depromeet.fairer.vo.houseWork.HouseWorkAndAssigneeVo; import com.depromeet.fairer.vo.houseWork.HouseWorkDetailVo; import com.depromeet.fairer.vo.houseWork.HouseWorkUpdateVo; -import com.depromeet.fairer.vo.houseWork.PooClass; +import com.depromeet.fairer.vo.houseWork.HouseWorkAndAssigneeResponseDto; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.jetbrains.annotations.NotNull; @@ -189,16 +189,23 @@ public HouseWork getHouseWorkById(Long houseWorkId) { .orElseThrow(() -> new IllegalArgumentException("존재하지 않는 집안일 입니다.")); } - public PooClass getTheMemberHouseWorks(Long reqMemberId, Long memberId, LocalDate localDate) { + public HouseWorkAndAssigneeResponseDto getTheMemberHouseWorks(Long reqMemberId, Long memberId, LocalDate localDate) { teamService.validateSameTeam(reqMemberId, memberId); final List houseWorkDetailVoList = houseWorkRepository.getHouseWorkAndAssignees(memberId, localDate); + List houseWorkAndAssigneeVos = makeHouseWorkAndAssigneeVos(houseWorkDetailVoList); + final long successCount = houseWorkAndAssigneeVos.stream().filter(HouseWorkAndAssigneeVo::getSuccess).count(); + return new HouseWorkAndAssigneeResponseDto(houseWorkAndAssigneeVos, successCount, houseWorkAndAssigneeVos.size() - successCount); + } + + @NotNull + private List makeHouseWorkAndAssigneeVos(List houseWorkDetailVoList) { Map> houseWorkMap = houseWorkDetailVoList.stream() .collect(Collectors.groupingBy( HouseWorkDetailVo::getHouseWorkId, Collectors.mapping(houseWorkDetailVo -> HouseWorkAndAssigneeVo.MemberVo.builder().memberId(houseWorkDetailVo.getMemberId()).memberName(houseWorkDetailVo.getMemberName()).profilePath(houseWorkDetailVo.getProfilePath()).build(), Collectors.toList()))); - List response = houseWorkDetailVoList.stream().map(houseWorkDetailVo -> + return houseWorkDetailVoList.stream().map(houseWorkDetailVo -> HouseWorkAndAssigneeVo.builder() .houseWorkId(houseWorkDetailVo.getHouseWorkId()) .space(houseWorkDetailVo.getSpace()) @@ -209,43 +216,5 @@ public PooClass getTheMemberHouseWorks(Long reqMemberId, Long memberId, LocalDat .assignees(houseWorkMap.get(houseWorkDetailVo.getHouseWorkId())) .build()) .distinct().collect(Collectors.toList()); - final long successCount = response.stream().filter(HouseWorkAndAssigneeVo::getSuccess).count(); - return new PooClass(response, successCount, response.size() - successCount); - - // 이 멤버 아이디로 집안일 조회 - // 집안일에 할당된 assignee 리스트 가져오기 - /* - final List houseWorkAndAssignee = houseWorkRepository.getHouseWorkAndAssignee(memberId, localDate); - - final List response = houseWorkAndAssignee.stream().map(h -> { - final HouseWorkAndAssigneeVo houseWorkAndAssigneeVo = new HouseWorkAndAssigneeVo(); - houseWorkAndAssigneeVo.setHouseWorkId(h.getHouseWorkId()); - houseWorkAndAssigneeVo.setSpace(h.getSpace()); - houseWorkAndAssigneeVo.setScheduledTime(h.getScheduledTime()); - houseWorkAndAssigneeVo.setSuccessDateTime(h.getSuccessDateTime()); - houseWorkAndAssigneeVo.setSuccess(h.getSuccess()); - - final List memberVos = h.getAssignments().stream() - .map(Assignment::getMember) - .collect(Collectors.toList()) - .stream() - .map(this::makeMemberVo).collect(Collectors.toList()); - - houseWorkAndAssigneeVo.setAssignees(memberVos); - return houseWorkAndAssigneeVo; - }).collect(Collectors.toList()); - final long successCount = houseWorkAndAssignee.stream().filter(HouseWork::getSuccess).count(); - - return new PooClass(response, successCount, houseWorkAndAssignee.size() - successCount); - */ } - -// @NotNull -// private HouseWorkAndAssigneeVo.MemberVo makeMemberVo(Member member) { -// final HouseWorkAndAssigneeVo.MemberVo memberVo = new HouseWorkAndAssigneeVo.MemberVo(); -// memberVo.setMemberId(member.getMemberId()); -// memberVo.setMemberName(member.getMemberName()); -// memberVo.setProfilePath(member.getProfilePath()); -// return memberVo; -// } } \ No newline at end of file diff --git a/src/main/java/com/depromeet/fairer/vo/houseWork/HouseWorkAndAssigneeResponseDto.java b/src/main/java/com/depromeet/fairer/vo/houseWork/HouseWorkAndAssigneeResponseDto.java new file mode 100644 index 00000000..be1b175a --- /dev/null +++ b/src/main/java/com/depromeet/fairer/vo/houseWork/HouseWorkAndAssigneeResponseDto.java @@ -0,0 +1,30 @@ +package com.depromeet.fairer.vo.houseWork; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Getter +@NoArgsConstructor @AllArgsConstructor +@ApiModel(value = "특정 멤버, 날짜에 할당된 집안일 모두 조회 반환 객체", description = "특정 멤버, 날짜에 할당된 집안일 모두 조회 반환 객체") +public class HouseWorkAndAssigneeResponseDto { + + @ApiModelProperty(value = "집안일, 담당자 객체 리스트") + private List houseWorkAndAssigneeVos; + + @ApiModelProperty(value = "완료한 집안일 갯수") + private int successCount; + + @ApiModelProperty(value = "남은 집안일 갯수") + private int leftCount; + + public HouseWorkAndAssigneeResponseDto(List houseWorkAndAssigneeVos, long successCount, long leftCount) { + this.houseWorkAndAssigneeVos = houseWorkAndAssigneeVos; + this.successCount = (int) successCount; + this.leftCount = (int) leftCount; + } +} diff --git a/src/main/java/com/depromeet/fairer/vo/houseWork/PooClass.java b/src/main/java/com/depromeet/fairer/vo/houseWork/PooClass.java deleted file mode 100644 index 53ee6cb6..00000000 --- a/src/main/java/com/depromeet/fairer/vo/houseWork/PooClass.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.depromeet.fairer.vo.houseWork; - -import java.util.List; - -public class PooClass { - private List houseWorkAndAssigneeVos; - private int successCount; - private int leftCount; - - public PooClass(List houseWorkAndAssigneeVos, long successCount, long leftCount) { - this.houseWorkAndAssigneeVos = houseWorkAndAssigneeVos; - this.successCount = (int) successCount; - this.leftCount = (int) leftCount; - } -}