Skip to content

Commit

Permalink
Merge pull request #59 from moevm/back-fix-6
Browse files Browse the repository at this point in the history
Back fix 6
  • Loading branch information
AnjeZenda authored Dec 5, 2024
2 parents 64bbc9a + 9779b1e commit 210c614
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions server/internal/handlers/plants/create_plant_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
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
11 changes: 6 additions & 5 deletions server/internal/storage/plants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
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 210c614

Please sign in to comment.