diff --git a/server/internal/handlers/plants/create_plant_v1.go b/server/internal/handlers/plants/create_plant_v1.go index 9e50653..6e9558e 100644 --- a/server/internal/handlers/plants/create_plant_v1.go +++ b/server/internal/handlers/plants/create_plant_v1.go @@ -35,6 +35,7 @@ func (h *Handler) CreatePlantV1( Species: req.Species, CreatedAt: time.Now().UTC(), Place: req.Place, + SoldAt: time.Time{}, } err = h.storage.AddPlant(ctx, plant) if err != nil { diff --git a/server/internal/handlers/plants/get_bought_plants_v1.go b/server/internal/handlers/plants/get_bought_plants_v1.go index 1a0b37c..1404fcb 100644 --- a/server/internal/handlers/plants/get_bought_plants_v1.go +++ b/server/internal/handlers/plants/get_bought_plants_v1.go @@ -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) } diff --git a/server/internal/handlers/plants/get_traded_plants_v1.go b/server/internal/handlers/plants/get_traded_plants_v1.go index baac7a2..b075e1f 100644 --- a/server/internal/handlers/plants/get_traded_plants_v1.go +++ b/server/internal/handlers/plants/get_traded_plants_v1.go @@ -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) } diff --git a/server/internal/handlers/plants/service.go b/server/internal/handlers/plants/service.go index 55ee7ec..5acba27 100644 --- a/server/internal/handlers/plants/service.go +++ b/server/internal/handlers/plants/service.go @@ -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 diff --git a/server/internal/storage/plants.go b/server/internal/storage/plants.go index 42b1f2b..9b00a27 100644 --- a/server/internal/storage/plants.go +++ b/server/internal/storage/plants.go @@ -262,11 +262,12 @@ func parseLabelsToBSON(labels map[string]interface{}) bson.D { for k, v := range labels { switch vc := v.(type) { case string: - if k == "species" { - bsonFltr = append(bsonFltr, bson.E{Key: k, Value: bson.M{"$regex": vc, "$options": "i"}}) - } else { - bsonFltr = append(bsonFltr, bson.E{Key: k, Value: vc}) - } + // if k == "species" { + // bsonFltr = append(bsonFltr, bson.E{Key: k, Value: bson.M{"$regex": vc, "$options": "i"}}) + // } else { + // bsonFltr = append(bsonFltr, bson.E{Key: k, Value: vc}) + // } + bsonFltr = append(bsonFltr, bson.E{Key: k, Value: bson.M{"$regex": vc, "$options": "i"}}) case []string: bsonFltr = createOrFilter(k, vc) } diff --git a/server/internal/storage/trades.go b/server/internal/storage/trades.go index bc53807..fa3d3e3 100644 --- a/server/internal/storage/trades.go +++ b/server/internal/storage/trades.go @@ -186,7 +186,7 @@ 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 @@ -194,7 +194,7 @@ func (s *Storage) GetTradesByIds(ctx context.Context, ids []primitive.ObjectID, 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