Skip to content

Commit

Permalink
[Refactor] return categoryId
Browse files Browse the repository at this point in the history
  • Loading branch information
jiyunio committed May 28, 2024
1 parent 8ae69ec commit e419160
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public ResponseEntity<ResponseCategoryDTO> createCategory(@Parameter(description

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ public ResponseCategoryDTO createCategory(Long memberId, CategoryDTO categoryDTO
.build();
}

public List<CategoryDTO> getCategory(Long memberId) {
public List<ResponseCategoryDTO> getCategory(Long memberId) {
List<Category> categories = categoryRepository.findByMemberId(memberId);
List<CategoryDTO> getCategoryDTO = new ArrayList<>();
List<ResponseCategoryDTO> getCategoryDTO = new ArrayList<>();

for (Category category : categories) {
getCategoryDTO.add(CategoryDTO.builder()
getCategoryDTO.add(ResponseCategoryDTO.builder()
.categoryId(category.getId())
.content(category.getContent())
.color(category.getColor())
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ public class ResponseTodoDTO {
private String category;
private LocalDate writeDate;
private LocalDate setDate;
private String color;

@Builder
protected ResponseTodoDTO(Long todoId, String content, boolean checked,
String category, LocalDate writeDate, LocalDate setDate){
String 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;
}
}
18 changes: 9 additions & 9 deletions src/main/java/com/jiyunio/todolist/todo/Todo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.jiyunio.todolist.todo;

import com.jiyunio.todolist.member.Member;
import com.jiyunio.todolist.todo.dto.UpdateTodoDTO;
import com.jiyunio.todolist.todo.dto.GetUpdateTodoDTO;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
Expand All @@ -20,7 +20,7 @@ public class Todo {
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member Id")
@JoinColumn(name = "memberId")
private Member member;

@Lob // 길이 제한 X
Expand All @@ -44,11 +44,11 @@ protected Todo(Member member, String content, Boolean checked, String category,
this.setDate = setDate;
}

protected void updateTodo(UpdateTodoDTO updateTodoDto) {
this.content = updateTodoDto.getContent();
this.checked = updateTodoDto.getChecked();
this.writeDate = updateTodoDto.getWriteDate();
this.setDate = updateTodoDto.getSetDate();
this.category = updateTodoDto.getCategory();
protected void updateTodo(GetUpdateTodoDTO getUpdateTodoDto) {
this.content = getUpdateTodoDto.getContent();
this.checked = getUpdateTodoDto.getChecked();
this.writeDate = getUpdateTodoDto.getWriteDate();
this.setDate = getUpdateTodoDto.getSetDate();
this.category = getUpdateTodoDto.getCategory();
}
}
}
7 changes: 3 additions & 4 deletions src/main/java/com/jiyunio/todolist/todo/TodoController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import com.jiyunio.todolist.responseDTO.ResponseDTO;
import com.jiyunio.todolist.responseDTO.ResponseTodoDTO;
import com.jiyunio.todolist.todo.dto.CreateTodoDTO;
import com.jiyunio.todolist.todo.dto.GetTodoDTO;
import com.jiyunio.todolist.todo.dto.UpdateTodoDTO;
import com.jiyunio.todolist.todo.dto.GetUpdateTodoDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -31,13 +30,13 @@ public ResponseEntity<ResponseTodoDTO> createTodo(@Parameter(description = "memb

@GetMapping("/{memberId}")
@Operation(summary = "todo 조회")
public List<GetTodoDTO> getTodo(@Parameter(description = "member의 id") @PathVariable Long memberId) {
public List<GetUpdateTodoDTO> getTodo(@Parameter(description = "member의 id") @PathVariable Long memberId) {
return todoService.getTodo(memberId);
}

@PutMapping("/{todoId}")
@Operation(summary = "todo 수정")
public ResponseEntity<?> updateTodo(@Parameter(description = "todo의 id") @PathVariable Long todoId, @Valid @RequestBody UpdateTodoDTO updateTodo) {
public ResponseEntity<?> updateTodo(@Parameter(description = "todo의 id") @PathVariable Long todoId, @Valid @RequestBody GetUpdateTodoDTO updateTodo) {
return ResponseEntity.ok(todoService.updateTodo(todoId, updateTodo));
}

Expand Down
11 changes: 5 additions & 6 deletions src/main/java/com/jiyunio/todolist/todo/TodoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import com.jiyunio.todolist.member.MemberRepository;
import com.jiyunio.todolist.responseDTO.ResponseTodoDTO;
import com.jiyunio.todolist.todo.dto.CreateTodoDTO;
import com.jiyunio.todolist.todo.dto.GetTodoDTO;
import com.jiyunio.todolist.todo.dto.UpdateTodoDTO;
import com.jiyunio.todolist.todo.dto.GetUpdateTodoDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -47,12 +46,12 @@ public ResponseTodoDTO createTodo(Long memberId, CreateTodoDTO createTodo) {
.build();
}

public List<GetTodoDTO> getTodo(Long memberId) {
public List<GetUpdateTodoDTO> getTodo(Long memberId) {
List<Todo> todoList = todoRepository.findByMemberId(memberId);
List<GetTodoDTO> getTodoList = new ArrayList<>();
List<GetUpdateTodoDTO> getTodoList = new ArrayList<>();

for (Todo todo : todoList) {
getTodoList.add(GetTodoDTO.builder()
getTodoList.add(GetUpdateTodoDTO.builder()
.content(todo.getContent())
.category(todo.getCategory())
.writeDate(todo.getWriteDate())
Expand All @@ -63,7 +62,7 @@ public List<GetTodoDTO> getTodo(Long memberId) {
return getTodoList;
}

public ResponseTodoDTO updateTodo(Long todoId, UpdateTodoDTO updateTodo) {
public ResponseTodoDTO updateTodo(Long todoId, GetUpdateTodoDTO updateTodo) {
Todo todo = todoRepository.findById(todoId).get();
todo.updateTodo(updateTodo);
todoRepository.save(todo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ public class CreateTodoDTO {

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

@NotBlank
private String color;
}
32 changes: 0 additions & 32 deletions src/main/java/com/jiyunio/todolist/todo/dto/GetTodoDTO.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

Expand All @@ -11,7 +12,7 @@
@Getter
@Setter
@Schema(description = "todo 수정")
public class UpdateTodoDTO {
public class GetUpdateTodoDTO {
@NotBlank(message = "todo를 작성해주세요.")
private String content;

Expand All @@ -26,4 +27,18 @@ public class UpdateTodoDTO {

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

@NotBlank
private String color;

@Builder
protected GetUpdateTodoDTO(String content, Boolean checked, String 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 e419160

Please sign in to comment.