Skip to content

Commit

Permalink
fix: add updated time field to stock api (#78)
Browse files Browse the repository at this point in the history
* feat: add lastmodifiedat response field

* chore: fix swagger example format

* chore: deploy

* refactor: refactor sector request code

* fix: test code
  • Loading branch information
songyi00 authored Mar 1, 2024
1 parent 3847905 commit 74b9122
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 14 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- main
- develop
- fix/#77

jobs:
build-and-push:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ public List<SectorRatioResponse> analyzeSectorRatio(final SectorRatioRequest req
return SectorRatioResponse.fromMap(sectorInfoMap);
}

public UpcomingDividendResponse getUpcomingDividendStocks(final String sector, final int pageNumber, final int pageSize) {
public UpcomingDividendResponse getUpcomingDividendStocks(final Sector sector, final int pageNumber, final int pageSize) {
return UpcomingDividendResponse.of(
stockRepository.findUpcomingDividendStock(Sector.fromValue(sector), pageNumber, pageSize)
stockRepository.findUpcomingDividendStock(sector, pageNumber, pageSize)
.stream()
.map(stockDividend -> SingleUpcomingDividendResponse.of(
stockDividend.stock(),
Expand All @@ -117,9 +117,9 @@ public UpcomingDividendResponse getUpcomingDividendStocks(final String sector, f
);
}

public StockDividendYieldResponse getBiggestDividendStocks(final String sector, final int pageNumber, final int pageSize) {
public StockDividendYieldResponse getBiggestDividendStocks(final Sector sector, final int pageNumber, final int pageSize) {
return StockDividendYieldResponse.of(
stockRepository.findBiggestDividendYieldStock(InstantProvider.getLastYear(), Sector.fromValue(sector), pageNumber, pageSize)
stockRepository.findBiggestDividendYieldStock(InstantProvider.getLastYear(), sector, pageNumber, pageSize)
.stream()
.map(stockDividendYield -> SingleStockDividendYieldResponse.of(
stockDividendYield.stock(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import nexters.payout.domain.dividend.domain.Dividend;
import nexters.payout.domain.stock.domain.Stock;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;
import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -40,7 +42,9 @@ public record StockDetailResponse(
@Schema(requiredMode = Schema.RequiredMode.REQUIRED)
Double dividendYield,
@Schema(requiredMode = Schema.RequiredMode.REQUIRED)
List<Month> dividendMonths
List<Month> dividendMonths,
@Schema(requiredMode = Schema.RequiredMode.REQUIRED)
Instant lastModifiedAt
) {

public static StockDetailResponse of(
Expand All @@ -61,7 +65,8 @@ public static StockDetailResponse of(
dividendResponse.upcomingExDividendDate(),
dividendResponse.paymentDate(),
dividendResponse.dividendYield(),
dividendResponse.dividendMonths()
dividendResponse.dividendMonths(),
stock.getLastModifiedAt()
);
}

Expand All @@ -85,7 +90,8 @@ public static StockDetailResponse of(
dividend.getPaymentDate() == null ? null :
InstantProvider.toLocalDate(dividend.getPaymentDate()).withYear(thisYear),
dividendYield,
dividendMonths
dividendMonths,
stock.getLastModifiedAt()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import nexters.payout.apiserver.stock.application.StockQueryService;
import nexters.payout.apiserver.stock.application.dto.request.SectorRatioRequest;
import nexters.payout.apiserver.stock.application.dto.response.*;
import nexters.payout.domain.stock.domain.Sector;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

Expand Down Expand Up @@ -45,7 +46,7 @@ public ResponseEntity<List<SectorRatioResponse>> findSectorRatios(

@GetMapping("/ex-dividend-dates/upcoming")
public ResponseEntity<UpcomingDividendResponse> getUpComingDividendStocks(
@RequestParam @NotEmpty final String sector,
@RequestParam @NotNull final Sector sector,
@RequestParam @NotNull final Integer pageNumber,
@RequestParam @NotNull final Integer pageSize
) {
Expand All @@ -54,7 +55,7 @@ public ResponseEntity<UpcomingDividendResponse> getUpComingDividendStocks(

@GetMapping("/dividend-yields/highest")
public ResponseEntity<StockDividendYieldResponse> getBiggestDividendYieldStocks(
@RequestParam @NotEmpty final String sector,
@RequestParam @NotNull final Sector sector,
@RequestParam @NotNull final Integer pageNumber,
@RequestParam @NotNull final Integer pageSize
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import nexters.payout.apiserver.stock.application.dto.request.SectorRatioRequest;
import nexters.payout.apiserver.stock.application.dto.response.*;
import nexters.payout.core.exception.ErrorResponse;
import nexters.payout.domain.stock.domain.Sector;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -51,7 +52,7 @@ ResponseEntity<List<StockResponse>> searchStock(
})
@Operation(summary = "종목 상세 조회")
ResponseEntity<StockDetailResponse> getStockByTicker(
@Parameter(description = "tickerName of stock", example = "AAPL", required = true)
@Parameter(description = "ticker name of stock", example = "AAPL", required = true)
@PathVariable String ticker
);

Expand Down Expand Up @@ -85,7 +86,7 @@ ResponseEntity<List<SectorRatioResponse>> findSectorRatios(
@Operation(summary = "배당락일이 다가오는 주식 리스트")
ResponseEntity<UpcomingDividendResponse> getUpComingDividendStocks(
@Parameter(description = "sector value", example = "TECHNOLOGY", required = true)
@RequestParam @NotEmpty final String sector,
@RequestParam @NotNull final Sector sector,
@Parameter(description = "page number(start with 1) for pagination", example = "1", required = true)
@RequestParam @NotNull final Integer pageNumber,
@Parameter(description = "page size for pagination", example = "20", required = true)
Expand All @@ -102,7 +103,7 @@ ResponseEntity<UpcomingDividendResponse> getUpComingDividendStocks(
@Operation(summary = "배당수익률이 큰 주식 리스트")
ResponseEntity<StockDividendYieldResponse> getBiggestDividendYieldStocks(
@Parameter(description = "sector value", example = "TECHNOLOGY", required = true)
@RequestParam @NotEmpty final String sector,
@RequestParam @NotNull final Sector sector,
@Parameter(description = "page number(start with 1) for pagination", example = "1", required = true)
@RequestParam @NotNull final Integer pageNumber,
@Parameter(description = "page size for pagination", example = "20", required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class StockQueryServiceTest {
.willReturn(List.of(new StockDividendDto(stock, expected)));

// when
List<SingleUpcomingDividendResponse> actual = stockQueryService.getUpcomingDividendStocks("TECHNOLOGY", 1, 10).dividends();
List<SingleUpcomingDividendResponse> actual = stockQueryService.getUpcomingDividendStocks(TECHNOLOGY, 1, 10).dividends();

// then
assertAll(
Expand All @@ -189,7 +189,7 @@ class StockQueryServiceTest {
Double expectedAaplDividendYield = 5.0;

// when
List<SingleStockDividendYieldResponse> actual = stockQueryService.getBiggestDividendStocks("TECHNOLOGY", 1, 10).dividends();
List<SingleStockDividendYieldResponse> actual = stockQueryService.getBiggestDividendStocks(TECHNOLOGY, 1, 10).dividends();


// then
Expand Down

0 comments on commit 74b9122

Please sign in to comment.