Skip to content

Commit

Permalink
fix: 월별 집안일 완료 랭킹 api - houseworkComplete.member 기준으로 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
daeunkwak committed Aug 2, 2023
1 parent 228a335 commit 087dc18
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ public interface HouseWorkCompleteCustomRepository {
List<HouseWorkCompleteStatisticsVo> findMonthlyHouseWorkRanking(Long teamId, YearMonth month);

List<HouseworkComplete> findMonthlyHouseWorkStatisticByTeamIdAndHouseWorkNameV2(Long memberId, YearMonth from, String houseWorkName);

Long findMonthlyHouseWorkByMember(Long memberId, YearMonth month);
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ public List<HouseworkComplete> findMonthlyHouseWorkStatisticByTeamIdAndHouseWork
.fetch();
}

@Override
public Long findMonthlyHouseWorkByMember(Long memberId, YearMonth month) {

LocalDateTime startTimeOfMonth = month.atDay(1) .atStartOfDay();
LocalDateTime endTimeOfMonth = month.atEndOfMonth().atTime(LocalTime.MAX);

return (long) jpaQueryFactory.selectFrom(houseworkComplete)
.where(houseworkComplete.member.memberId.eq(memberId),
houseworkComplete.successDateTime.between(startTimeOfMonth, endTimeOfMonth))
.fetch()
.size();
}

private BooleanExpression houseworkNameEq(String houseworkName) {
return houseworkName != null? houseWork.houseWorkName.eq(houseworkName) : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,23 @@ public MonthlyHouseWorkStatisticResponseDto getMonthlyHouseWorkRanking(Long memb
() -> new NoSuchMemberException("memberId에 해당하는 회원을 찾지 못했습니다.")
);

List<HouseWorkCompleteStatisticsVo> teamHouseWorkStatistics = houseWorkCompleteRepository.findMonthlyHouseWorkRanking(
currentMember.getTeam().getTeamId(),
YearMonth.from(month));

List<MemberHouseWorkStatisticDto> houseWorkStatics = teamHouseWorkStatistics.stream()
.map(statistic -> MemberHouseWorkStatisticDto.of(statistic.getMember(), statistic.getCompleteCount()))
.sorted(Comparator.comparing(MemberHouseWorkStatisticDto::getHouseWorkCount).reversed())
.collect(Collectors.toList());
List<MemberHouseWorkStatisticDto> memberHouseWorkStatisticDtos = new ArrayList<>();
for(Member member : currentMember.getTeam().getMembers()){
memberHouseWorkStatisticDtos.add(
MemberHouseWorkStatisticDto.of(member, houseWorkCompleteRepository.findMonthlyHouseWorkByMember(member.getMemberId(), YearMonth.from(month))));
}

return MonthlyHouseWorkStatisticResponseDto.of(houseWorkStatics);
// List<HouseWorkCompleteStatisticsVo> teamHouseWorkStatistics = houseWorkCompleteRepository.findMonthlyHouseWorkRanking(
// currentMember.getTeam().getTeamId(),
// YearMonth.from(month));
//
// List<MemberHouseWorkStatisticDto> houseWorkStatics = teamHouseWorkStatistics.stream()
// .map(statistic -> MemberHouseWorkStatisticDto.of(statistic.getMember(), statistic.getCompleteCount()))
// .sorted(Comparator.comparing(MemberHouseWorkStatisticDto::getHouseWorkCount).reversed())
// .collect(Collectors.toList());

memberHouseWorkStatisticDtos.sort(Comparator.comparing(MemberHouseWorkStatisticDto::getHouseWorkCount).reversed());
return MonthlyHouseWorkStatisticResponseDto.of(memberHouseWorkStatisticDtos);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import com.depromeet.fairer.domain.member.Member;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class HouseWorkCompleteStatisticsVo {

private Member member;
Expand Down

0 comments on commit 087dc18

Please sign in to comment.