Skip to content

Commit

Permalink
Merge pull request Sylius#8772 from paulstoica/product-reviews-api
Browse files Browse the repository at this point in the history
Product reviews API
  • Loading branch information
pamil authored Jan 5, 2018
2 parents 96f560a + 7224308 commit 4c7877e
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 0 deletions.
1 change: 1 addition & 0 deletions Resources/config/app/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ imports:
- { resource: "@SyliusAdminApiBundle/Resources/config/grids/cart.yml" }
- { resource: "@SyliusAdminApiBundle/Resources/config/grids/payments.yml" }
- { resource: "@SyliusAdminApiBundle/Resources/config/grids/product.yml" }
- { resource: "@SyliusAdminApiBundle/Resources/config/grids/product_review.yml" }
- { resource: "@SyliusAdminApiBundle/Resources/config/grids/product_variant.yml" }
- { resource: "@SyliusAdminApiBundle/Resources/config/grids/promotion.yml" }
- { resource: "@SyliusAdminApiBundle/Resources/config/grids/shipments.yml" }
Expand Down
44 changes: 44 additions & 0 deletions Resources/config/grids/product_review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This file is part of the Sylius package.
# (c) Paweł Jędrzejewski

sylius_grid:
grids:
sylius_admin_api_product_review:
driver:
name: doctrine/orm
options:
class: "%sylius.model.product_review.class%"
repository:
method: createQueryBuilderByProductCode
arguments: ["%locale%", $productCode]
sorting:
date: desc
fields:
date:
type: datetime
label: sylius.ui.date
path: createdAt
sortable: createdAt
options:
format: d-m-Y H:i:s
title:
type: string
label: sylius.ui.title
sortable: ~
rating:
type: string
label: sylius.ui.rating
sortable: ~
status:
type: twig
label: sylius.ui.status
reviewSubject:
type: string
label: sylius.ui.product
author:
type: string
label: sylius.ui.customer
filters:
title:
type: string
label: sylius.ui.title
4 changes: 4 additions & 0 deletions Resources/config/routing/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ sylius_api_product_association_type:
sylius_api_product_option:
resource: "@SyliusAdminApiBundle/Resources/config/routing/product_option.yml"

sylius_api_product_review:
resource: "@SyliusAdminApiBundle/Resources/config/routing/product_review.yml"
prefix: /products/{productCode}

sylius_api_product_taxon_position:
resource: "@SyliusAdminApiBundle/Resources/config/routing/product_taxon_position.yml"

Expand Down
90 changes: 90 additions & 0 deletions Resources/config/routing/product_review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# This file is part of the Sylius package.
# (c) Paweł Jędrzejewski

sylius_admin_api_product_review:
resource: |
path: 'reviews'
grid: sylius_admin_api_product_review
alias: sylius.product_review
section: admin_api
only: ['index']
serialization_version: $version
vars:
route:
parameters:
productCode: $productCode
type: sylius.resource_api

sylius_admin_api_product_review_create:
path: /reviews/
methods: [POST]
defaults:
_controller: sylius.controller.product_review:createAction
_sylius:
serialization_groups: [Default, Detailed]
serialization_version: $version
section: admin_api
form: Sylius\Bundle\CoreBundle\Form\Type\Product\ProductReviewType
factory:
method: createForSubject
arguments:
- expr:notFoundOnNull(service('sylius.repository.product').findOneByCode($productCode))

sylius_admin_api_product_review_update:
path: /reviews/{id}
methods: [PUT, PATCH]
defaults:
_controller: sylius.controller.product_review:updateAction
_sylius:
serialization_version: $version
section: admin_api
form: Sylius\Bundle\CoreBundle\Form\Type\Product\ProductReviewType
repository:
method: findOneByIdAndProductCode
arguments: [$id, $productCode]

sylius_admin_api_product_review_delete:
path: /reviews/{id}
methods: [DELETE]
defaults:
_controller: sylius.controller.product_review:deleteAction
_sylius:
serialization_version: $version
section: admin_api
repository:
method: findOneByIdAndProductCode
arguments: [$id, $productCode]
csrf_protection: false

sylius_admin_api_product_review_show:
path: /reviews/{code}
methods: [GET]
defaults:
_controller: sylius.controller.product_review:showAction
_sylius:
serialization_version: $version
section: admin_api
serialization_groups: [Default, Detailed]
repository:
method: findOneByIdAndProductCode
arguments: [$code, $productCode]

sylius_admin_api_product_review_accept:
path: /reviews/{id}/accept
methods: [POST, PUT, PATCH]
defaults:
_controller: sylius.controller.product_review:applyStateMachineTransitionAction
_sylius:
state_machine:
graph: sylius_product_review
transition: accept

sylius_admin_api_product_review_reject:
path: /reviews/{id}/reject
methods: [POST, PUT, PATCH]
defaults:
_controller: sylius.controller.product_review:applyStateMachineTransitionAction
_sylius:
state_machine:
graph: sylius_product_review
transition: reject

0 comments on commit 4c7877e

Please sign in to comment.