Skip to content

Commit

Permalink
[Refactor] JPA 연관관계 매핑
Browse files Browse the repository at this point in the history
  • Loading branch information
jiyunio committed May 29, 2024
1 parent 88c0e10 commit 460277b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jiyunio.todolist.responseDTO;

import com.jiyunio.todolist.category.Category;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -13,20 +14,18 @@ public class ResponseTodoDTO {
private Long todoId;
private String content;
private boolean checked;
private String category;
private LocalDate writeDate;
private LocalDate setDate;
private String color;
private Category category;

@Builder
protected ResponseTodoDTO(Long todoId, String content, boolean checked,
String category, LocalDate writeDate, LocalDate setDate, String color){
Category category, LocalDate writeDate, LocalDate setDate, String color){
this.todoId = todoId;
this.content = content;
this.checked = checked;
this.category = category;
this.writeDate = writeDate;
this.setDate = setDate;
this.color = color;
this.category = category;
}
}
10 changes: 4 additions & 6 deletions src/main/java/com/jiyunio/todolist/todo/Todo.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.awt.*;
import java.time.LocalDate;

@Getter
Expand All @@ -29,25 +30,23 @@ public class Todo {

private Boolean checked;

private String category;

private LocalDate writeDate;

private LocalDate setDate;

private String color;
@OneToOne
private Category category;


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

protected void updateTodo(GetUpdateTodoDTO getUpdateTodoDto) {
Expand All @@ -56,6 +55,5 @@ protected void updateTodo(GetUpdateTodoDTO getUpdateTodoDto) {
this.writeDate = getUpdateTodoDto.getWriteDate();
this.setDate = getUpdateTodoDto.getSetDate();
this.category = getUpdateTodoDto.getCategory();
this.color = getUpdateTodoDto.getColor();
}
}
12 changes: 4 additions & 8 deletions src/main/java/com/jiyunio/todolist/todo/TodoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,20 @@ public ResponseTodoDTO createTodo(Long memberId, CreateTodoDTO createTodo) {
Todo todo = Todo.builder()
.member(member)
.content(createTodo.getContent())
.category(createTodo.getCategory())
.writeDate(createTodo.getWriteDate())
.setDate(createTodo.getSetDate())
.checked(false)
.color(createTodo.getColor())
.category(createTodo.getCategory())
.build();
todoRepository.save(todo);

return ResponseTodoDTO.builder()
.todoId(todo.getId())
.content(todo.getContent())
.checked(todo.getChecked())
.category(todo.getCategory())
.writeDate(todo.getWriteDate())
.setDate(todo.getSetDate())
.color(todo.getColor())
.category(todo.getCategory())
.build();
}

Expand All @@ -56,11 +54,10 @@ public List<ResponseTodoDTO> getTodo(Long memberId) {
getTodoList.add(ResponseTodoDTO.builder()
.todoId(todo.getId())
.content(todo.getContent())
.category(todo.getCategory())
.writeDate(todo.getWriteDate())
.setDate(todo.getSetDate())
.checked(todo.getChecked())
.color(todo.getColor())
.category(todo.getCategory())
.build());
}
return getTodoList;
Expand All @@ -75,10 +72,9 @@ public ResponseTodoDTO updateTodo(Long todoId, GetUpdateTodoDTO updateTodo) {
.todoId(todo.getId())
.content(todo.getContent())
.checked(todo.getChecked())
.category(todo.getCategory())
.writeDate(todo.getWriteDate())
.setDate(todo.getSetDate())
.color(todo.getColor())
.category(todo.getCategory())
.build();
}

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

import com.jiyunio.todolist.category.Category;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand All @@ -15,15 +16,12 @@ public class CreateTodoDTO {
@NotBlank(message = "todo를 작성해주세요.")
private String content;

@NotBlank
private String category;

@NotNull(message = "작성 일자를 선택해주세요.")
private LocalDate writeDate;

@NotNull(message = "설정 일자를 선택해주세요.")
private LocalDate setDate;

@NotBlank
private String color;
private Category category;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jiyunio.todolist.todo.dto;

import com.jiyunio.todolist.category.Category;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand All @@ -19,26 +20,22 @@ public class GetUpdateTodoDTO {
@NotNull
private Boolean checked;

@NotBlank
private String category;

@NotNull(message = "작성 일자를 선택해주세요.")
private LocalDate writeDate;

@NotNull(message = "설정 일자를 선택해주세요.")
private LocalDate setDate;

@NotBlank
private String color;
private Category category;

@Builder
protected GetUpdateTodoDTO(String content, Boolean checked, String category,
protected GetUpdateTodoDTO(String content, Boolean checked, Category category,
LocalDate writeDate, LocalDate setDate, String color) {
this.content = content;
this.checked = checked;
this.category = category;
this.writeDate = writeDate;
this.setDate = setDate;
this.color = color;
}
}

0 comments on commit 460277b

Please sign in to comment.