Skip to content

Commit

Permalink
corrected trades with status 2
Browse files Browse the repository at this point in the history
  • Loading branch information
AnjeZenda committed Dec 5, 2024
1 parent 4b2c5f5 commit 4534b37
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion server/internal/handlers/plants/get_bought_plants_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (h *Handler) GetBoughtPlantsV1(
if err != nil {
return nil, status.Errorf(codes.Internal, "cannot get users trades %v", err)
}
trades, err := h.storage.GetTradesByIds(ctx, tradeIds, "buy")
trades, err := h.storage.GetTradesByIds(ctx, tradeIds, "buy", 2)
if err != nil {
return nil, status.Errorf(codes.Internal, "cannot get trades %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion server/internal/handlers/plants/get_traded_plants_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (h *Handler) GetTradedPlantsV1(
if err != nil {
return nil, status.Errorf(codes.Internal, "cannot get users trades %v", err)
}
trades, err := h.storage.GetTradesByIds(ctx, tradeIds, "trade")
trades, err := h.storage.GetTradesByIds(ctx, tradeIds, "trade", 2)
if err != nil {
return nil, status.Errorf(codes.Internal, "cannot get trades %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion server/internal/handlers/plants/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Storage interface {
CreateBuyTrade(ctx context.Context, trade *models.Trade) error
DeletePlantFromUser(ctx context.Context, userId, plantId string) error
SoldPlant(ctx context.Context, id string) error
GetTradesByIds(ctx context.Context, ids []primitive.ObjectID, tradeType string) ([]*models.Trade, error)
GetTradesByIds(ctx context.Context, ids []primitive.ObjectID, tradeType string, tradeStatus int8) ([]*models.Trade, error)
GetUserTrades(ctx context.Context, id string) ([]primitive.ObjectID, error)
GetPlantsByIds(ctx context.Context, ids []string, fltr *models.Filter) ([]*models.Plant, error)
AddTradeToUser(ctx context.Context, userId, tradeId primitive.ObjectID) error
Expand Down
4 changes: 2 additions & 2 deletions server/internal/storage/trades.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,15 @@ func (s *Storage) UpdateTrade(ctx context.Context,
return nil
}

func (s *Storage) GetTradesByIds(ctx context.Context, ids []primitive.ObjectID, tradeType string) ([]*models.Trade, error) {
func (s *Storage) GetTradesByIds(ctx context.Context, ids []primitive.ObjectID, tradeType string, tradeStatus int8) ([]*models.Trade, error) {
var (
trades []*models.Trade
fltr bson.D
)
collection := s.DataBase.Collection("trades")
orFltr := createOrFilter("_id", ids)
fltr = append(fltr, orFltr...)
fltr = append(fltr, bson.E{Key: "type", Value: tradeType})
fltr = append(fltr, bson.E{Key: "type", Value: tradeType}, bson.E{Key: "status", Value: tradeStatus})
cur, err := collection.Find(ctx, fltr)
if err != nil {
return nil, err
Expand Down

0 comments on commit 4534b37

Please sign in to comment.