Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
songyi00 committed Mar 10, 2024
2 parents d6453ce + 834a2f1 commit 6fba9c6
Show file tree
Hide file tree
Showing 17 changed files with 58 additions and 76 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

<h3> 📈 미국 배당 투자자를 위한 배당금 진단 서비스, Payout </h3>

- <h5> 1분 내로 간단하게, 배당 포트폴리오 셀프 체크할 수 있어요 </h5>
- <h5> 포트폴리오 밸런스 진단, 섹터별 인사이트를 제공해요 </h5>
- <h5> 월간 / 연간 배당금 체크, 종목별 주요 배당 정보를 알 수 있어요 </h5>
1분 내로 간단하게, 배당 포트폴리오 셀프 체크할 수 있어요 ✅️
포트폴리오 밸런스 진단, 섹터별 인사이트를 제공해요 💡
월간 / 연간 배당금 체크, 종목별 주요 배당 정보를 알 수 있어요 💰


## 🔗 Link
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import lombok.extern.slf4j.Slf4j;
import nexters.payout.apiserver.dividend.application.dto.request.DividendRequest;
import nexters.payout.apiserver.dividend.application.dto.request.TickerShare;
import nexters.payout.apiserver.dividend.application.dto.response.SingleMonthlyDividendResponse;
import nexters.payout.apiserver.dividend.application.dto.response.MonthlyDividendResponse;
import nexters.payout.apiserver.dividend.application.dto.response.SingleMonthlyDividendResponse;
import nexters.payout.apiserver.dividend.application.dto.response.SingleYearlyDividendResponse;
import nexters.payout.apiserver.dividend.application.dto.response.YearlyDividendResponse;
import nexters.payout.core.exception.error.NotFoundException;
import nexters.payout.core.time.InstantProvider;
import nexters.payout.domain.dividend.domain.Dividend;
import nexters.payout.domain.dividend.domain.repository.DividendRepository;
import nexters.payout.domain.stock.domain.Stock;
import nexters.payout.domain.stock.domain.exception.TickerNotFoundException;
import nexters.payout.domain.stock.domain.repository.StockRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -70,7 +70,7 @@ private List<Dividend> getLastYearDividendsByTicker(final String ticker) {

private Stock getStock(final String ticker) {
return stockRepository.findByTicker(ticker)
.orElseThrow(() -> new NotFoundException(String.format("not found ticker [%s]", ticker)));
.orElseThrow(() -> new TickerNotFoundException(ticker));
}

private List<SingleMonthlyDividendResponse> getDividendsOfLastYearAndMonth(
Expand All @@ -80,7 +80,7 @@ private List<SingleMonthlyDividendResponse> getDividendsOfLastYearAndMonth(
.stream()
.flatMap(tickerShare -> stockRepository.findByTicker(tickerShare.ticker())
.map(stock -> getMonthlyDividendResponse(month, tickerShare, stock))
.orElseThrow(() -> new NotFoundException(String.format("not found ticker [%s]", tickerShare.ticker()))))
.orElseThrow(() -> new TickerNotFoundException(tickerShare.ticker())))
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
import nexters.payout.apiserver.stock.application.dto.request.SectorRatioRequest;
import nexters.payout.apiserver.stock.application.dto.request.TickerShare;
import nexters.payout.apiserver.stock.application.dto.response.*;
import nexters.payout.core.exception.error.NotFoundException;
import nexters.payout.core.time.InstantProvider;
import nexters.payout.domain.dividend.domain.Dividend;
import nexters.payout.domain.dividend.domain.repository.DividendRepository;
import nexters.payout.domain.stock.domain.Sector;
import nexters.payout.domain.stock.domain.Stock;
import nexters.payout.domain.stock.domain.exception.TickerNotFoundException;
import nexters.payout.domain.stock.domain.repository.StockRepository;
import nexters.payout.domain.stock.domain.service.StockDividendAnalysisService;
import nexters.payout.domain.stock.domain.service.SectorAnalysisService;
import nexters.payout.domain.stock.domain.service.SectorAnalysisService.SectorInfo;
import nexters.payout.domain.stock.domain.service.SectorAnalysisService.StockShare;
import nexters.payout.domain.stock.domain.service.StockDividendAnalysisService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -76,7 +76,7 @@ private List<Dividend> combinedDividends(final List<Dividend> lastYearDividends,

private Stock getStock(final String ticker) {
return stockRepository.findByTicker(ticker)
.orElseThrow(() -> new NotFoundException(String.format("not found ticker [%s]", ticker)));
.orElseThrow(() -> new TickerNotFoundException(ticker));
}

private List<Dividend> getLastYearDividends(final Stock stock) {
Expand Down
1 change: 1 addition & 0 deletions api-server/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ spring:
hibernate:
format_sql: true
show-sql: false
open-in-view: false

flyway:
enabled: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ public static Integer getThisYear() {
return getNow().getYear();
}

public static Integer getNextYear() {
return getNow().plusYears(1).getYear();
}

public static Integer getLastYear() {
return getNow().minusYears(1).getYear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class QBaseEntity extends EntityPathBase<BaseEntity> {

public final DateTimePath<java.time.Instant> createdAt = createDateTime("createdAt", java.time.Instant.class);

public final ComparablePath<java.util.UUID> id = createComparable("id", java.util.UUID.class);

public final DateTimePath<java.time.Instant> lastModifiedAt = createDateTime("lastModifiedAt", java.time.Instant.class);

public QBaseEntity(String variable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public class QDividend extends EntityPathBase<Dividend> {

public final DateTimePath<java.time.Instant> exDividendDate = createDateTime("exDividendDate", java.time.Instant.class);

public final ComparablePath<java.util.UUID> id = createComparable("id", java.util.UUID.class);
//inherited
public final ComparablePath<java.util.UUID> id = _super.id;

//inherited
public final DateTimePath<java.time.Instant> lastModifiedAt = _super.lastModifiedAt;
Expand Down
17 changes: 17 additions & 0 deletions domain/src/main/java/nexters/payout/domain/BaseEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.persistence.*;
import lombok.Getter;
import nexters.payout.domain.dividend.domain.Dividend;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
Expand All @@ -14,6 +15,9 @@
@EntityListeners(AuditingEntityListener.class)
@Getter
public class BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
private UUID id;

@Column(name = "created_at", updatable = false)
@CreatedDate
Expand All @@ -23,4 +27,17 @@ public class BaseEntity {
@LastModifiedDate
private Instant lastModifiedAt;

public BaseEntity(UUID id) {
this.id = id;
}

@Override
public int hashCode() {
return Objects.hash(id);
}

@Override
public boolean equals(Object obj) {
return obj instanceof BaseEntity && this.id.equals(((BaseEntity) obj).getId());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
package nexters.payout.domain.dividend.domain;

import jakarta.persistence.*;
import lombok.AccessLevel;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import lombok.Getter;
import lombok.NoArgsConstructor;
import nexters.payout.domain.BaseEntity;

import java.time.Instant;
import java.util.Objects;
import java.util.UUID;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Dividend extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.UUID)
private UUID id;

@Column(nullable = false, updatable = false)
private UUID stockId;

Expand All @@ -31,9 +24,13 @@ public class Dividend extends BaseEntity {

private Instant declarationDate;

public Dividend() {
super(null);
}

public Dividend(final UUID id, final UUID stockId, final Double dividend, final Instant exDividendDate,
final Instant paymentDate, final Instant declarationDate) {
this.id = id;
super(id);
this.stockId = stockId;
this.dividend = dividend;
this.exDividendDate = exDividendDate;
Expand All @@ -58,16 +55,6 @@ public static Dividend create(
return new Dividend(stockId, dividend, exDividendDate, paymentDate, declarationDate);
}

@Override
public boolean equals(Object obj) {
return obj instanceof Dividend && this.id.equals(((Dividend) obj).getId());
}

@Override
public int hashCode() {
return Objects.hash(id);
}

@Override
public String toString() {
return "Dividend{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,5 @@
import java.util.UUID;

public interface DividendRepository extends JpaRepository<Dividend, UUID>, DividendRepositoryCustom {

List<Dividend> findAllByStockId(UUID stockId);

List<Dividend> findAllByStockIdIn(List<UUID> stockIds);
}

This file was deleted.

19 changes: 3 additions & 16 deletions domain/src/main/java/nexters/payout/domain/stock/domain/Stock.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Stock extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.UUID)
private UUID id;

@Column(unique = true, nullable = false, length = 50)
private String ticker;

Expand All @@ -37,11 +32,13 @@ public class Stock extends BaseEntity {

private String logoUrl;

public Stock() {super(null);}

public Stock(final UUID id, final String ticker, final String name,
final Sector sector, final String exchange, final String industry,
final Double price, final Integer volume, final String logoUrl) {
super(id);
validateTicker(ticker);
this.id = id;
this.ticker = ticker;
this.name = name;
this.sector = sector;
Expand Down Expand Up @@ -73,16 +70,6 @@ public void update(
this.sector = sector;
}

@Override
public boolean equals(Object obj) {
return obj instanceof Stock && this.id.equals(((Stock) obj).getId());
}

@Override
public int hashCode() {
return Objects.hash(id);
}

@Override
public String toString() {
return "Stock{" +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package nexters.payout.domain.stock.domain.exception;

import nexters.payout.core.exception.error.NotFoundException;

public class TickerNotFoundException extends NotFoundException {

public TickerNotFoundException(String ticker) {
super(String.format("not found ticker [%s]", ticker));
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package nexters.payout.domain.stock.domain.service;

import nexters.payout.domain.common.config.DomainService;
import nexters.payout.domain.dividend.domain.Dividend;
import nexters.payout.domain.stock.domain.Sector;
import nexters.payout.domain.stock.domain.Stock;

Expand All @@ -15,6 +14,9 @@
@DomainService
public class SectorAnalysisService {

/**
* 포트폴리오의 섹터 별 비중을 계산합니다.
*/
public Map<Sector, SectorInfo> calculateSectorRatios(final List<StockShare> stockShares) {
Map<Sector, Integer> sectorCountMap = getSectorCountMap(stockShares);
Map<Sector, List<StockShare>> sectorStockMap = getSectorStockMap(stockShares);
Expand Down Expand Up @@ -73,13 +75,11 @@ public record SectorInfo(
Double ratio,
List<StockShare> stockShares
) {

}

public record StockShare(
Stock stock,
Integer share
) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import java.util.List;

public interface StockRepositoryCustom {

List<Stock> findStocksByTickerOrNameWithPriority(String search, Integer pageNumber, Integer pageSize);

List<StockDividendDto> findUpcomingDividendStock(Sector sector, int pageNumber, int pageSize);

List<StockDividendYieldDto> findBiggestDividendYieldStock(int lastYear, Sector sector, int pageNumber, int pageSize);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@RequiredArgsConstructor
public class StockRepositoryImpl implements StockRepositoryCustom {

private final Double MAX_DIVIDEND_YIELD = 0.9;
private static final Double MAX_DIVIDEND_YIELD = 0.9;
private final JPAQueryFactory queryFactory;

@Override
Expand Down

0 comments on commit 6fba9c6

Please sign in to comment.