Skip to content

Commit

Permalink
[FIX] category, task, subTask id header로 응답
Browse files Browse the repository at this point in the history
  • Loading branch information
Seokyeong237 committed Aug 23, 2023
1 parent 39f1b73 commit 1c7edb5
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -37,9 +38,10 @@ public class CategoryController {
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
public ApiResponseDto createCategoryName(Principal principal,
@RequestBody @Valid final CategoryCreateRequestDto requestDto) {
@RequestBody @Valid final CategoryCreateRequestDto requestDto, HttpServletResponse response) {
Long memberId = MemberUtil.getMemberId(principal);
categoryService.createCategoryName(memberId, requestDto);
Long categoryId = categoryService.createCategoryName(memberId, requestDto);
response.addHeader("Location", String.valueOf(categoryId));
return ApiResponseDto.success();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public interface CategoryService {

void createCategoryName(Long memberId, CategoryCreateRequestDto categoryCreateRequestDto);
Long createCategoryName(Long memberId, CategoryCreateRequestDto categoryCreateRequestDto);
List<CategoryGetResponseDto> getAllCategory(Long memberId);
void updateCategoryName(Long memberId, Long categoryId, CategoryUpdateRequestDto categoryUpdateRequestDto);
void deleteCategory(Long categoryId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ public class CategoryServiceImpl implements CategoryService {

@Override
@Transactional
public void createCategoryName(Long memberId, CategoryCreateRequestDto requestDto) {
public Long createCategoryName(Long memberId, CategoryCreateRequestDto requestDto) {
checkDuplicateCategoryName(memberId, requestDto.getName());

categoryRepository.save(Category.builder()
Category category = categoryRepository.save(Category.builder()
.name(requestDto.getName())
.member(memberRepository.findByIdOrThrow(memberId))
.isShared(false)
.build());

return category.getId();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -46,8 +47,9 @@ public ApiResponseDto<List<SubTaskGetResponseDto>> getAllSubTask(Principal princ
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
}
)
public ApiResponseDto createSubTask(@Valid @RequestBody SubTaskCreateRequestDto requestDto) {
subTaskService.createSubTask(requestDto);
public ApiResponseDto createSubTask(@Valid @RequestBody SubTaskCreateRequestDto requestDto, HttpServletResponse response) {
Long subTaskId = subTaskService.createSubTask(requestDto);
response.addHeader("Location", String.valueOf(subTaskId));
return ApiResponseDto.success();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ public List<SubTaskGetResponseDto> getAllSubTask(Long taskId) {

@Override
@Transactional
public void createSubTask(SubTaskCreateRequestDto requestDto) {
public Long createSubTask(SubTaskCreateRequestDto requestDto) {
Task task = taskRepository.findByIdOrThrow(requestDto.getTaskId());

SubTask subTask = new SubTask(requestDto.getName(), task);

subTaskRepository.save(subTask);

return subTask.getId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
public interface SubTaskService {

List<SubTaskGetResponseDto> getAllSubTask(Long taskId);
void createSubTask(SubTaskCreateRequestDto requestDto);
Long createSubTask(SubTaskCreateRequestDto requestDto);

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
Expand All @@ -15,7 +16,6 @@
import site.katchup.katchupserver.api.task.dto.request.TaskCreateRequestDto;
import site.katchup.katchupserver.api.task.dto.request.TaskUpdateRequestDto;
import site.katchup.katchupserver.api.task.dto.response.TaskGetResponseDto;
import site.katchup.katchupserver.api.task.repository.TaskRepository;
import site.katchup.katchupserver.api.task.service.TaskService;
import site.katchup.katchupserver.common.dto.ApiResponseDto;
import site.katchup.katchupserver.common.util.MemberUtil;
Expand All @@ -31,7 +31,6 @@
@Tag(name = "[Task] 업무 관련 API (V1)")
public class TaskController {

private final TaskRepository taskRepository;
private final CardService cardService;
private final TaskService taskService;

Expand Down Expand Up @@ -82,8 +81,9 @@ public ApiResponseDto updateTaskName(@PathVariable final Long taskId,
})
@PostMapping()
@ResponseStatus(HttpStatus.CREATED)
public ApiResponseDto createTaskName(@RequestBody @Valid final TaskCreateRequestDto requestDto) {
taskService.createTaskName(requestDto);
public ApiResponseDto createTaskName(@RequestBody @Valid final TaskCreateRequestDto requestDto, HttpServletResponse response) {
Long taskId = taskService.createTaskName(requestDto);
response.addHeader("Location", String.valueOf(taskId));
return ApiResponseDto.success();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,17 @@ public void updateTaskName(Long taskId, TaskUpdateRequestDto requestDto) {

@Override
@Transactional
public void createTaskName(TaskCreateRequestDto requestDto) {
public Long createTaskName(TaskCreateRequestDto requestDto) {
Category findCategory = categoryRepository.findByIdOrThrow(requestDto.getCategoryId());

checkDuplicateTaskName(findCategory.getId(), requestDto.getName());

taskRepository.save(Task.builder()
Task task = taskRepository.save(Task.builder()
.name(requestDto.getName())
.category(findCategory)
.build());

return task.getId();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface TaskService {
List<TaskGetResponseDto> getAllTask(Long memberId);
List<TaskGetResponseDto> getByCategoryId(Long categoryId);
void updateTaskName(Long taskId, TaskUpdateRequestDto taskUpdateRequestDto);
void createTaskName(TaskCreateRequestDto taskCreateRequestDto);
Long createTaskName(TaskCreateRequestDto taskCreateRequestDto);
void deleteTask(Long taskId);

}

0 comments on commit 1c7edb5

Please sign in to comment.