From 9cc348c66dce4729e9d244cf081c567dd0c3c3cd Mon Sep 17 00:00:00 2001 From: lowgiant Date: Sun, 13 Feb 2022 21:02:59 +0900 Subject: [PATCH] feat: Delete Buyer List [#317] --- .../sub/buyer/controller/BuyerController.java | 9 +++++++++ .../sub/buyer/dto/BuyerDeleteRequestDto.java | 16 ++++++++++++++++ .../sub/buyer/repository/BuyerRepository.java | 2 ++ .../domain/sub/buyer/service/BuyerService.java | 13 +++++++++++++ 4 files changed, 40 insertions(+) create mode 100644 spring/src/main/java/com/bancow/bancowback/domain/sub/buyer/dto/BuyerDeleteRequestDto.java diff --git a/spring/src/main/java/com/bancow/bancowback/domain/sub/buyer/controller/BuyerController.java b/spring/src/main/java/com/bancow/bancowback/domain/sub/buyer/controller/BuyerController.java index b91a2aaa..981998fe 100644 --- a/spring/src/main/java/com/bancow/bancowback/domain/sub/buyer/controller/BuyerController.java +++ b/spring/src/main/java/com/bancow/bancowback/domain/sub/buyer/controller/BuyerController.java @@ -16,6 +16,7 @@ import com.bancow.bancowback.domain.common.dto.Response; import com.bancow.bancowback.domain.common.util.token.service.TokenService; +import com.bancow.bancowback.domain.sub.buyer.dto.BuyerDeleteRequestDto; import com.bancow.bancowback.domain.sub.buyer.dto.BuyerUpdateRequestDto; import com.bancow.bancowback.domain.sub.buyer.service.BuyerService; @@ -46,4 +47,12 @@ public Response deleteBuyer(@RequestHeader("TOKEN") final String token, tokenService.validTokenAuthority(token); return new Response<>(buyerService.deleteBuyerOne(id), HttpStatus.OK); } + + @DeleteMapping("/delete") + public Response deleteBuyerList(@RequestHeader("TOKEN") final String token, + @NotNull @RequestBody final BuyerDeleteRequestDto dto) { + tokenService.validTokenAuthority(token); + return new Response<>(buyerService.deleteBuyerList(dto.getId()), HttpStatus.OK); + } + } diff --git a/spring/src/main/java/com/bancow/bancowback/domain/sub/buyer/dto/BuyerDeleteRequestDto.java b/spring/src/main/java/com/bancow/bancowback/domain/sub/buyer/dto/BuyerDeleteRequestDto.java new file mode 100644 index 00000000..ee941cac --- /dev/null +++ b/spring/src/main/java/com/bancow/bancowback/domain/sub/buyer/dto/BuyerDeleteRequestDto.java @@ -0,0 +1,16 @@ +package com.bancow.bancowback.domain.sub.buyer.dto; + +import java.util.List; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class BuyerDeleteRequestDto { + private List id; +} diff --git a/spring/src/main/java/com/bancow/bancowback/domain/sub/buyer/repository/BuyerRepository.java b/spring/src/main/java/com/bancow/bancowback/domain/sub/buyer/repository/BuyerRepository.java index 2b6b6487..2cf858b2 100644 --- a/spring/src/main/java/com/bancow/bancowback/domain/sub/buyer/repository/BuyerRepository.java +++ b/spring/src/main/java/com/bancow/bancowback/domain/sub/buyer/repository/BuyerRepository.java @@ -8,4 +8,6 @@ public interface BuyerRepository extends JpaRepository { List findByStatus(boolean b); + + List findByIdIn(List id); } diff --git a/spring/src/main/java/com/bancow/bancowback/domain/sub/buyer/service/BuyerService.java b/spring/src/main/java/com/bancow/bancowback/domain/sub/buyer/service/BuyerService.java index 4c88f926..b937429a 100644 --- a/spring/src/main/java/com/bancow/bancowback/domain/sub/buyer/service/BuyerService.java +++ b/spring/src/main/java/com/bancow/bancowback/domain/sub/buyer/service/BuyerService.java @@ -53,5 +53,18 @@ public ServiceResult deleteBuyerOne(Long id) { return ServiceResult.success("구매자리뷰가 삭제 됐습니다. "); } + public Object deleteBuyerList(List id) { + List deleteBuyerList = buyerRepository.findByIdIn(id); + if (deleteBuyerList.size() == 0) { + throw new BuyerException(ErrorCode.NOT_FOUND_BUYER, "구매자 없음"); + } + + deleteBuyerList + .stream().forEach(e -> { + buyerRepository.delete(e); + }); + + return ServiceResult.success("구매자 성공."); + } }