-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from lotteon2/O2F-1052/feat/read-auctions
O2 f 1052/feat/read auctions
- Loading branch information
Showing
8 changed files
with
218 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/com/dailyon/auctionservice/dto/response/ReadAuctionPageResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.dailyon.auctionservice.dto.response; | ||
|
||
import com.dailyon.auctionservice.document.Auction; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ReadAuctionPageResponse { | ||
private long totalElements; | ||
private int totalPages; | ||
private List<ReadAuctionResponse> responses; | ||
|
||
public static ReadAuctionPageResponse of(Page<Auction> auctions) { | ||
return ReadAuctionPageResponse.builder() | ||
.totalPages(auctions.getTotalPages()) | ||
.totalElements(auctions.getTotalElements()) | ||
.responses(auctions.stream() | ||
.map(ReadAuctionResponse::of) | ||
.collect(Collectors.toList())) | ||
.build(); | ||
} | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class ReadAuctionResponse { | ||
private String id; | ||
private Long auctionProductId; | ||
private String auctionName; | ||
private Integer startBidPrice; | ||
private Integer maximumWinner; | ||
private LocalDateTime startAt; | ||
private boolean isStarted; | ||
private boolean isEnded; | ||
|
||
public static ReadAuctionResponse of(Auction auction) { | ||
return ReadAuctionResponse.builder() | ||
.id(auction.getId()) | ||
.auctionProductId(auction.getAuctionProductId()) | ||
.auctionName(auction.getAuctionName()) | ||
.startBidPrice(auction.getStartBidPrice()) | ||
.maximumWinner(auction.getMaximumWinner()) | ||
.startAt(auction.getStartAt()) | ||
.isStarted(auction.isStarted()) | ||
.isEnded(auction.isEnded()) | ||
.build(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/test/java/com/dailyon/auctionservice/service/AuctionServiceTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.dailyon.auctionservice.service; | ||
|
||
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBAsync; | ||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; | ||
import com.amazonaws.services.dynamodbv2.model.CreateTableRequest; | ||
import com.amazonaws.services.dynamodbv2.model.ProvisionedThroughput; | ||
import com.amazonaws.services.dynamodbv2.util.TableUtils; | ||
import com.dailyon.auctionservice.ContainerBaseTestSupport; | ||
import com.dailyon.auctionservice.document.Auction; | ||
import com.dailyon.auctionservice.repository.AuctionRepository; | ||
import org.assertj.core.api.BDDAssertions; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.BDDMockito; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.stream.IntStream; | ||
|
||
public class AuctionServiceTests extends ContainerBaseTestSupport { | ||
@Autowired private AmazonDynamoDBAsync dynamoDB; | ||
@Autowired private DynamoDBMapper dynamoDBMapper; | ||
@Autowired private AuctionRepository auctionRepository; | ||
@Autowired private AuctionService auctionService; | ||
|
||
@BeforeEach | ||
void beforeEach() { | ||
CreateTableRequest createTableRequest = dynamoDBMapper | ||
.generateCreateTableRequest(Auction.class) | ||
.withProvisionedThroughput(new ProvisionedThroughput(1L, 1L)); | ||
|
||
TableUtils.createTableIfNotExists(dynamoDB, createTableRequest); | ||
} | ||
|
||
@AfterEach | ||
void afterEach() { | ||
TableUtils.deleteTableIfExists( | ||
dynamoDB, | ||
dynamoDBMapper.generateDeleteTableRequest(Auction.class) | ||
); | ||
} | ||
|
||
@Test | ||
@DisplayName("경매 목록 생성 내림차순 기준 정렬 페이지네이션 조회") | ||
void paginationTest() { | ||
for(int i=0; i<10; i++) { | ||
auctionRepository.save(Auction.builder() | ||
.auctionProductId((long) i) | ||
.auctionName("TEST_"+i) | ||
.startBidPrice(1000) | ||
.maximumWinner(5) | ||
.startAt(LocalDateTime.now()) | ||
.build() | ||
); | ||
} | ||
|
||
Page<Auction> auctions = auctionService.readAuctions(PageRequest.of(0, 5)); | ||
assertEquals(10, auctions.getTotalElements()); | ||
assertEquals(2, auctions.getTotalPages()); | ||
assertEquals(5, auctions.getContent().size()); | ||
IntStream.range(1, 5).forEach(i -> { | ||
Auction prev = auctions.getContent().get(i-1); | ||
Auction next = auctions.getContent().get(i); | ||
|
||
BDDAssertions | ||
.then(prev.getCreatedAt().isAfter(next.getCreatedAt())) | ||
.isTrue(); | ||
}); | ||
} | ||
} |