Skip to content

Commit

Permalink
Merge pull request #58 from moevm/back-fix-5
Browse files Browse the repository at this point in the history
Corrected mistales and bugs
  • Loading branch information
AnjeZenda authored Dec 5, 2024
2 parents 9c4ade5 + c54f1f4 commit 64bbc9a
Show file tree
Hide file tree
Showing 8 changed files with 432 additions and 449 deletions.
4 changes: 1 addition & 3 deletions server/api/plants/v1/plants.proto
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ service PlantsAPI {

rpc GetPlantsV1 (GetPlantsV1Request) returns (GetPlantsV1Response) {
option (google.api.http) = {
post: "/api/palnts/{page}/{size}/{sort}"
post: "/api/plants/{page}/{size}/{sort}"
body: "*"
};
};
Expand Down Expand Up @@ -113,8 +113,6 @@ message CreatePlantV1Request {
string description = 9;
string type = 10;
string species = 11;
string careRules = 12;
google.protobuf.Timestamp createdAt = 13;
string userId = 14;
}

Expand Down
111 changes: 52 additions & 59 deletions server/gen/docs/plants/v1/plants.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,58 +124,6 @@
]
}
},
"/api/palnts/{page}/{size}/{sort}": {
"post": {
"operationId": "PlantsAPI_GetPlantsV1",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/v1GetPlantsV1Response"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "page",
"in": "path",
"required": true,
"type": "string",
"format": "int64"
},
{
"name": "size",
"in": "path",
"required": true,
"type": "string",
"format": "int64"
},
{
"name": "sort",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/PlantsAPIGetPlantsV1Body"
}
}
],
"tags": [
"PlantsAPI"
]
}
},
"/api/plants/active/{userId}": {
"get": {
"operationId": "PlantsAPI_GetActivePlantsV1",
Expand Down Expand Up @@ -433,6 +381,58 @@
"PlantsAPI"
]
}
},
"/api/plants/{page}/{size}/{sort}": {
"post": {
"operationId": "PlantsAPI_GetPlantsV1",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/v1GetPlantsV1Response"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "page",
"in": "path",
"required": true,
"type": "string",
"format": "int64"
},
{
"name": "size",
"in": "path",
"required": true,
"type": "string",
"format": "int64"
},
{
"name": "sort",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/PlantsAPIGetPlantsV1Body"
}
}
],
"tags": [
"PlantsAPI"
]
}
}
},
"definitions": {
Expand Down Expand Up @@ -676,13 +676,6 @@
"species": {
"type": "string"
},
"careRules": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time"
},
"userId": {
"type": "string"
}
Expand Down
9 changes: 7 additions & 2 deletions server/internal/handlers/plants/create_plant_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (h *Handler) CreatePlantV1(
if err != nil {
return nil, status.Error(codes.InvalidArgument, "invalid user id")
}
err = h.storage.AddPlant(ctx, &models.Plant{
plant := &models.Plant{
ID: primitive.NewObjectID(),
UserID: userId,
Image: req.Image,
Expand All @@ -35,9 +35,14 @@ func (h *Handler) CreatePlantV1(
Species: req.Species,
CreatedAt: time.Now().UTC(),
Place: req.Place,
})
}
err = h.storage.AddPlant(ctx, plant)
if err != nil {
return nil, status.Error(codes.Internal, "could not create plant")
}
err = h.storage.AddPlantToUser(ctx, plant)
if err != nil {
return nil, status.Error(codes.Internal, "could not add plants to user")
}
return &api.CreatePlantV1Response{}, nil
}
2 changes: 1 addition & 1 deletion server/internal/handlers/plants/get_care_rule_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func (h *Handler) GetCareRuleV1(
ctx context.Context,
req *api.GetCareRuleV1Request,
) (*api.GetCareRuleV1Response, error) {
rules, err := h.storage.GetCareRulesForPlant(ctx, req.Species)
rules, err := h.storage.GetCareRulesForPlant(ctx, req.Id)
if err != nil {
return nil, status.Error(codes.Internal, "cant get plant")
}
Expand Down
1 change: 1 addition & 0 deletions server/internal/handlers/plants/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Storage interface {
GetPlantsByIds(ctx context.Context, ids []string, fltr *models.Filter) ([]*models.Plant, error)
AddTradeToUser(ctx context.Context, userId, tradeId primitive.ObjectID) error
GetPlantsByUserId(ctx context.Context, userId string, isSold bool) ([]*models.Plant, error)
AddPlantToUser(ctx context.Context, plant *models.Plant) error
}

type Handler struct {
Expand Down
Loading

0 comments on commit 64bbc9a

Please sign in to comment.