Skip to content

Commit

Permalink
refactor: add more queries for stake concentration
Browse files Browse the repository at this point in the history
  • Loading branch information
samwang0723 committed Jul 7, 2024
1 parent b2b9dfa commit de5d7db
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
9 changes: 9 additions & 0 deletions database/sqlc/queries/stake_concentration.sql
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,12 @@ WHERE a.stock_id = $1 AND a.exchange_date <= $2
ORDER BY a.exchange_date DESC
LIMIT 60;

-- name: HasStakeConcentration :one
SELECT EXISTS (
SELECT 1 FROM stake_concentration
WHERE exchange_date = $1
);

-- name: GetStakeConcentrationLatestDataPoint :one
SELECT exchange_date FROM stake_concentration
ORDER BY exchange_date DESC LIMIT 1;
10 changes: 10 additions & 0 deletions internal/app/adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type Adapter interface {
ctx context.Context,
stockID, date string,
) ([]*domain.CalculationBase, error)
HasStakeConcentration(ctx context.Context, exchangeDate string) (bool, error)
GetStakeConcentrationLatestDataPoint(ctx context.Context) (string, error)
CreatePickedStock(ctx context.Context, userID uuid.UUID, stockID string) error
DeletePickedStock(ctx context.Context, userID uuid.UUID, stockID string) error
ListPickedStocks(ctx context.Context, userID uuid.UUID) (*[]domain.PickedStock, error)
Expand Down Expand Up @@ -140,6 +142,14 @@ func (a *Imp) GetStakeConcentrationsWithVolumes(
return a.repo.GetStakeConcentrationsWithVolumes(ctx, stockID, date)
}

func (a *Imp) HasStakeConcentration(ctx context.Context, exchangeDate string) (bool, error) {
return a.repo.HasStakeConcentration(ctx, exchangeDate)
}

func (a *Imp) GetStakeConcentrationLatestDataPoint(ctx context.Context) (string, error) {
return a.repo.GetStakeConcentrationLatestDataPoint(ctx)
}

func (a *Imp) CreatePickedStock(
ctx context.Context,
userID uuid.UUID,
Expand Down
14 changes: 14 additions & 0 deletions internal/app/adapter/sqlc/stake_concentration.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ func (repo *Repo) GetStakeConcentrationsWithVolumes(
return toDomainCalculationBaseList(result), nil
}

func (repo *Repo) HasStakeConcentration(ctx context.Context, exchangeDate string) (bool, error) {
return repo.primary().HasStakeConcentration(ctx, exchangeDate)
}

func (repo *Repo) GetStakeConcentrationLatestDataPoint(
ctx context.Context,
) (string, error) {
exchangeDate, err := repo.primary().GetStakeConcentrationLatestDataPoint(ctx)
if err != nil {
return "", err
}
return exchangeDate, nil
}

func toSqlcBatchUpsertStakeConcentrationParams(
stakeConcentrations []*domain.StakeConcentration,
) *sqlcdb.BatchUpsertStakeConcentrationParams {
Expand Down
26 changes: 26 additions & 0 deletions internal/db/main/sqlc/stake_concentration.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit de5d7db

Please sign in to comment.