Skip to content

Commit

Permalink
feat: Delete Buyer List [#317]
Browse files Browse the repository at this point in the history
  • Loading branch information
lowgiant committed Feb 13, 2022
1 parent a83fe7d commit 9cc348c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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<Long> id;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@

public interface BuyerRepository extends JpaRepository<Buyer, Long> {
List<Buyer> findByStatus(boolean b);

List<Buyer> findByIdIn(List<Long> id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,18 @@ public ServiceResult deleteBuyerOne(Long id) {
return ServiceResult.success("구매자리뷰가 삭제 됐습니다. ");
}

public Object deleteBuyerList(List<Long> id) {
List<Buyer> 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("구매자 성공.");
}
}

0 comments on commit 9cc348c

Please sign in to comment.