Skip to content

Commit

Permalink
[Refactor] todo에서의 category save 기능
Browse files Browse the repository at this point in the history
  • Loading branch information
jiyunio committed May 29, 2024
1 parent 8220c05 commit e5a23bc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/main/java/com/jiyunio/todolist/todo/TodoService.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.CategoryRepository;
import com.jiyunio.todolist.customError.CustomException;
import com.jiyunio.todolist.customError.ErrorCode;
import com.jiyunio.todolist.member.Member;
Expand All @@ -21,17 +22,15 @@
public class TodoService {
private final MemberRepository memberRepository;
private final TodoRepository todoRepository;
private final CategoryRepository categoryRepository;

public ResponseTodoDTO createTodo(Long memberId, CreateTodoDTO createTodo) {
Member member = memberRepository.findById(memberId).orElseThrow(
// 회원 존재 안함
() -> new CustomException(HttpStatus.NOT_FOUND, ErrorCode.NOT_EXIST_MEMBER)
);
Category category = Category.builder()
.member(member)
.content(createTodo.getCategory().getContent())
.color(createTodo.getCategory().getColor())
.build();

Category category = categoryRepository.findById(createTodo.getCategory().getId()).get();

Todo todo = Todo.builder()
.member(member)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ public class CreateTodoDTO {
private LocalDate setDate;

@NotNull
private ResponseCategoryDTO category;
private Category category;
}

0 comments on commit e5a23bc

Please sign in to comment.