Skip to content

Commit

Permalink
[Feat] todo의 category 정보 update 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jiyunio committed May 29, 2024
1 parent 29e05fd commit d3d7037
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ public List<ResponseCategoryDTO> getCategories(@Parameter(description = "member
return categoryService.getCategories(memberId);
}

@GetMapping("/{memberId}/{categoryId}")
@Operation(summary = "카테고리 조회")
public ResponseCategoryDTO getCategory(@Parameter(description = "member의 id") @PathVariable Long memberId,
@Parameter(description = "category의 id") @PathVariable Long categoryId) {
return categoryService.getCategory(memberId, categoryId);
}

@PutMapping("/{categoryId}")
@Operation(summary = "카테고리 수정")
public ResponseEntity<ResponseCategoryDTO> updateCategory(@Parameter(description = "카테고리의 id") @PathVariable Long categoryId, @RequestBody CategoryDTO categoryDTO) {
Expand Down
18 changes: 2 additions & 16 deletions src/main/java/com/jiyunio/todolist/category/CategoryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.jiyunio.todolist.responseDTO.ResponseCategoryDTO;
import com.jiyunio.todolist.todo.TodoRepository;
import com.jiyunio.todolist.todo.TodoService;
import com.jiyunio.todolist.todo.dto.CreateTodoDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -58,26 +59,11 @@ public List<ResponseCategoryDTO> getCategories(Long memberId) {
return getCategoryDTO;
}

public ResponseCategoryDTO getCategory(Long memberId, Long categoryId) {
List<Category> categories = categoryRepository.findByMemberId(memberId);
for (Category category : categories) {
if (category.getId().equals(categoryId)) {
return ResponseCategoryDTO.builder()
.categoryId(categoryId)
.content(category.getContent())
.color(category.getColor())
.build();
}
}
throw new CustomException(HttpStatus.NOT_FOUND, ErrorCode.NOT_EXIST_CATEGORY);
}

public ResponseCategoryDTO updateCategory(Long categoryId, CategoryDTO categoryDTO) {
Category category = categoryRepository.findById(categoryId).get();
category.updateCategory(categoryDTO);
categoryRepository.save(category);
todoService.updateCategory(ResponseCategoryDTO.builder() //member의 category 상태도 변경
.categoryId(categoryId)
todoService.updateCategory(categoryId, CategoryDTO.builder() //member의 category 상태도 변경
.content(category.getContent())
.color(category.getColor())
.build());
Expand Down
7 changes: 1 addition & 6 deletions src/main/java/com/jiyunio/todolist/todo/Todo.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
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.responseDTO.ResponseCategoryDTO;
import com.jiyunio.todolist.todo.dto.CreateTodoDTO;
import com.jiyunio.todolist.todo.dto.GetUpdateTodoDTO;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

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

@Getter
Expand Down Expand Up @@ -64,8 +60,7 @@ protected void updateTodo(GetUpdateTodoDTO getUpdateTodoDto) {
this.setDate = getUpdateTodoDto.getSetDate();
}

protected void updateCategory(ResponseCategoryDTO categoryDTO){
this.categoryId = categoryDTO.getCategoryId();
protected void updateCategory(CategoryDTO categoryDTO) {
this.categoryContent = categoryDTO.getContent();
this.categoryColor = categoryDTO.getColor();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/jiyunio/todolist/todo/TodoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public ResponseTodoDTO updateTodo(Long todoId, GetUpdateTodoDTO updateTodo) {
.build();
}

public void updateCategory(ResponseCategoryDTO categoryDTO) {
List<Todo> todoList = todoRepository.findByCategoryId(categoryDTO.getCategoryId());
public void updateCategory(Long categoryId, CategoryDTO categoryDTO) {
List<Todo> todoList = todoRepository.findByCategoryId(categoryId);
for (Todo todo : todoList) {
todo.updateCategory(categoryDTO);
todoRepository.save(todo);
Expand Down

0 comments on commit d3d7037

Please sign in to comment.