Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

todolist #3

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions backend-study-2023.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
11 changes: 9 additions & 2 deletions src/pro/hexa/study/backend/todo/domain/ChildTodo.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@ public ParentTodo getParent() {

public void setParentTodo(ParentTodo parent) {
// todo: parentTodo를 지정하고, parentTodo의 details에 이 childTodo가 없으면 details에도 추가.
}
this.parent = parent;
if (!parent.getDetails().contains(this)) {
parent.addDetailTodo(this);
}

}
void completeTodo() {
// todo: 이 childTodo의 완료 처리

this.completeYn = true;


}
}
34 changes: 32 additions & 2 deletions src/pro/hexa/study/backend/todo/domain/ParentTodo.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

public class ParentTodo extends Todo {


private List<ChildTodo> details;

public ParentTodo(String title, String content, Short timeToTakeInMinutes, LocalDateTime startAt, boolean completeYn) {
Expand All @@ -19,15 +20,44 @@ public List<ChildTodo> getDetails() {

public void addDetailTodo(ChildTodo detail) {
// todo: details에 detail을 추가하고, detail의 parent로 지금 이 parentTodo를 지정하기(parent가 이 객체가 아닐때만).
this.details.add(detail);
if (detail.getParent()!=this) {
detail.setParentTodo(this);
}
// todo: parentTodo의 걸리는 시간은 details의 걸리는 시간의 합과 같도록 항상 유지해줘야한다.
updateTimeToTakeInMinutes();
}

public void deleteDetailTodo(ChildTodo detail) {
// todo: detail을 details에서 삭제하고, detail의 parent에서도 지금 이 parentTodo를 삭제하기.
// todo: parentTodo의 걸리는 시간은 details의 걸리는 시간의 합과 같도록 항상 유지해줘야한다.
this.details.remove(detail);
if (detail.getParent()==this) {
detail.setParentTodo(null);
}
updateTimeToTakeInMinutes();


}

public void completeTodo(ChildTodo childTodo) {
// todo: 입력 받은 childTodo의 완료 처리와 동시에 parentTodo의 모든 details 내에 있는 todo가 완료 되었으면 parentTodo도 완료 처리.
public void completeTodo() {
// todo: 입력 받은 childTodo의 완료 처리와 동시에 parentTodo의 모든 details 내에 있는 todo가 완료 되었으면 parentTodo도 완료 처리
boolean allDetailsComplete = true;
for (ChildTodo d : this.details) {
if (!d.completeYn) {
allDetailsComplete = false;
break;
}
}
if (allDetailsComplete) {
this.completeYn = true;
}
}
private void updateTimeToTakeInMinutes() {
short total=0;
for (ChildTodo d : this.details) {
total+= d.timeToTakeInMinutes;
}
this.timeToTakeInMinutes=total;
}
}
45 changes: 45 additions & 0 deletions src/pro/hexa/study/backend/todo/domain/Todo.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,49 @@ protected Todo(String title, String content, Short timeToTakeInMinutes, LocalDat
this.startAt = startAt;
this.completeYn = completeYn;
}

public Long getId(){
return this.id;
}
public String getTitle(){
return this.title;
}
public String getContent(){
return this.content;
}
public Short getTimeToTakeInMinutes(){
return this.timeToTakeInMinutes;
}
public LocalDateTime getStartAt(){
return this.startAt;
}
public boolean getCompleteYn(){
return this.completeYn;
}
public void setId(Long id) {
this.id = id;
}

public void setTitle(String title) {
this.title = title;
}

public void setContent(String content) {
this.content = content;
}

public void setTimeToTakeInMinutes(Short timeToTakeInMinutes) {
this.timeToTakeInMinutes = timeToTakeInMinutes;
}

public void setStartAt(LocalDateTime startAt) {
this.startAt = startAt;
}

public void setCompleteYn(boolean completeYn) {
this.completeYn = completeYn;
}
}



8 changes: 8 additions & 0 deletions src/pro/hexa/study/backend/todo/dto/SaveTodoRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ public class SaveTodoRequest {

private List<Long> todoDeleteIds;
private List<TodoUpdateDto> todoUpdateList;

public List<Long> getTodoDeleteIds() {
return todoDeleteIds;
}

public List<TodoUpdateDto> getTodoUpdateList() {
return todoUpdateList;
}
}
31 changes: 20 additions & 11 deletions src/pro/hexa/study/backend/todo/dto/TodoInquiryDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@
import java.time.LocalDateTime;
import java.util.List;

/*
* todoList 조회용 dto
*/
public class TodoInquiryDto {
private List<Long> id;
private String title;
private String content;
private List<String> subTitles;
private List<String> detailContents;
private int timeToTakeInMinutes;
private LocalDateTime startAt;
private boolean completeYn;

private List<Long> id; // 맨 첫 id가 parent, 그 뒤로 따라오는건 child
private String title; // 제목
private String content; // 상세 내용
private List<String> subTitles; // child title list
private List<String> detailContents; // child content list
private Short remainingTime; // 예상되는 남은 시간(분)
private LocalDateTime startAt; // 시작 예정시간
private boolean completeYn; // 완료 여부
public TodoInquiryDto(List<Long> id, String title, String content, List<String> subTitles, List<String> detailContents, int timeToTakeInMinutes, LocalDateTime startAt, boolean completeYn) {
this.id = id;
this.title = title;
this.content = content;
this.subTitles = subTitles;
this.detailContents = detailContents;
this.timeToTakeInMinutes = timeToTakeInMinutes;
this.startAt = startAt;
this.completeYn = completeYn;
}

// getters and setters
}
18 changes: 15 additions & 3 deletions src/pro/hexa/study/backend/todo/dto/TodoResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,22 @@
* 할 일 목록 처리 등을 위한 객체
*/
public class TodoResponse {

private List<TodoInquiryDto> todoList;
private Integer completedCount; // 완료한 todo객체 개수
private Integer totalCount; // 전체 todo객체 개수
private int completedCount;
private int totalCount;

// Setter 메서드
public void setTodoList(List<TodoInquiryDto> todoList) {
this.todoList = todoList;
}

public void setCompletedCount(int completedCount) {
this.completedCount = completedCount;
}

public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}

public List<TodoInquiryDto> getTodoList() {
return this.todoList;
Expand Down
20 changes: 20 additions & 0 deletions src/pro/hexa/study/backend/todo/dto/TodoUpdateDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,24 @@ public class TodoUpdateDto {
private LocalDateTime startAt; // 시작 예정시간
private LocalDateTime endAt; // 완료 예정시간
private boolean completeYn; // 완료 여부
// Getter methods
public Long getId() {
return id;
}

public String getTitle() {
return title;
}

public String getDetail() {
return detail;
}

public LocalDateTime getStartAt() {
return startAt;
}

public boolean getCompleteYn() {
return completeYn;
}
}
86 changes: 82 additions & 4 deletions src/pro/hexa/study/backend/todo/service/TodoService.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package pro.hexa.study.backend.todo.service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import pro.hexa.study.backend.todo.domain.Todo;
import pro.hexa.study.backend.todo.domain.ParentTodo;
import pro.hexa.study.backend.todo.dto.SaveTodoRequest;
import pro.hexa.study.backend.todo.dto.TodoInquiryDto;
import pro.hexa.study.backend.todo.dto.TodoResponse;
import pro.hexa.study.backend.todo.dto.TodoUpdateDto;

/*
* todoList를 위한 변환 로직
Expand Down Expand Up @@ -33,14 +40,85 @@ public void saveTodoEntities(List<Todo> todoEntities) {
* todoList를 todoResponse로 변환
*/
public TodoResponse getTodoResponse() {
// todo
return null;
List<TodoInquiryDto> todoInquiryDtoList = new ArrayList<>();
int completedCount = 0;
int totalCount = 0;

for (Todo todo : todoEntities) {
if (todo instanceof ParentTodo) {
ParentTodo parentTodo = (ParentTodo) todo;
List<String> subTitles = parentTodo.getDetails().stream().map(Todo::getTitle).collect(Collectors.toList());
List<String> detailContents = parentTodo.getDetails().stream().map(Todo::getContent).collect(Collectors.toList());
List<Long> ids = Arrays.asList(parentTodo.getId());
TodoInquiryDto todoInquiryDto = new TodoInquiryDto(
ids,
parentTodo.getTitle(),
parentTodo.getContent(),
subTitles,
detailContents,
parentTodo.getTimeToTakeInMinutes(),
parentTodo.getStartAt(),
parentTodo.getCompleteYn()
);
todoInquiryDtoList.add(todoInquiryDto);
totalCount++;
if (parentTodo.getCompleteYn()) {
completedCount++;
}
}
}

TodoResponse todoResponse = new TodoResponse();
todoResponse.setTodoList(todoInquiryDtoList);
todoResponse.setCompletedCount(completedCount);
todoResponse.setTotalCount(totalCount);

return todoResponse;
}

/*
* todoList 수정 요청 받아서 처리한 뒤 저장
*/
public void saveTodo(SaveTodoRequest request) {
// todo
// Delete todos
for (Long deleteId : request.getTodoDeleteIds()) {
todoEntities.removeIf(todo -> todo.getId().equals(deleteId));
}

// Update or add todos
for (TodoUpdateDto todoUpdateDto : request.getTodoUpdateList()) {
Todo todo = findTodoById(todoUpdateDto.getId());
if (todo != null) {
// Update todo
todo.setTitle(todoUpdateDto.getTitle());
todo.setContent(todoUpdateDto.getDetail());
todo.setStartAt(todoUpdateDto.getStartAt());
todo.setCompleteYn(todoUpdateDto.getCompleteYn());
} else {
// Add new todo
ParentTodo parentTodo = new ParentTodo(
todoUpdateDto.getTitle(),
todoUpdateDto.getDetail(),
(short) 0,
todoUpdateDto.getStartAt(),
todoUpdateDto.getCompleteYn()
);
todoEntities.add(parentTodo);
}
}
}
}

private Todo findTodoById(Long id) {
if (id == null) {
return null;
}
for (Todo todo : todoEntities) {
if (todo.getId().equals(id)) {
return todo;
}
}
return null;
}

// ... 기존 코드 ...
}
18 changes: 9 additions & 9 deletions src/pro/hexa/study/backend/todo/service/TodoSetupService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ public class TodoSetupService {
public List<Todo> setup() {
LocalDateTime projectStartAt = LocalDateTime.of(2023, 4, 11, 23, 0, 0);
ParentTodo parentTodo = new ParentTodo(
"해야할 일", "기존에 있는 코드를 수정하지 않고, Main.main 함수가 의도하는 대로 잘 돌아가도록 하기.",
(short) 60, projectStartAt, false
"해야할 일", "기존에 있는 코드를 수정하지 않고, Main.main 함수가 의도하는 대로 잘 돌아가도록 하기.",
(short) 60, projectStartAt, false
);

Todo childTodo1 = new ChildTodo(
"첫번째 세부사항", "ParentTodo와 ChildTodo 내에 todo 작업 완료하기.",
(short) 20, projectStartAt, false, parentTodo
"첫번째 세부사항", "ParentTodo와 ChildTodo 내에 todo 작업 완료하기.",
(short) 20, projectStartAt, false, parentTodo
);
Todo childTodo2 = new ChildTodo(
"두번째 세부사항", "TodoService에 있는 todo 작업 완료하기.",
(short) 40, projectStartAt, false, parentTodo
"두번째 세부사항", "TodoService에 있는 todo 작업 완료하기.",
(short) 40, projectStartAt, false, parentTodo
);

return List.of(
parentTodo,
childTodo1,
childTodo2
parentTodo,
childTodo1,
childTodo2
);
}
}