-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from ThomasDaSilva/main
CS Fixer + fix import/export API + Add site and product rating + route
- Loading branch information
Showing
19 changed files
with
322 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
SET FOREIGN_KEY_CHECKS = 0; | ||
|
||
-- --------------------------------------------------------------------- | ||
-- guaranteed_opinion_product_rating | ||
-- --------------------------------------------------------------------- | ||
|
||
DROP TABLE IF EXISTS `guaranteed_opinion_product_rating`; | ||
|
||
CREATE TABLE `guaranteed_opinion_product_rating` | ||
( | ||
`product_id` INTEGER NOT NULL, | ||
`total` INTEGER, | ||
`average` VARCHAR(255), | ||
PRIMARY KEY (`product_id`) | ||
) ENGINE=InnoDB; | ||
|
||
# This restores the fkey checks, after having unset them earlier | ||
SET FOREIGN_KEY_CHECKS = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace GuaranteedOpinion\Controller; | ||
|
||
use GuaranteedOpinion\GuaranteedOpinion; | ||
use GuaranteedOpinion\Model\GuaranteedOpinionProductRatingQuery; | ||
use GuaranteedOpinion\Model\GuaranteedOpinionProductReviewQuery; | ||
use GuaranteedOpinion\Model\GuaranteedOpinionSiteReviewQuery; | ||
use Propel\Runtime\Exception\PropelException; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
use Thelia\Controller\Front\BaseFrontController; | ||
use Thelia\Core\HttpFoundation\JsonResponse; | ||
|
||
#[Route(path: "/guaranteed_opinion", name: "guaranteed_opinion")] | ||
class FrontController extends BaseFrontController | ||
{ | ||
/** | ||
* @throws PropelException | ||
*/ | ||
#[Route(path: "/site_reviews/offset/{offset}/limit/{limit}", name: "site_reviews", methods: "GET")] | ||
public function siteReviews(int $offset, int $limit): JsonResponse | ||
{ | ||
$reviews = []; | ||
|
||
$siteReviews = GuaranteedOpinionSiteReviewQuery::create() | ||
->setLimit($limit) | ||
->setOffset($limit * ($offset -1)) | ||
->find() | ||
; | ||
|
||
foreach ($siteReviews as $review) { | ||
$reviews[] = [ | ||
'rate' => $review->getRate(), | ||
'name' => $review->getName(), | ||
'date' => $review->getReviewDate()?->format('Y-m-d'), | ||
'message' => $review->getReview() | ||
]; | ||
} | ||
|
||
return new JsonResponse([ | ||
'total' => GuaranteedOpinion::getConfigValue(GuaranteedOpinion::SITE_RATING_TOTAL_CONFIG_KEY), | ||
'average' => GuaranteedOpinion::getConfigValue(GuaranteedOpinion::SITE_RATING_AVERAGE_CONFIG_KEY), | ||
'reviews' => $reviews | ||
]); | ||
} | ||
|
||
/** | ||
* @throws PropelException | ||
*/ | ||
#[Route(path: "/product_reviews/{id}/offset/{offset}/limit/{limit}", name: "product_reviews", methods: "GET")] | ||
public function productReviews(int $id, int $offset, int $limit): JsonResponse | ||
{ | ||
$reviews = []; | ||
|
||
$productRating = GuaranteedOpinionProductRatingQuery::create() | ||
->findOneByProductId($id); | ||
|
||
$productReviews = GuaranteedOpinionProductReviewQuery::create() | ||
->filterByProductId($id) | ||
->setLimit($limit) | ||
->setOffset($limit * ($offset -1)) | ||
->find(); | ||
|
||
foreach ($productReviews as $review) { | ||
$reviews[] = [ | ||
'rate' => $review->getRate(), | ||
'name' => $review->getName(), | ||
'date' => $review->getReviewDate()?->format('Y-m-d'), | ||
'message' => $review->getReview() | ||
]; | ||
} | ||
|
||
return new JsonResponse([ | ||
'total' => $productRating?->getTotal(), | ||
'average' => $productRating?->getAverage(), | ||
'reviews' => $reviews | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.