Skip to content

Commit

Permalink
Merge pull request #35 from MOONSHOT-Team/feature/#34
Browse files Browse the repository at this point in the history
[Refactor] #34 - KeyResult 삭제 API 수정
  • Loading branch information
its-sky authored Jan 6, 2024
2 parents d778d61 + 287729f commit 14050e7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.moonshot.server.domain.keyresult.dto.request.KeyResultCreateRequestDto;
import org.moonshot.server.domain.keyresult.dto.request.KeyResultDeleteRequestDto;
import org.moonshot.server.domain.keyresult.dto.request.KeyResultModifyRequestDto;
import org.moonshot.server.domain.keyresult.service.KeyResultService;
import org.moonshot.server.global.common.response.ApiResponse;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -29,9 +29,9 @@ public ApiResponse<?> createKeyResult(@RequestBody @Valid KeyResultCreateRequest
return ApiResponse.success(POST_KEY_RESULT_SUCCESS);
}

@DeleteMapping
public ApiResponse<?> deleteKeyResult(@RequestBody @Valid KeyResultDeleteRequestDto request) {
keyResultService.deleteKeyResult(request.keyResultIds());
@DeleteMapping("/{keyResultId}")
public ApiResponse<?> deleteKeyResult(@PathVariable("keyResultId") Long keyResultId) {
keyResultService.deleteKeyResult(keyResultId);
return ApiResponse.success(DELETE_KEY_RESULT_SUCCESS);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.moonshot.server.domain.keyresult.service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -87,8 +86,11 @@ public void createKeyResult(KeyResultCreateRequestDto request) {
}

@Transactional
public void deleteKeyResult(List<Long> keyResultIds) {
cascadeDelete(keyResultRepository.findByIdIn(keyResultIds));
public void deleteKeyResult(Long keyResultId) {
KeyResult keyResult = keyResultRepository.findById(keyResultId)
.orElseThrow(KeyResultNotFoundException::new);
taskRepository.deleteAllInBatch(taskRepository.findAllByKeyResult(keyResult));
keyResultRepository.delete(keyResult);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class SecurityConfig {
"/v1/image",
"/v1/objective",
"/v1/task",
"/v1/key-result",
"/v1/key-result/**",
"/error",
"/swagger-ui/**",
"/swagger-resources/**",
Expand Down

0 comments on commit 14050e7

Please sign in to comment.