mirror of
https://github.com/3ybactuk/marketplace-go-service-project.git
synced 2025-12-21 18:28:59 +03:00
[hw-5] concurrency, graceful shutdown, concurrent tests
This commit is contained in:
@@ -27,7 +27,7 @@ func NewStockRepository(write, read *pgxpool.Pool) service.StockRepository {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *stockRepo) GetQuerier(ctx context.Context) *Queries {
|
||||
func (s *stockRepo) GetWriter(ctx context.Context) *Queries {
|
||||
tx, ok := postgres.TxFromCtx(ctx)
|
||||
if ok {
|
||||
return New(tx)
|
||||
@@ -36,8 +36,17 @@ func (s *stockRepo) GetQuerier(ctx context.Context) *Queries {
|
||||
return New(s.write)
|
||||
}
|
||||
|
||||
func (s *stockRepo) GetReader(ctx context.Context) *Queries {
|
||||
tx, ok := postgres.TxFromCtx(ctx)
|
||||
if ok {
|
||||
return New(tx)
|
||||
}
|
||||
|
||||
return New(s.read)
|
||||
}
|
||||
|
||||
func (s *stockRepo) StockReserve(ctx context.Context, stock *entity.Stock) error {
|
||||
querier := s.GetQuerier(ctx)
|
||||
querier := s.GetWriter(ctx)
|
||||
|
||||
rows, err := querier.StockReserve(ctx, &StockReserveParams{
|
||||
Sku: int64(stock.Item.ID),
|
||||
@@ -55,7 +64,7 @@ func (s *stockRepo) StockReserve(ctx context.Context, stock *entity.Stock) error
|
||||
}
|
||||
|
||||
func (s *stockRepo) StockReserveRemove(ctx context.Context, stock *entity.Stock) error {
|
||||
querier := s.GetQuerier(ctx)
|
||||
querier := s.GetWriter(ctx)
|
||||
|
||||
rows, err := querier.StockReserveRemove(ctx, &StockReserveRemoveParams{
|
||||
Sku: int64(stock.Item.ID),
|
||||
@@ -81,7 +90,7 @@ func (s *stockRepo) StockReserveRemove(ctx context.Context, stock *entity.Stock)
|
||||
}
|
||||
|
||||
func (s *stockRepo) StockCancel(ctx context.Context, stock *entity.Stock) error {
|
||||
querier := s.GetQuerier(ctx)
|
||||
querier := s.GetWriter(ctx)
|
||||
|
||||
rows, err := querier.StockCancel(ctx, &StockCancelParams{
|
||||
Sku: int64(stock.Item.ID),
|
||||
@@ -107,7 +116,7 @@ func (s *stockRepo) StockCancel(ctx context.Context, stock *entity.Stock) error
|
||||
}
|
||||
|
||||
func (s *stockRepo) StockGetByID(ctx context.Context, sku entity.Sku) (*entity.Stock, error) {
|
||||
querier := s.GetQuerier(ctx)
|
||||
querier := s.GetReader(ctx)
|
||||
|
||||
stock, err := querier.StockGetByID(ctx, int64(sku))
|
||||
switch {
|
||||
|
||||
Reference in New Issue
Block a user