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 981998fe..29fa6e6c 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 @@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import com.bancow.bancowback.domain.common.dto.Response; @@ -34,6 +35,13 @@ public Response getBuyerDistribute() { return new Response<>(buyerService.getBuyerDistribute(), HttpStatus.OK); } + @GetMapping() + public Response getBuyerPaging(@RequestHeader("TOKEN") final String token, + @NotNull @RequestParam("page") final int page) { + tokenService.validTokenAuthority(token); + return new Response<>(buyerService.getBuyerPaging(page), HttpStatus.OK); + } + @PatchMapping("/edit") public Response editBuyer(@RequestHeader("TOKEN") final String token, @Valid @RequestBody BuyerUpdateRequestDto buyerUpdateRequestDto) { diff --git a/spring/src/main/java/com/bancow/bancowback/domain/sub/buyer/dto/BuyerPagingResponseDto.java b/spring/src/main/java/com/bancow/bancowback/domain/sub/buyer/dto/BuyerPagingResponseDto.java new file mode 100644 index 00000000..ba693bb9 --- /dev/null +++ b/spring/src/main/java/com/bancow/bancowback/domain/sub/buyer/dto/BuyerPagingResponseDto.java @@ -0,0 +1,37 @@ +package com.bancow.bancowback.domain.sub.buyer.dto; + +import java.time.LocalDateTime; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class BuyerPagingResponseDto { + + private Long id; + + @JsonProperty("buyer_name") + private String buyerName; + + private String title; + + @JsonProperty("user_name") + private String userName; + + @JsonProperty("farm_name") + private String farmName; + + private Boolean status; + + @JsonProperty("create_date") + private LocalDateTime create_date; +} diff --git a/spring/src/main/java/com/bancow/bancowback/domain/sub/buyer/mapper/BuyerMapper.java b/spring/src/main/java/com/bancow/bancowback/domain/sub/buyer/mapper/BuyerMapper.java index 7f3abc2b..ac4568c6 100644 --- a/spring/src/main/java/com/bancow/bancowback/domain/sub/buyer/mapper/BuyerMapper.java +++ b/spring/src/main/java/com/bancow/bancowback/domain/sub/buyer/mapper/BuyerMapper.java @@ -3,6 +3,7 @@ import org.springframework.stereotype.Component; import com.bancow.bancowback.domain.sub.buyer.dto.BuyerDistributeResponseDto; +import com.bancow.bancowback.domain.sub.buyer.dto.BuyerPagingResponseDto; import com.bancow.bancowback.domain.sub.buyer.dto.BuyerUpdateRequestDto; import com.bancow.bancowback.domain.sub.buyer.entity.Buyer; @@ -30,4 +31,17 @@ public Buyer toUpdateNotImageEntity(Buyer buyer, BuyerUpdateRequestDto buyerUpda .createDate(buyer.getCreateDate()) .build(); } + + public BuyerPagingResponseDto toBuyerPagingResponseDto(Buyer buyer){ + return BuyerPagingResponseDto.builder() + .id(buyer.getId()) + .buyerName(buyer.getBuyerName()) + .title(buyer.getTitle()) + .userName(buyer.getManager().getUsername()) + .farmName(buyer.getFarm().getFarmName()) + .status(buyer.getStatus()) + .create_date(buyer.getCreateDate()) + .build(); + + } } 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 b937429a..0f0c8bc9 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 @@ -3,6 +3,9 @@ import java.util.List; import java.util.stream.Collectors; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; import com.bancow.bancowback.domain.common.dto.ServiceResult; @@ -10,6 +13,7 @@ import com.bancow.bancowback.domain.common.exception.ErrorCode; import com.bancow.bancowback.domain.common.exception.EventException; import com.bancow.bancowback.domain.sub.buyer.dto.BuyerDistributeResponseDto; +import com.bancow.bancowback.domain.sub.buyer.dto.BuyerPagingResponseDto; import com.bancow.bancowback.domain.sub.buyer.dto.BuyerUpdateRequestDto; import com.bancow.bancowback.domain.sub.buyer.entity.Buyer; import com.bancow.bancowback.domain.sub.buyer.mapper.BuyerMapper; @@ -53,7 +57,7 @@ public ServiceResult deleteBuyerOne(Long id) { return ServiceResult.success("구매자리뷰가 삭제 됐습니다. "); } - public Object deleteBuyerList(List id) { + public ServiceResult deleteBuyerList(List id) { List deleteBuyerList = buyerRepository.findByIdIn(id); if (deleteBuyerList.size() == 0) { @@ -67,4 +71,9 @@ public Object deleteBuyerList(List id) { return ServiceResult.success("구매자 성공."); } + + public Page getBuyerPaging(int page) { + Page buyerList = buyerRepository.findAll(PageRequest.of(page, 5, Sort.by(Sort.Direction.DESC, "id"))); + return buyerList.map(buyer -> buyerMapper.toBuyerPagingResponseDto(buyer)); + } }