Skip to content

Commit

Permalink
Merge pull request #97 from depromeet/refact/houseWork-220625-temp
Browse files Browse the repository at this point in the history
Refact/house work 220625 temp
  • Loading branch information
SDB016 authored Jun 26, 2022
2 parents 376157d + 9fe7f23 commit e2afdd8
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 72 deletions.
15 changes: 5 additions & 10 deletions src/main/java/com/depromeet/fairer/api/HouseWorkController.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -75,11 +70,11 @@ public ResponseEntity<?> deleteHouseWork(
@Tag(name = "houseWorks")
@ApiOperation(value = "특정 멤버의 날짜별 집안일 조회", notes = "특정 멤버의 날짜별 집안일 조회")
@GetMapping("")
public ResponseEntity<PooClass> getTheMemberHouseWork(@RequestParam("reqDate") String reqDate,
@RequestParam("memberId") Long memberId,
@ApiIgnore @RequestMemberId Long reqMemberId) {
public ResponseEntity<HouseWorkAndAssigneeResponseDto> 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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,6 +11,7 @@ public interface HouseWorkCustomRepository {
Long getHouseWorkSuccessCount(Long memberId, LocalDate startDate, LocalDate endDate);

List<HouseWork> getHouseWorkAndAssignee(Long memberId, LocalDate localDate);
List<HouseWorkDetailVo> getHouseWorkAndAssignees(Long memberId, LocalDate localDate);


// List<HouseWork> getHouseWorkList(LocalDate scheduledDate, Long memberId);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -41,5 +47,29 @@ public List<HouseWork> getHouseWorkAndAssignee(Long memberId, LocalDate localDat

}

@Override
public List<HouseWorkDetailVo> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,14 @@ public List<Member> getMemberDtoListByHouseWorkId(Long houseWorkId){

@Override
public List<Member> 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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
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 com.depromeet.fairer.vo.houseWork.HouseWorkAndAssigneeResponseDto;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
Expand All @@ -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
Expand Down Expand Up @@ -191,40 +189,32 @@ 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);
// 이 멤버 아이디로 집안일 조회
// 집안일에 할당된 assignee 리스트 가져오기
final List<HouseWork> houseWorkAndAssignee = houseWorkRepository.getHouseWorkAndAssignee(memberId, localDate);

final List<HouseWorkAndAssigneeVo> 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<HouseWorkAndAssigneeVo.MemberVo> 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);
final List<HouseWorkDetailVo> houseWorkDetailVoList = houseWorkRepository.getHouseWorkAndAssignees(memberId, localDate);

List<HouseWorkAndAssigneeVo> houseWorkAndAssigneeVos = makeHouseWorkAndAssigneeVos(houseWorkDetailVoList);
final long successCount = houseWorkAndAssigneeVos.stream().filter(HouseWorkAndAssigneeVo::getSuccess).count();
return new HouseWorkAndAssigneeResponseDto(houseWorkAndAssigneeVos, successCount, houseWorkAndAssigneeVos.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;
private List<HouseWorkAndAssigneeVo> makeHouseWorkAndAssigneeVos(List<HouseWorkDetailVo> houseWorkDetailVoList) {
Map<Long, List<HouseWorkAndAssigneeVo.MemberVo>> 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())));

return 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());
}
}
Original file line number Diff line number Diff line change
@@ -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<HouseWorkAndAssigneeVo> houseWorkAndAssigneeVos;

@ApiModelProperty(value = "완료한 집안일 갯수")
private int successCount;

@ApiModelProperty(value = "남은 집안일 갯수")
private int leftCount;

public HouseWorkAndAssigneeResponseDto(List<HouseWorkAndAssigneeVo> houseWorkAndAssigneeVos, long successCount, long leftCount) {
this.houseWorkAndAssigneeVos = houseWorkAndAssigneeVos;
this.successCount = (int) successCount;
this.leftCount = (int) leftCount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,6 +18,7 @@
import java.util.List;

@Getter @Setter
@Builder
public class HouseWorkAndAssigneeVo {

private Long houseWorkId;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
15 changes: 0 additions & 15 deletions src/main/java/com/depromeet/fairer/vo/houseWork/PooClass.java

This file was deleted.

0 comments on commit e2afdd8

Please sign in to comment.