Skip to content

Commit

Permalink
Merge pull request #150 from kakao-tech-campus-2nd-step3/weekly
Browse files Browse the repository at this point in the history
Weekly
  • Loading branch information
sunandrabbit authored Nov 14, 2024
2 parents a6c4ef2 + f5f4deb commit 604ac04
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ public SingleResult<TaskDetail> getTask(@PathVariable("taskId") Long taskId) {
public PageResult<TaskWithOwnerDetail> getTaskList(@PathVariable("projectId") Long projectId,
@RequestParam(value = "status", required = false) String status,
@RequestParam(value = "priority", required = false) String priority,
@RequestParam(value = "owner", required = false) String ownerName,
@RequestParam(value = "owner", required = false) long ownerId,
@Valid TaskDTO.getList param) {

return PageMapper.toPageResult(
taskService.getTaskList(projectId, status, priority, ownerName, param));
taskService.getTaskList(projectId, status, priority, ownerId, param));
}

@Operation(summary = "팀 전체 진행도 확인")
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/team1/be/seamless/service/ProjectService.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,18 @@ public ProjectDetail updateProject(long projectId, ProjectUpdate update, String
}

//종료일이 가장 늦은 태스크보다 종료일을 이전으로 업데이드 하면 안됨
LocalDateTime lastEndDate = projectEntity.getTaskEntities().stream()
projectEntity.getTaskEntities().stream()
.map(TaskEntity::getEndDate)
.max(Comparator.naturalOrder()).orElseThrow();
.max(Comparator.naturalOrder())
.ifPresent(lastEndDate -> {
if (lastEndDate.isAfter(update.getEndDate())) {
throw new BaseHandler(HttpStatus.BAD_REQUEST,
"변경하려는 프로젝트의 종료일은 현재 태스크의 가장 늦은 종료일 보다 이릅니다.");
}
});



if (lastEndDate.isAfter(update.getEndDate())) {
throw new BaseHandler(HttpStatus.BAD_REQUEST, "변경하려는 프로젝트의 종료일은 현재 태스크의 가장 늦은 종료일 보다 이릅니다.");
}

projectMapper.toUpdate(projectEntity, update, newProjectOptionEntities);

Expand Down
19 changes: 4 additions & 15 deletions src/main/java/team1/be/seamless/service/TaskService.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,14 @@ public TaskDetail getTask(Long taskId) {
}

public Page<TaskWithOwnerDetail> getTaskList(Long projectId, String status, String priority,
String ownerName, getList param) {
long ownerId, getList param) {

//멤버 아이디에 대한 쿼리 파라미터가 존재할때 : null일때
Long memberId = null;

if (ownerName != null) {
MemberEntity memberEntity = memberRepository.findByName(ownerName)
MemberEntity memberEntity = memberRepository.findByIdAndIsDeleteFalse(ownerId)
.orElseThrow(() -> new BaseHandler(HttpStatus.NOT_FOUND, "존재하지 않는 멤버"));
memberId = memberEntity.getId();
}

Page<TaskEntity> taskEntities = taskRepository.findByProjectIdAndOptionalFilters(projectId,
status, priority, memberId, param.toPageable());
status, priority, ownerId, param.toPageable());

return new PageImpl<>(
taskEntities.stream()
Expand All @@ -72,7 +67,6 @@ public Page<TaskWithOwnerDetail> getTaskList(Long projectId, String status, Stri
taskEntities.getPageable(),
taskEntities.getTotalElements()
);

}

public ProjectProgress getProjectProgress(Long projectId, getList param) {
Expand All @@ -83,11 +77,7 @@ public ProjectProgress getProjectProgress(Long projectId, getList param) {
int sum = taskEntities.getContent().stream().mapToInt(TaskEntity::getProgress).sum();
int count = taskEntities.getContent().size();

if (count == 0) {
throw new BaseHandler(HttpStatus.NOT_FOUND, "해당 프로젝트에 할당된 태스크가 존재하지 않습니다.");
}

int average = sum / count;
int average = (count == 0) ? 0 : sum / count;
String growthLevel;
String description;

Expand Down Expand Up @@ -135,7 +125,6 @@ public Page<MemberProgress> getMemberProgress(Long projectId, getList param) {

if (param.getPage() * param.getSize() >= memberEntities.size()) {
start = 0;

} else {
start = param.getPage() * param.getSize();
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/team1/be/seamless/e2e/ProjectE2ETest.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void setUp() {
}

@Test
void 프로젝트_날짜_수정_성공() {
void 프로젝트_종료일은_태스크의_가장_늦은_종료일보다_뒤여야_합니다() {
ProjectUpdate body = new ProjectUpdate(
"프로젝트 이름1",
"프로젝트 설명1",
Expand All @@ -106,7 +106,7 @@ public void setUp() {
requestEntity,
String.class);
System.out.println(responseEntity.getBody());
assertThat(responseEntity.getStatusCode()).isEqualTo(OK);
assertThat(responseEntity.getStatusCode()).isEqualTo(BAD_REQUEST);
}

@Test
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/team1/be/seamless/service/TaskServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ void setUp() {
1L,
"IN_PROGRESS",
"HIGH",
memberEntity.getId(),
1L,
taskParam.toPageable())).thenReturn(tasks);
when(memberRepository.findByName("멤버 1")).thenReturn(Optional.of(memberEntity));
when(memberRepository.findByIdAndIsDeleteFalse(1L)).thenReturn(Optional.of(memberEntity));
when(taskMapper.toDetailWithOwner(any(TaskEntity.class)))
.thenReturn(mock(TaskDTO.TaskWithOwnerDetail.class));

Expand All @@ -140,15 +140,15 @@ void setUp() {
1L,
"IN_PROGRESS",
"HIGH",
"멤버 1",
1L,
taskParam);

// Then
assertThat(result).isNotNull();
assertThat(result.getTotalElements()).isEqualTo(2);
verify(taskRepository, times(1)).findByProjectIdAndOptionalFilters(
1L, "IN_PROGRESS", "HIGH", memberEntity.getId(), taskParam.toPageable());
verify(memberRepository, times(1)).findByName("멤버 1"); // 멤버 조회가 1번 호출되었는지 확인
1L, "IN_PROGRESS", "HIGH", 1L, taskParam.toPageable());
verify(memberRepository, times(1)).findByIdAndIsDeleteFalse(1L);
verify(taskMapper, atLeastOnce()).toDetailWithOwner(any(TaskEntity.class));
}

Expand Down

0 comments on commit 604ac04

Please sign in to comment.