Skip to content

Commit

Permalink
Merge pull request #44 from Kusitms-POPTATO-DEV/feat/update-todo-content
Browse files Browse the repository at this point in the history
Feat#42: 할일 내용 수정 기능 구현
  • Loading branch information
pkl0912 authored Oct 17, 2024
2 parents 57126e6 + 6572627 commit 847eb2e
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main/java/server/poptato/todo/api/TodoController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import server.poptato.global.response.BaseResponse;
import server.poptato.todo.api.request.BacklogCreateRequestDto;
import server.poptato.todo.api.request.DeadlineUpdateRequestDto;
import server.poptato.todo.api.request.DragAndDropRequestDto;
import server.poptato.todo.api.request.SwipeRequestDto;
import server.poptato.todo.api.request.*;
import server.poptato.todo.application.TodoService;
import server.poptato.todo.application.response.BacklogListResponseDto;
import server.poptato.todo.application.response.PaginatedHistoryResponseDto;
Expand Down Expand Up @@ -104,4 +101,12 @@ public BaseResponse updateDeadline(@UserId Long userId,
todoService.updateDeadline(userId, todoId, requestDto.getDeadline());
return new BaseResponse<>();
}

@PatchMapping("/todo/{todoId}/content")
public BaseResponse updateContent(@UserId Long userId,
@PathVariable Long todoId,
@Validated @RequestBody ContentUpdateRequestDto requestDto){
todoService.updateContent(userId, todoId, requestDto.getContent());
return new BaseResponse<>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package server.poptato.todo.api.request;

import jakarta.validation.constraints.NotBlank;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class ContentUpdateRequestDto {
@NotBlank(message = "할 일 수정 시 내용은 필수입니다.")
String content;
}
12 changes: 12 additions & 0 deletions src/main/java/server/poptato/todo/application/TodoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,18 @@ public void updateDeadline(Long userId, Long todoId, LocalDate deadline) {
if(findTodo.getUserId()!=userId)
throw new TodoException(TodoExceptionErrorCode.TODO_USER_NOT_MATCH);
findTodo.updateDeadline(deadline);
//TODO: 여기도 왜 SAVE가 필수인지 몰겟담
todoRepository.save(findTodo);
}

public void updateContent(Long userId, Long todoId, String content) {
checkIsExistUser(userId);
Todo findTodo = todoRepository.findById(todoId)
.orElseThrow(() -> new TodoException(TODO_NOT_EXIST));
if(findTodo.getUserId()!=userId)
throw new TodoException(TodoExceptionErrorCode.TODO_USER_NOT_MATCH);
findTodo.updateContent(content);
//TODO: 여기도 왜 SAVE가 필수인지 몰겟담
todoRepository.save(findTodo);
}
}
4 changes: 4 additions & 0 deletions src/main/java/server/poptato/todo/domain/entity/Todo.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,8 @@ public void setBacklogOrder(int order) {
public void updateDeadline(LocalDate deadline) {
this.deadline = deadline;
}

public void updateContent(String content) {
this.content = content;
}
}
15 changes: 15 additions & 0 deletions src/test/java/server/poptato/todo/api/TodoControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,19 @@ public void shouldReturnOk_WhenIsBookmarkToggled() throws Exception {
.andExpect(status().isOk())
.andDo(print());
}

@DisplayName("할 일 내용 수정 요청 시 성공한다.")
@Test
void 할일_내용_수정_요청_성공_응답() throws Exception {
//given
Long todoId = 1L;

//when
mockMvc.perform(patch("/todo/{todoId}/content", todoId)
.header("Authorization", "Bearer " + accessToken)
.content("{\"content\": \"내용 수정\"}")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andDo(print());
}
}
16 changes: 16 additions & 0 deletions src/test/java/server/poptato/todo/application/TodoServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,20 @@ void getYesterdays_ShouldReturnPagedResult() {
//then
assertThat(findTodo.getDeadline()).isEqualTo(updateDate);
}

@DisplayName("할일 내용 수정 시 성공한다.")
@Test
void 할일_내용_수정_성공(){
//given
Long userId = 1L;
Long todoId = 11L;
String updateContent = "할일 내용 수정";

//when
todoService.updateContent(userId,todoId,updateContent);
Todo findTodo = todoRepository.findById(todoId).get();

//then
assertThat(findTodo.getContent()).isEqualTo(updateContent);
}
}

0 comments on commit 847eb2e

Please sign in to comment.