Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] Delete Buyer List #318

Merged
merged 1 commit into from
Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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("구매자 성공.");
}
}