Skip to content

Commit

Permalink
feat: 카테고리 삭제 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
peeerr committed Oct 2, 2024
1 parent 2975e5f commit cfbdfe9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -53,4 +54,13 @@ public ResponseEntity<SuccessResponse> updateCategory(@PathVariable Long categor
.body(SuccessResponse.ok());
}

@DeleteMapping("/{categoryId}")
public ResponseEntity<SuccessResponse> deleteCategory(@PathVariable Long categoryId,
@AuthenticationPrincipal MemberDetails memberDetails) {
categoryService.deleteCategory(categoryId, memberDetails.getId());

return ResponseEntity.ok()
.body(SuccessResponse.ok());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,13 @@ public void updateCategory(Long categoryId, Long memberId, CategoryCreateRequest
category.update(request.getCategoryName());
}

public void deleteCategory(Long categoryId, Long memberId) {
Category category = categoryRepository.findById(categoryId)
.orElseThrow(() -> new GlobalException(ErrorCode.CATEGORY_NOT_FOUND));

category.checkOwner(memberId);

categoryRepository.delete(category);
}

}

0 comments on commit cfbdfe9

Please sign in to comment.