Skip to content

Commit

Permalink
Merge pull request #69 from moevm/back-addition-1
Browse files Browse the repository at this point in the history
Added searching by description
  • Loading branch information
AnjeZenda authored Dec 12, 2024
2 parents 53d0a97 + b8a44d8 commit 39b7e8f
Show file tree
Hide file tree
Showing 13 changed files with 309 additions and 288 deletions.
1 change: 1 addition & 0 deletions server/api/plants/v1/plants.proto
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ message GetPlantsWithCareRulesV1Request {
string type = 2;
repeated string lightCondition = 3;
repeated string temperatureRegime = 4;
string description = 5;
}
Filter filter = 1;
int64 page = 2;
Expand Down
14 changes: 2 additions & 12 deletions server/gen/docs/data/v1/data.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,9 @@
"operationId": "DataAPI_ExportDBV1",
"responses": {
"200": {
"description": "A successful response.(streaming responses)",
"description": "A successful response.",
"schema": {
"type": "object",
"properties": {
"result": {
"$ref": "#/definitions/v1ExportDBV1Response"
},
"error": {
"$ref": "#/definitions/rpcStatus"
}
},
"title": "Stream result of v1ExportDBV1Response"
"$ref": "#/definitions/v1ExportDBV1Response"
}
},
"default": {
Expand Down Expand Up @@ -65,7 +56,6 @@
"parameters": [
{
"name": "body",
"description": " (streaming inputs)",
"in": "body",
"required": true,
"schema": {
Expand Down
9 changes: 9 additions & 0 deletions server/gen/docs/plants/v1/plants.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,12 @@
"createdAt": {
"type": "string",
"format": "date-time"
},
"id": {
"type": "string"
},
"image": {
"type": "string"
}
}
},
Expand Down Expand Up @@ -871,6 +877,9 @@
"items": {
"type": "string"
}
},
"description": {
"type": "string"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func (h *Handler) GetPlantsWithCareRulesV1(
if len(req.Filter.TemperatureRegime) != 0 {
filter.Labels["temperature_regime"] = req.Filter.TemperatureRegime
}
if req.Filter.Description != "" {
filter.Labels["description"] = req.Filter.Description
}
rules, count, err := h.storage.GetPlantsWithCareRules(ctx, filter)
if err != nil {
return nil, status.Error(codes.Internal, "internal error occured")
Expand Down
4 changes: 2 additions & 2 deletions server/internal/pkg/pb/data/v1/data.pb.go

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

2 changes: 1 addition & 1 deletion server/internal/pkg/pb/data/v1/data_grpc.pb.go

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

516 changes: 263 additions & 253 deletions server/internal/pkg/pb/plants/v1/plants.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion server/internal/pkg/pb/plants/v1/plants_grpc.pb.go

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

4 changes: 2 additions & 2 deletions server/internal/pkg/pb/trades/v1/trades.pb.go

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

2 changes: 1 addition & 1 deletion server/internal/pkg/pb/trades/v1/trades_grpc.pb.go

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

28 changes: 14 additions & 14 deletions server/internal/pkg/pb/users/v1/users.pb.go

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

2 changes: 1 addition & 1 deletion server/internal/pkg/pb/users/v1/users_grpc.pb.go

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

10 changes: 9 additions & 1 deletion server/internal/storage/plants.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ type valsType interface {

func (s *Storage) GetPlantsWithCareRules(ctx context.Context, fltr *models.Filter) ([]*models.CareRules, int64, error) {
collection := s.DataBase.Collection("care_rules")
filter := parseLabelsToBSON(fltr.Labels)
filter := primitive.D{}
if v, ok := fltr.Labels["description"]; ok {
filter = append(filter, bson.E{
Key: "description", Value: bson.M{"$elemMatch": bson.M{"description_addition": bson.M{"$regex": v, "$options": "i"}}},
},
)
delete(fltr.Labels, "description")
}
filter = append(filter, parseLabelsToBSON(fltr.Labels)...)
opts := options.Find()
opts.SetLimit(fltr.Size)
opts.SetSkip((fltr.Page - 1) * fltr.Size)
Expand Down

0 comments on commit 39b7e8f

Please sign in to comment.