Skip to content

Commit

Permalink
[Refactor] todo 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jiyunio committed May 29, 2024
1 parent 577fe5d commit 1754098
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ public class ResponseTodoDTO {
private boolean checked;
private LocalDate writeDate;
private LocalDate setDate;
private Long categoryId;
private ResponseCategoryDTO category;

@Builder
protected ResponseTodoDTO(Long todoId, String content, boolean checked,
LocalDate writeDate, LocalDate setDate, Long categoryId){
LocalDate writeDate, LocalDate setDate, ResponseCategoryDTO category){
this.todoId = todoId;
this.content = content;
this.checked = checked;
this.writeDate = writeDate;
this.setDate = setDate;
this.categoryId = categoryId;
this.category = category;
}
}
10 changes: 6 additions & 4 deletions src/main/java/com/jiyunio/todolist/todo/Todo.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jiyunio.todolist.todo;

import com.jiyunio.todolist.category.Category;
import com.jiyunio.todolist.category.CategoryDTO;
import com.jiyunio.todolist.member.Member;
import com.jiyunio.todolist.todo.dto.GetUpdateTodoDTO;
import jakarta.persistence.*;
Expand Down Expand Up @@ -34,25 +35,26 @@ public class Todo {

private LocalDate setDate;

private Long categoryId;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "categoryId")
private Category category;


@Builder
protected Todo(Member member, String content, Boolean checked,
LocalDate writeDate, LocalDate setDate, Long categoryId) {
LocalDate writeDate, LocalDate setDate, Category category) {
this.member = member;
this.content = content;
this.checked = checked;
this.writeDate = writeDate;
this.setDate = setDate;
this.categoryId = categoryId;
this.category = category;
}

protected void updateTodo(GetUpdateTodoDTO getUpdateTodoDto) {
this.content = getUpdateTodoDto.getContent();
this.checked = getUpdateTodoDto.getChecked();
this.writeDate = getUpdateTodoDto.getWriteDate();
this.setDate = getUpdateTodoDto.getSetDate();
this.categoryId = getUpdateTodoDto.getCategoryId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ public interface TodoRepository extends JpaRepository<Todo, Long> {
List<Todo> findByMemberId(Long memberId);

Optional<Todo> findById(Long todoId);

}
17 changes: 12 additions & 5 deletions src/main/java/com/jiyunio/todolist/todo/TodoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.jiyunio.todolist.customError.ErrorCode;
import com.jiyunio.todolist.member.Member;
import com.jiyunio.todolist.member.MemberRepository;
import com.jiyunio.todolist.responseDTO.ResponseCategoryDTO;
import com.jiyunio.todolist.responseDTO.ResponseTodoDTO;
import com.jiyunio.todolist.todo.dto.CreateTodoDTO;
import com.jiyunio.todolist.todo.dto.GetUpdateTodoDTO;
Expand Down Expand Up @@ -32,7 +33,6 @@ public ResponseTodoDTO createTodo(Long memberId, CreateTodoDTO createTodo) {
.writeDate(createTodo.getWriteDate())
.setDate(createTodo.getSetDate())
.checked(false)
.categoryId(createTodo.getCategoryId())
.build();

todoRepository.save(todo);
Expand All @@ -43,7 +43,11 @@ public ResponseTodoDTO createTodo(Long memberId, CreateTodoDTO createTodo) {
.checked(todo.getChecked())
.writeDate(todo.getWriteDate())
.setDate(todo.getSetDate())
.categoryId(todo.getCategoryId())
.category(ResponseCategoryDTO.builder()
.categoryId(todo.getCategory().getId())
.content(todo.getCategory().getContent())
.color(todo.getCategory().getColor())
.build())
.build();
}

Expand All @@ -58,13 +62,17 @@ public List<ResponseTodoDTO> getTodo(Long memberId) {
.writeDate(todo.getWriteDate())
.setDate(todo.getSetDate())
.checked(todo.getChecked())
.categoryId(todo.getCategoryId())
.category(ResponseCategoryDTO.builder()
.categoryId(todo.getCategory().getId())
.content(todo.getCategory().getContent())
.color(todo.getCategory().getColor())
.build())
.build());
}
return getTodoList;
}

public ResponseTodoDTO updateTodo(Long todoId,GetUpdateTodoDTO updateTodo) {
public ResponseTodoDTO updateTodo(Long todoId, GetUpdateTodoDTO updateTodo) {
Todo todo = todoRepository.findById(todoId).get();
todo.updateTodo(updateTodo);
todoRepository.save(todo);
Expand All @@ -75,7 +83,6 @@ public ResponseTodoDTO updateTodo(Long todoId,GetUpdateTodoDTO updateTodo) {
.checked(todo.getChecked())
.writeDate(todo.getWriteDate())
.setDate(todo.getSetDate())
.categoryId(todo.getCategoryId())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.jiyunio.todolist.todo.dto;

import com.jiyunio.todolist.category.Category;
import com.jiyunio.todolist.category.CategoryDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand Down

0 comments on commit 1754098

Please sign in to comment.