Skip to content

Commit

Permalink
Merge pull request #155 from depromeet/develop
Browse files Browse the repository at this point in the history
deploy-22.11.15.1
  • Loading branch information
dskym authored Nov 15, 2022
2 parents 1bb4c0b + 296d495 commit eae8fe3
Show file tree
Hide file tree
Showing 36 changed files with 1,131 additions and 149 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.depromeet.fairer.api;

import com.depromeet.fairer.dto.houseworkComplete.response.HouseWorkCompleteResponseDto;
import com.depromeet.fairer.global.resolver.RequestMemberId;
import com.depromeet.fairer.global.util.DateTimeUtils;
import com.depromeet.fairer.service.houseworkComplete.HouseWorkCompleteService;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@Slf4j
@RestController
@RequiredArgsConstructor
@Tag(name = "houseWorkComplete", description = "집안일 완료 API")
@RequestMapping("/api/houseworks/complete")
public class HouseWorkCompleteController {

private final HouseWorkCompleteService houseWorkCompleteService;

@Tag(name = "houseWorkComplete")
@ApiOperation(value = "집안일 완료 생성 - 반복 기능 구현 후")
@PostMapping(value = "/{houseWorkId}")
public ResponseEntity<HouseWorkCompleteResponseDto> createHouseWorkComp(@PathVariable("houseWorkId") Long houseWorkId,
@RequestParam("scheduledDate") String scheduledDate) {
final LocalDate date = DateTimeUtils.stringToLocalDate(scheduledDate);

final Long houseWorkCompleteId = houseWorkCompleteService.create(houseWorkId, date);
return new ResponseEntity<>(HouseWorkCompleteResponseDto.create(houseWorkCompleteId), HttpStatus.CREATED);
}

@Tag(name = "houseWorkComplete")
@ApiOperation(value = "집안일 완료 삭제 - 반복 기능 구현 후")
@DeleteMapping("/{houseWorkCompleteId}")
public ResponseEntity<?> deleteHouseWorkComp(@PathVariable("houseWorkCompleteId") Long houseWorkCompleteId) {
houseWorkCompleteService.delete(houseWorkCompleteId);
return new ResponseEntity<>(HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.depromeet.fairer.service.member.MemberService;

import com.depromeet.fairer.service.team.TeamService;
import com.depromeet.fairer.dto.housework.request.HouseWorkDeleteRequestDto;
import com.depromeet.fairer.vo.houseWork.HouseWorkUpdateVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
Expand All @@ -27,11 +28,10 @@

import javax.validation.Valid;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Slf4j
@RestController
Expand All @@ -45,16 +45,128 @@ public class HouseWorkController {
private final ModelMapper modelMapper;

@Tag(name = "houseWorks")
@ApiOperation(value = "집안일 생성 API ")
@ApiOperation(value = "집안일 생성 API")
@PostMapping("")
public ResponseEntity<HouseWorksCreateResponseDto> createHouseWorks(@ApiIgnore @RequestMemberId Long memberId,
@RequestBody @Valid HouseWorksCreateRequestDto dto) {
List<HouseWorkResponseDto> houseWorkList = houseWorkService.createHouseWorks(memberId, dto.getHouseWorks());
return new ResponseEntity<>(new HouseWorksCreateResponseDto(houseWorkList), HttpStatus.CREATED);
public ResponseEntity<List<HouseWorkResponseDto>> createHouseWorks(@ApiIgnore @RequestMemberId Long memberId,
@RequestBody @Valid List<HouseWorksCreateRequestDto> request) {
List<HouseWorkResponseDto> responseDtos = new ArrayList<>();
for (HouseWorksCreateRequestDto requestDto : request) {
responseDtos.add(houseWorkService.createHouseWork(memberId, requestDto));
}
return new ResponseEntity<>(responseDtos, HttpStatus.CREATED);
}

@Tag(name = "houseWorks")
@ApiOperation(value = "집안일 수정 API - 반복 기능 구현 후")
@PutMapping("/v2")
public ResponseEntity<?> editHouseWork(@ApiIgnore @RequestMemberId Long memberId,
@RequestBody @Valid HouseWorkUpdateRequestDto dto) {
return ResponseEntity.ok(houseWorkService.updateHouseWork(memberId, dto));
}

@Tag(name = "houseWorks")
@ApiOperation(value = "집안일 삭제 API - 반복 기능 구현 후")
@DeleteMapping("/v2")
public ResponseEntity<?> deleteHouseWork(
@ApiIgnore @RequestMemberId Long memberId,
@RequestBody @Valid HouseWorkDeleteRequestDto dto) {
houseWorkService.deleteHouseWork(memberId, dto.getHouseWorkId(), dto.getType(), dto.getDeleteStandardDate());
return new ResponseEntity<>(HttpStatus.OK);
}

// 쿼리 1개로 처리
@Tag(name = "houseWorks")
@ApiOperation(value = "팀원의 특정 기간 집안일 목록 조회 - 반복 기능 구현 후", notes = "본인이 속한 팀의 팀원의 특정 기간 집안일 목록 조회")
@GetMapping("/list/member/{teamMemberId}/query")
public ResponseEntity<Map<String, HouseWorkDateResponseDto>> getHouseWorkListByTeamMemberAndDateQuery(@RequestParam("fromDate") String fromDate,
@RequestParam("toDate") String toDate,@PathVariable("teamMemberId") Long teamMemberId,
@ApiIgnore @RequestMemberId Long memberId) {
final LocalDate from = DateTimeUtils.stringToLocalDate(fromDate);
final LocalDate to = DateTimeUtils.stringToLocalDate(toDate);

teamService.checkJoinSameTeam(teamMemberId, memberId);
Member teamMember = memberService.find(teamMemberId);

Map<LocalDate, List<HouseWorkResponseDto>> results = new HashMap<>();
Stream.iterate(from, date -> date.plusDays(1))
.limit(ChronoUnit.DAYS.between(from, to) + 1).forEach(date -> {

List<HouseWorkResponseDto> houseWorkResponseDtoList = houseWorkService.getHouseWorkByDateRepeatQuery(teamMember, date).stream().map(arr -> {
List<MemberDto> memberDtoList = memberService.getMemberListByHouseWorkId(arr.getHouseWork().getHouseWorkId())
.stream().map(MemberDto::from).collect(Collectors.toList());
return HouseWorkResponseDto.from(arr.getHouseWork(), memberDtoList, date, arr.getHouseWorkCompleteId());

}).collect(Collectors.toList());

results.put(date, houseWorkResponseDtoList);
});

return ResponseEntity.ok(makeHouseWorkListResponse(teamMemberId, results));
}

// 팀 전체 쿼리 1개
@Tag(name = "houseWorks")
@ApiOperation(value = "특정 날짜별 집안일 조회 - 반복 기능 구현 후", notes = "특정 날짜별 집안일 조회")
@GetMapping("/list/query")
public ResponseEntity<Map<String, HouseWorkDateResponseDto>> getHouseWorkListByDateQuery(@RequestParam("fromDate") String fromDate,
@RequestParam("toDate") String toDate,
@ApiIgnore @RequestMemberId Long memberId) {
final LocalDate from = DateTimeUtils.stringToLocalDate(fromDate);
final LocalDate to = DateTimeUtils.stringToLocalDate(toDate);

Member member = memberService.find(memberId);
Map<LocalDate, List<HouseWorkResponseDto>> results = new HashMap<>();

Stream.iterate(from, date -> date.plusDays(1))
.limit(ChronoUnit.DAYS.between(from, to) + 1).forEach(date -> {
List<HouseWorkResponseDto> houseWorkResponseDtoList = houseWorkService.getHouseWorkByDateRepeatTeamQuery(member.getTeam(), date).stream().map(arr -> {
List<MemberDto> memberDtoList = memberService.getMemberListByHouseWorkId(arr.getHouseWork().getHouseWorkId())
.stream().map(MemberDto::from).collect(Collectors.toList());
return HouseWorkResponseDto.from(arr.getHouseWork(), memberDtoList, date, arr.getHouseWorkCompleteId());
}).collect(Collectors.toList());

results.put(date, houseWorkResponseDtoList);
});

return ResponseEntity.ok(makeHouseWorkListResponse(memberId, results));
}

private Map<LocalDate, List<HouseWorkResponseDto>> getHouseWorkListGroupByScheduledDate(List<HouseWork> houseWorkList) {
return houseWorkList.stream().map(houseWork -> {
List<MemberDto> memberDtoList = memberService.getMemberListByHouseWorkId(houseWork.getHouseWorkId())
.stream().map(MemberDto::from).collect(Collectors.toList());
return HouseWorkResponseDto.from(houseWork, memberDtoList);
}).collect(Collectors.groupingBy(HouseWorkResponseDto::getScheduledDate, HashMap::new, Collectors.toCollection(ArrayList::new)));
}

private Map<String, HouseWorkDateResponseDto> makeHouseWorkListResponse(Long memberId, Map<LocalDate, List<HouseWorkResponseDto>> houseWorkListGroupByScheduledDate) {
Map<String, HouseWorkDateResponseDto> response = new HashMap<>();
houseWorkListGroupByScheduledDate.forEach((scheduledDate, houseWorkResponseDtoList) -> {
long countDone = houseWorkResponseDtoList.stream().filter(HouseWorkResponseDto::getSuccess).count();
long countLeft = houseWorkResponseDtoList.stream().filter(houseWorkResponseDto -> !houseWorkResponseDto.getSuccess()).count();
response.put(DateTimeUtils.localDateToString(scheduledDate), HouseWorkDateResponseDto.from(memberId, scheduledDate, countDone, countLeft, houseWorkResponseDtoList));
});
return response;
}

@Tag(name = "houseWorks")
@ApiOperation(value = "개별 집안일 조회", notes = "")
@GetMapping(value = "{houseWorkId}/detail")
public ResponseEntity<HouseWorkResponseDto> getHouseWorkDetail(@PathVariable("houseWorkId") Long houseWorkId) {
return ResponseEntity.ok(houseWorkService.getHouseWorkDetail(houseWorkId));
}

@Tag(name = "houseWorks")
@GetMapping("/success/count")
public ResponseEntity<HouseWorkSuccessCountResponseDto> getSuccessCount(@RequestParam String scheduledDate,
@ApiIgnore @RequestMemberId Long memberId) {
HouseWorkSuccessCountResponseDto houseWorkSuccessCountResponseDto = houseWorkService.getSuccessCount(scheduledDate, memberId);
return ResponseEntity.ok(houseWorkSuccessCountResponseDto);
}

@Deprecated
@Tag(name = "houseWorks")
@ApiOperation(value = "집안일 수정 API")
@ApiOperation(value = "집안일 수정 API - 반복 기능 구현 전")
@PutMapping("/{houseWorkId}")
public ResponseEntity<HouseWorkResponseDto> editHouseWork(@ApiIgnore @RequestMemberId Long memberId,
@RequestBody @Valid HouseWorkUpdateRequestDto dto,
Expand All @@ -66,8 +178,9 @@ public ResponseEntity<HouseWorkResponseDto> editHouseWork(@ApiIgnore @RequestMem
return new ResponseEntity<>(houseWorkService.updateHouseWork(houseWorkUpdateVo), HttpStatus.OK);
}

@Deprecated
@Tag(name = "houseWorks")
@ApiOperation(value = "집안일 삭제 API ")
@ApiOperation(value = "집안일 삭제 API - 반복 기능 구현 전")
@DeleteMapping("/{houseWorkId}")
public ResponseEntity<?> deleteHouseWork(
@ApiIgnore @RequestMemberId Long memberId,
Expand Down Expand Up @@ -106,8 +219,10 @@ public ResponseEntity<List<HouseWorkDateResponseDto>> getHouseWork(@RequestParam
return ResponseEntity.ok(houseWorkDateResponseDtos);
}

// 1명 조회
@Deprecated
@Tag(name = "houseWorks")
@ApiOperation(value = "팀원의 특정 기간 집안일 목록 조회", notes = "본인이 속한 팀의 팀원의 특정 기간 집안일 목록 조회")
@ApiOperation(value = "팀원의 특정 기간 집안일 목록 조회 - 반복 기능 구현 전", notes = "본인이 속한 팀의 팀원의 특정 기간 집안일 목록 조회")
@GetMapping("/list/member/{teamMemberId}")
public ResponseEntity<Map<String, HouseWorkDateResponseDto>> getHouseWorkListByTeamMemberAndDate(@RequestParam("fromDate") String fromDate,
@RequestParam("toDate") String toDate,
Expand All @@ -124,8 +239,10 @@ public ResponseEntity<Map<String, HouseWorkDateResponseDto>> getHouseWorkListByT
return ResponseEntity.ok(makeHouseWorkListResponse(teamMemberId, houseWorkListGroupByScheduledDate));
}

// 팀 전체 조회
@Deprecated
@Tag(name = "houseWorks")
@ApiOperation(value = "특정 날짜별 집안일 조회", notes = "특정 날짜별 집안일 조회")
@ApiOperation(value = "특정 날짜별 집안일 조회 - 반복 기능 구현 전", notes = "특정 날짜별 집안일 조회")
@GetMapping("/list")
public ResponseEntity<Map<String, HouseWorkDateResponseDto>> getHouseWorkListByDate(@RequestParam("fromDate") String fromDate,
@RequestParam("toDate") String toDate,
Expand All @@ -139,44 +256,12 @@ public ResponseEntity<Map<String, HouseWorkDateResponseDto>> getHouseWorkListByD
return ResponseEntity.ok(makeHouseWorkListResponse(memberId, houseWorkListGroupByScheduledDate));
}

private Map<LocalDate, List<HouseWorkResponseDto>> getHouseWorkListGroupByScheduledDate(List<HouseWork> houseWorkList) {
return houseWorkList.stream().map(houseWork -> {
List<MemberDto> memberDtoList = memberService.getMemberListByHouseWorkId(houseWork.getHouseWorkId())
.stream().map(MemberDto::from).collect(Collectors.toList());
return HouseWorkResponseDto.from(houseWork, memberDtoList);
}).collect(Collectors.groupingBy(HouseWorkResponseDto::getScheduledDate, HashMap::new, Collectors.toCollection(ArrayList::new)));
}

private Map<String, HouseWorkDateResponseDto> makeHouseWorkListResponse(Long memberId, Map<LocalDate, List<HouseWorkResponseDto>> houseWorkListGroupByScheduledDate) {
Map<String, HouseWorkDateResponseDto> response = new HashMap<>();
houseWorkListGroupByScheduledDate.forEach((scheduledDate, houseWorkResponseDtoList) -> {
long countDone = houseWorkResponseDtoList.stream().filter(HouseWorkResponseDto::getSuccess).count();
long countLeft = houseWorkResponseDtoList.stream().filter(houseWorkResponseDto -> !houseWorkResponseDto.getSuccess()).count();
response.put(DateTimeUtils.localDateToString(scheduledDate), HouseWorkDateResponseDto.from(memberId, scheduledDate, countDone, countLeft, houseWorkResponseDtoList));
});
return response;
}

@Tag(name = "houseWorks")
@ApiOperation(value = "개별 집안일 조회", notes = "")
@GetMapping(value = "{houseWorkId}/detail")
public ResponseEntity<HouseWorkResponseDto> getHouseWorkDetail(@PathVariable("houseWorkId") Long houseWorkId) {
return ResponseEntity.ok(houseWorkService.getHouseWorkDetail(houseWorkId));
}

@Tag(name = "houseWorks")
@ApiOperation(value = "집안일 완료여부 수정", notes = "toBeStatus=0이면 완료->미완료, toBeStatus=1이면 미완료->완료")
@ApiOperation(value = "집안일 완료여부 수정 - 반복 기능 구현 전", notes = "toBeStatus=0이면 완료->미완료, toBeStatus=1이면 미완료->완료")
@PatchMapping(value = "{houseWorkId}")
@Deprecated
public ResponseEntity<HouseWorkStatusResponseDto> updateHouseWorkStatus(@PathVariable("houseWorkId") Long houseWorkId,
@RequestBody @Valid HouseWorkStatusRequestDto req) {
return ResponseEntity.ok(houseWorkService.updateHouseWorkStatus(houseWorkId, req.getToBeStatus()));
}

@Tag(name = "houseWorks")
@GetMapping("/success/count")
public ResponseEntity<HouseWorkSuccessCountResponseDto> getSuccessCount(@RequestParam String scheduledDate,
@ApiIgnore @RequestMemberId Long memberId) {
HouseWorkSuccessCountResponseDto houseWorkSuccessCountResponseDto = houseWorkService.getSuccessCount(scheduledDate, memberId);
return ResponseEntity.ok(houseWorkSuccessCountResponseDto);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@

import com.depromeet.fairer.domain.assignment.Assignment;
import com.depromeet.fairer.domain.base.BaseTimeEntity;
import com.depromeet.fairer.domain.housework.constant.RepeatCycle;
import com.depromeet.fairer.domain.houseworkComplete.HouseworkComplete;
import com.depromeet.fairer.domain.preset.Space;
import com.depromeet.fairer.domain.repeatexception.RepeatException;
import com.depromeet.fairer.domain.team.Team;
import com.depromeet.fairer.global.util.DateTimeUtils;
import lombok.*;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
import java.util.*;

@Entity
@Table(name = "housework")
@Getter
@Setter
@ToString(exclude = {"assignments"})
@ToString(exclude = {"assignments", "houseworkComplete"})
@EqualsAndHashCode
@Builder
@NoArgsConstructor
Expand Down Expand Up @@ -54,4 +58,41 @@ public class HouseWork extends BaseTimeEntity {
@Builder.Default
@OneToMany(mappedBy = "houseWork", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Assignment> assignments = new ArrayList<>();

@Enumerated(EnumType.STRING)
@Column(name = "repeat_cycle", columnDefinition = "VARCHAR(30)")
private RepeatCycle repeatCycle;

@Column(name = "repeat_pattern", columnDefinition = "VARCHAR(100)")
private String repeatPattern;

@Column(name = "repeat_end_date", columnDefinition = "DATE")
private LocalDate repeatEndDate; //endDate 당일까지 반복 포함

@OneToMany(mappedBy = "houseWork", cascade = CascadeType.ALL, orphanRemoval = true)
private List<HouseworkComplete> houseworkCompleteList;

@OneToMany(mappedBy = "houseWork", cascade = CascadeType.ALL, orphanRemoval = true)
private List<RepeatException> repeatExceptionList;

public boolean isIncludingDate(LocalDate date) {
if (repeatEndDate != null && date.isAfter(repeatEndDate)) {
return false;
}
boolean result = true;
if (repeatCycle == RepeatCycle.WEEKLY) {
result = StringUtils.containsIgnoreCase(repeatPattern, DateTimeUtils.convertDayOfWeekToEng(date.getDayOfWeek()));
} else if (repeatCycle == RepeatCycle.MONTHLY) {
result = Integer.parseInt(repeatPattern) == date.getDayOfMonth();
} /*else if (repeatCycle == RepeatCycle.DAILY) {
return date.isEqual(scheduledDate) || date.isAfter(scheduledDate);
} else if (repeatCycle == RepeatCycle.ONCE) {
return date.isEqual(scheduledDate) || date.isAfter(scheduledDate);
}*/
return result && (date.isEqual(scheduledDate) || date.isAfter(scheduledDate));
}

public void deleteRepeatEndDateByCycle(LocalDate deleteStandardDate) {
repeatEndDate = deleteStandardDate.minusDays(1);
}
}
Loading

0 comments on commit eae8fe3

Please sign in to comment.