Skip to content

Commit

Permalink
Merge pull request #323 from 2022-bancow-teamProject/feature/Siyeon
Browse files Browse the repository at this point in the history
[FEAT] Get Buyer Paging
  • Loading branch information
lowgiant authored Feb 13, 2022
2 parents 250b8bc + c3dd3be commit 9a2c0cf
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
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;
import com.bancow.bancowback.domain.common.exception.BuyerException;
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;
Expand Down Expand Up @@ -53,7 +57,7 @@ public ServiceResult deleteBuyerOne(Long id) {
return ServiceResult.success("구매자리뷰가 삭제 됐습니다. ");
}

public Object deleteBuyerList(List<Long> id) {
public ServiceResult deleteBuyerList(List<Long> id) {
List<Buyer> deleteBuyerList = buyerRepository.findByIdIn(id);

if (deleteBuyerList.size() == 0) {
Expand All @@ -67,4 +71,9 @@ public Object deleteBuyerList(List<Long> id) {

return ServiceResult.success("구매자 성공.");
}

public Page<BuyerPagingResponseDto> getBuyerPaging(int page) {
Page<Buyer> buyerList = buyerRepository.findAll(PageRequest.of(page, 5, Sort.by(Sort.Direction.DESC, "id")));
return buyerList.map(buyer -> buyerMapper.toBuyerPagingResponseDto(buyer));
}
}

0 comments on commit 9a2c0cf

Please sign in to comment.