@eui/cli 15.4.0 → 15.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.version.properties +1 -1
- package/LICENSE +296 -296
- package/README.md +26 -26
- package/bin/eui-cli.js +70 -70
- package/lib/build.js +153 -153
- package/lib/cli.js +111 -111
- package/lib/config.js +54 -54
- package/lib/generators.js +64 -64
- package/lib/install.js +54 -54
- package/lib/maven-build/build.xml +115 -115
- package/lib/maven-build/pom.xml +64 -64
- package/lib/post-build.js +33 -33
- package/lib/skeletons/_angular/base/.browserslistrc +16 -16
- package/lib/skeletons/_angular/base/.editorconfig +16 -16
- package/lib/skeletons/_angular/base/.euirc.json +8 -8
- package/lib/skeletons/_angular/base/.stylelintrc +24 -24
- package/lib/skeletons/_angular/base/README.md +26 -26
- package/lib/skeletons/_angular/base/angular.json +176 -175
- package/lib/skeletons/_angular/base/gitignore_TO_REPLACE +50 -50
- package/lib/skeletons/_angular/base/mock/app/models/user.js +8 -8
- package/lib/skeletons/_angular/base/mock/app/routes/index.js +5 -5
- package/lib/skeletons/_angular/base/mock/app/routes/user_routes.js +24 -24
- package/lib/skeletons/_angular/base/mock/db/db.json +12 -12
- package/lib/skeletons/_angular/base/mock/server.js +21 -21
- package/lib/skeletons/_angular/base/package.json +24 -24
- package/lib/skeletons/_angular/base/proxy-mock.conf.json +6 -6
- package/lib/skeletons/_angular/base/proxy.conf.json +6 -6
- package/lib/skeletons/_angular/base/src/.eslintrc.json +118 -118
- package/lib/skeletons/_angular/base/src/app/app-routing.module.ts +17 -17
- package/lib/skeletons/_angular/base/src/app/app-starter.service.ts +66 -66
- package/lib/skeletons/_angular/base/src/app/app.component.html +29 -29
- package/lib/skeletons/_angular/base/src/app/app.component.ts +51 -51
- package/lib/skeletons/_angular/base/src/app/app.module.ts +35 -35
- package/lib/skeletons/_angular/base/src/app/core/core.module.ts +87 -87
- package/lib/skeletons/_angular/base/src/app/core/reducers/index.ts +31 -31
- package/lib/skeletons/_angular/base/src/app/features/home/home-routing.module.ts +15 -15
- package/lib/skeletons/_angular/base/src/app/features/home/home.component.html +39 -39
- package/lib/skeletons/_angular/base/src/app/features/home/home.component.ts +11 -11
- package/lib/skeletons/_angular/base/src/app/features/home/home.module.ts +18 -18
- package/lib/skeletons/_angular/base/src/app/features/module1/components/page1/page1.component.html +7 -7
- package/lib/skeletons/_angular/base/src/app/features/module1/components/page1/page1.component.ts +7 -7
- package/lib/skeletons/_angular/base/src/app/features/module1/components/page2/page2.component.html +7 -7
- package/lib/skeletons/_angular/base/src/app/features/module1/components/page2/page2.component.ts +7 -7
- package/lib/skeletons/_angular/base/src/app/features/module1/module1-routing.module.ts +18 -18
- package/lib/skeletons/_angular/base/src/app/features/module1/module1.component.html +7 -7
- package/lib/skeletons/_angular/base/src/app/features/module1/module1.component.ts +8 -8
- package/lib/skeletons/_angular/base/src/app/features/module1/module1.module.ts +21 -21
- package/lib/skeletons/_angular/base/src/app/features/module2/module2-routing.module.ts +16 -16
- package/lib/skeletons/_angular/base/src/app/features/module2/module2.component.html +7 -7
- package/lib/skeletons/_angular/base/src/app/features/module2/module2.component.ts +7 -7
- package/lib/skeletons/_angular/base/src/app/features/module2/module2.module.ts +17 -17
- package/lib/skeletons/_angular/base/src/app/shared/shared.module.ts +45 -45
- package/lib/skeletons/_angular/base/src/app/shared/testing/router.mock.ts +18 -18
- package/lib/skeletons/_angular/base/src/assets/config/env-json-config-dev.json +8 -8
- package/lib/skeletons/_angular/base/src/assets/config/env-json-config-prod.json +8 -8
- package/lib/skeletons/_angular/base/src/assets/config/env-json-config.json +7 -7
- package/lib/skeletons/_angular/base/src/assets/i18n/en.json +6 -6
- package/lib/skeletons/_angular/base/src/assets/i18n/fr.json +6 -6
- package/lib/skeletons/_angular/base/src/config/global.ts +20 -20
- package/lib/skeletons/_angular/base/src/config/index.ts +8 -8
- package/lib/skeletons/_angular/base/src/config/modules.ts +7 -7
- package/lib/skeletons/_angular/base/src/dummy.spec.ts +6 -6
- package/lib/skeletons/_angular/base/src/environments/environment.prod.ts +11 -11
- package/lib/skeletons/_angular/base/src/environments/environment.ts +11 -11
- package/lib/skeletons/_angular/base/src/index.html +21 -21
- package/lib/skeletons/_angular/base/src/karma.conf.js +7 -7
- package/lib/skeletons/_angular/base/src/main.ts +14 -14
- package/lib/skeletons/_angular/base/src/polyfills.ts +89 -89
- package/lib/skeletons/_angular/base/src/styles.scss +1 -1
- package/lib/skeletons/_angular/base/src/tsconfig.app.json +18 -18
- package/lib/skeletons/_angular/base/src/tsconfig.spec.json +14 -14
- package/lib/skeletons/_angular/base/tsconfig.json +27 -27
- package/lib/skeletons/_angular/base-mobile/angular.json +160 -160
- package/lib/skeletons/_angular/base-mobile/ionic.config.json +5 -5
- package/lib/skeletons/_angular/base-mobile/ngsw-config.json +33 -33
- package/lib/skeletons/_angular/base-mobile/package.json +28 -28
- package/lib/skeletons/_angular/base-mobile/src/app/app-routing.module.ts +17 -17
- package/lib/skeletons/_angular/base-mobile/src/app/app-starter.service.ts +73 -73
- package/lib/skeletons/_angular/base-mobile/src/app/app.component.html +27 -27
- package/lib/skeletons/_angular/base-mobile/src/app/app.component.ts +55 -55
- package/lib/skeletons/_angular/base-mobile/src/app/app.module.ts +44 -44
- package/lib/skeletons/_angular/base-mobile/src/app/core/core.module.ts +89 -89
- package/lib/skeletons/_angular/base-mobile/src/app/core/reducers/index.ts +31 -31
- package/lib/skeletons/_angular/base-mobile/src/app/features/home/home-routing.module.ts +15 -15
- package/lib/skeletons/_angular/base-mobile/src/app/features/home/home.component.html +14 -14
- package/lib/skeletons/_angular/base-mobile/src/app/features/home/home.component.ts +11 -11
- package/lib/skeletons/_angular/base-mobile/src/app/features/home/home.module.ts +18 -18
- package/lib/skeletons/_angular/base-mobile/src/app/features/module1/components/page1/page1.component.html +11 -11
- package/lib/skeletons/_angular/base-mobile/src/app/features/module1/components/page1/page1.component.ts +7 -7
- package/lib/skeletons/_angular/base-mobile/src/app/features/module1/components/page2/page2.component.html +11 -11
- package/lib/skeletons/_angular/base-mobile/src/app/features/module1/components/page2/page2.component.ts +7 -7
- package/lib/skeletons/_angular/base-mobile/src/app/features/module1/module1-routing.module.ts +18 -18
- package/lib/skeletons/_angular/base-mobile/src/app/features/module1/module1.component.html +15 -15
- package/lib/skeletons/_angular/base-mobile/src/app/features/module1/module1.component.ts +17 -17
- package/lib/skeletons/_angular/base-mobile/src/app/features/module1/module1.module.ts +21 -21
- package/lib/skeletons/_angular/base-mobile/src/app/features/module2/module2-routing.module.ts +16 -16
- package/lib/skeletons/_angular/base-mobile/src/app/features/module2/module2.component.html +11 -11
- package/lib/skeletons/_angular/base-mobile/src/app/features/module2/module2.component.ts +7 -7
- package/lib/skeletons/_angular/base-mobile/src/app/features/module2/module2.module.ts +17 -17
- package/lib/skeletons/_angular/base-mobile/src/app/shared/shared.module.ts +16 -16
- package/lib/skeletons/_angular/base-mobile/src/app/shared/testing/router.mock.ts +18 -18
- package/lib/skeletons/_angular/base-mobile/src/index.html +27 -27
- package/lib/skeletons/_angular/base-mobile/src/manifest.webmanifest +51 -51
- package/lib/skeletons/_angular/base-mobile/src/tsconfig.app.json +19 -19
- package/lib/skeletons/_angular/options/ecl/angular.json +193 -193
- package/lib/skeletons/_angular/options/ecl/src/app/app.component.html +262 -262
- package/lib/skeletons/_angular/options/ecl/src/app/app.component.ts +59 -59
- package/lib/skeletons/_angular/options/ecl/src/app/features/home/home.component.html +70 -70
- package/lib/skeletons/_angular/options/ecl/src/app/features/module1/components/page1/page1.component.html +1 -1
- package/lib/skeletons/_angular/options/ecl/src/app/features/module1/components/page2/page2.component.html +1 -1
- package/lib/skeletons/_angular/options/ecl/src/app/features/module1/module1.component.html +1 -1
- package/lib/skeletons/_angular/options/ecl/src/app/features/module2/module2.component.html +1 -1
- package/lib/skeletons/_angular/options/ecl/src/app/shared/shared.module.ts +19 -19
- package/lib/skeletons/_angular/options/ecl/src/config/global.ts +20 -20
- package/lib/skeletons/_angular/options/openid-jwt/package.json +22 -22
- package/lib/skeletons/_angular/options/openid-jwt/src/app/core/core.module.ts +94 -94
- package/lib/skeletons/_angular/options/openid-jwt/src/assets/config/env-json-config-dev.json +24 -24
- package/lib/skeletons/_angular/options/openid-jwt/src/assets/config/env-json-config-local-mock.json +10 -10
- package/lib/skeletons/_angular/options/openid-jwt/src/assets/config/env-json-config-local.json +23 -23
- package/lib/skeletons/_angular/options/openid-jwt/src/assets/config/env-json-config-prod.json +23 -23
- package/lib/skeletons/_angular/options/openid-jwt/src/assets/config/env-json-config.json +10 -10
- package/lib/skeletons/_angular/options/openid-jwt/src/environments/environment.prod.ts +11 -11
- package/lib/skeletons/_angular/options/openid-jwt/src/environments/environment.ts +11 -11
- package/lib/skeletons/_angular/options/openid-jwt/src/index.html +21 -21
- package/lib/skeletons/web-maven/package.json +17 -17
- package/lib/skeletons/web-maven/pom.xml +55 -55
- package/lib/skeletons/web-maven/src/main/java/eu/europa/ec/digit/eui/angular2clistarter/servlet/SpringWebApplicationInitializer.java +22 -22
- package/lib/skeletons/web-maven/src/main/java/eu/europa/ec/digit/eui/angular2clistarter/spring/SpringRestConfiguration.java +24 -24
- package/lib/skeletons/web-maven/src/main/java/eu/europa/ec/digit/eui/angular2clistarter/spring/rest/UserDetailsResource.java +23 -23
- package/lib/skeletons/web-maven/src/main/resources/ecas-config-application-name.xml +7 -7
- package/lib/skeletons/web-maven/src/main/webapp/WEB-INF/dispatcher-servlet.xml +10 -10
- package/lib/skeletons/web-maven/src/main/webapp/WEB-INF/web.xml +38 -38
- package/lib/skeletons/web-maven/src/main/webapp/WEB-INF/weblogic.xml +15 -15
- package/lib/skeletons/web-maven/src/main/webapp/index.jsp +29 -29
- package/lib/skeletons/web-spring-boot/myapp-web/pom.xml +77 -77
- package/lib/skeletons/web-spring-boot/myapp-web-rest/pom.xml +84 -84
- package/lib/skeletons/web-spring-boot/myapp-web-rest/src/main/java/myapp/MyappApplication.java +46 -46
- package/lib/skeletons/web-spring-boot/myapp-web-rest/src/main/java/myapp/domain/Address.java +65 -65
- package/lib/skeletons/web-spring-boot/myapp-web-rest/src/main/java/myapp/domain/Building.java +44 -44
- package/lib/skeletons/web-spring-boot/myapp-web-rest/src/main/java/myapp/repositories/BuildingRepository.java +10 -10
- package/lib/skeletons/web-spring-boot/myapp-web-rest/src/main/java/myapp/resources/BuildingResource.java +26 -26
- package/lib/skeletons/web-spring-boot/myapp-web-rest/src/main/java/myapp/resources/SwaggerConfig.java +20 -20
- package/lib/skeletons/web-spring-boot/myapp-web-rest/src/main/java/myapp/resources/support/HateoasPageableHandlerMethodArgumentResolver.java +45 -45
- package/lib/skeletons/web-spring-boot/myapp-web-rest/src/main/java/myapp/resources/support/HypermediaSupport.java +25 -25
- package/lib/skeletons/web-spring-boot/myapp-web-rest/src/main/java/myapp/resources/support/PageJsonSerializer.java +17 -17
- package/lib/skeletons/web-spring-boot/myapp-web-rest/src/main/java/myapp/security/CachingPreventionFilter.java +29 -29
- package/lib/skeletons/web-spring-boot/myapp-web-rest/src/main/java/myapp/security/CsrfPreventionFilter.java +35 -35
- package/lib/skeletons/web-spring-boot/myapp-web-rest/src/main/java/myapp/security/FakeAuthenticationFilter.java +372 -372
- package/lib/skeletons/web-spring-boot/myapp-web-rest/src/main/java/myapp/security/SecurityConfig.java +47 -47
- package/lib/skeletons/web-spring-boot/myapp-web-rest/src/main/java/myapp/services/BuildingSearchCriteria.java +25 -25
- package/lib/skeletons/web-spring-boot/myapp-web-rest/src/main/java/myapp/services/BuildingService.java +9 -9
- package/lib/skeletons/web-spring-boot/myapp-web-rest/src/main/java/myapp/services/BuildingServiceImpl.java +25 -25
- package/lib/skeletons/web-spring-boot/myapp-web-rest/src/main/resources/data.sql +10 -10
- package/lib/skeletons/web-spring-boot/pom.xml +30 -30
- package/lib/skeletons/web-symfony/myapp-web/angular.json +170 -170
- package/lib/skeletons/web-symfony/myapp-web/package.json +23 -23
- package/lib/skeletons/web-symfony/myapp-web/src/app/app-routing.module.ts +18 -18
- package/lib/skeletons/web-symfony/myapp-web/src/app/app.component.ts +77 -77
- package/lib/skeletons/web-symfony/myapp-web/src/app/features/products/components/products.component.html +160 -160
- package/lib/skeletons/web-symfony/myapp-web/src/app/features/products/components/products.component.ts +104 -104
- package/lib/skeletons/web-symfony/myapp-web/src/app/features/products/models/product.model.ts +6 -6
- package/lib/skeletons/web-symfony/myapp-web/src/app/features/products/products-routing.module.ts +16 -16
- package/lib/skeletons/web-symfony/myapp-web/src/app/features/products/products.module.ts +16 -16
- package/lib/skeletons/web-symfony/myapp-web/src/app/features/products/services/products.service.ts +29 -29
- package/lib/skeletons/web-symfony/myapp-web/src/environments/environment.ts +17 -17
- package/lib/skeletons/web-symfony/myapp-web-rest/.env +28 -28
- package/lib/skeletons/web-symfony/myapp-web-rest/bin/console +42 -42
- package/lib/skeletons/web-symfony/myapp-web-rest/composer.json +67 -67
- package/lib/skeletons/web-symfony/myapp-web-rest/composer.lock +3572 -3572
- package/lib/skeletons/web-symfony/myapp-web-rest/config/bootstrap.php +21 -21
- package/lib/skeletons/web-symfony/myapp-web-rest/config/bundles.php +12 -12
- package/lib/skeletons/web-symfony/myapp-web-rest/config/packages/cache.yaml +19 -19
- package/lib/skeletons/web-symfony/myapp-web-rest/config/packages/dev/routing.yaml +3 -3
- package/lib/skeletons/web-symfony/myapp-web-rest/config/packages/doctrine.yaml +29 -29
- package/lib/skeletons/web-symfony/myapp-web-rest/config/packages/doctrine_migrations.yaml +5 -5
- package/lib/skeletons/web-symfony/myapp-web-rest/config/packages/framework.yaml +17 -17
- package/lib/skeletons/web-symfony/myapp-web-rest/config/packages/prod/doctrine.yaml +32 -32
- package/lib/skeletons/web-symfony/myapp-web-rest/config/packages/routing.yaml +4 -4
- package/lib/skeletons/web-symfony/myapp-web-rest/config/packages/sensio_framework_extra.yaml +3 -3
- package/lib/skeletons/web-symfony/myapp-web-rest/config/packages/test/framework.yaml +4 -4
- package/lib/skeletons/web-symfony/myapp-web-rest/config/packages/test/routing.yaml +3 -3
- package/lib/skeletons/web-symfony/myapp-web-rest/config/packages/twig.yaml +4 -4
- package/lib/skeletons/web-symfony/myapp-web-rest/config/routes/annotations.yaml +3 -3
- package/lib/skeletons/web-symfony/myapp-web-rest/config/routes/dev/twig.yaml +3 -3
- package/lib/skeletons/web-symfony/myapp-web-rest/config/routes.yaml +3 -3
- package/lib/skeletons/web-symfony/myapp-web-rest/config/services.yaml +27 -27
- package/lib/skeletons/web-symfony/myapp-web-rest/public/index.php +27 -27
- package/lib/skeletons/web-symfony/myapp-web-rest/src/Controller/ProductController.php +196 -196
- package/lib/skeletons/web-symfony/myapp-web-rest/src/Entity/Product.php +99 -99
- package/lib/skeletons/web-symfony/myapp-web-rest/src/Kernel.php +53 -53
- package/lib/skeletons/web-symfony/myapp-web-rest/src/Migrations/Version20190604101623.php +31 -31
- package/lib/skeletons/web-symfony/myapp-web-rest/src/Migrations/Version20190604101638.php +35 -35
- package/lib/skeletons/web-symfony/myapp-web-rest/src/Repository/ProductRepository.php +51 -51
- package/lib/skeletons/web-symfony/myapp-web-rest/symfony.lock +274 -274
- package/lib/skeletons/web-symfony/myapp-web-rest/templates/base.html.twig +12 -12
- package/lib/skeletons/web-symfony/myapp-web-rest/templates/product/index.html.twig +20 -20
- package/lib/utils.js +17 -17
- package/package.json +2 -2
|
@@ -1,196 +1,196 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
namespace App\Controller;
|
|
3
|
-
use App\Entity\Product;
|
|
4
|
-
use App\Controller\OutputController;
|
|
5
|
-
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
6
|
-
use Symfony\Component\Routing\Annotation\Route;
|
|
7
|
-
use Symfony\Component\HttpFoundation\Response;
|
|
8
|
-
use Symfony\Component\HttpFoundation\Request;
|
|
9
|
-
use Symfony\Component\HttpFoundation\AcceptHeader;
|
|
10
|
-
use Doctrine\ORM\ORMException;
|
|
11
|
-
use Doctrine\DBAL\DBALException;
|
|
12
|
-
|
|
13
|
-
class ProductController extends AbstractController
|
|
14
|
-
{
|
|
15
|
-
/**
|
|
16
|
-
* @Route("/api/product", name="product_create", methods = {"OPTIONS","POST"})
|
|
17
|
-
*/
|
|
18
|
-
public function create()
|
|
19
|
-
{
|
|
20
|
-
try
|
|
21
|
-
{
|
|
22
|
-
$params = json_decode(file_get_contents('php://input'), true);
|
|
23
|
-
|
|
24
|
-
$request = Request::createFromGlobals();
|
|
25
|
-
|
|
26
|
-
if ($request->isMethod('POST')) {
|
|
27
|
-
//ENTITY MANAGER
|
|
28
|
-
$entityManager = $this->getDoctrine()->getManager();
|
|
29
|
-
$product = new Product();
|
|
30
|
-
$product->setName($params['name']);
|
|
31
|
-
$product->setPrice($params['price']);
|
|
32
|
-
$product->setDescription($params['description']);
|
|
33
|
-
|
|
34
|
-
$entityManager->persist($product);
|
|
35
|
-
$entityManager->flush();
|
|
36
|
-
|
|
37
|
-
//GET PRODUCT
|
|
38
|
-
$product = $this->getDoctrine()->getRepository(Product::class)->find($product->getProductId());
|
|
39
|
-
if (!$product) {
|
|
40
|
-
throw $this->createNotFoundException('error');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
//OUTPUT
|
|
44
|
-
$response = new Response(json_encode($product->toArray()));
|
|
45
|
-
|
|
46
|
-
}else{
|
|
47
|
-
$response = new Response();
|
|
48
|
-
$response -> setStatusCode(Response::HTTP_OK);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
$response -> setStatusCode(Response::HTTP_OK);
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
catch (\Exception $e) {
|
|
57
|
-
$response = New Response(json_encode(array('error' => $e->getMessage())));
|
|
58
|
-
$response -> setStatusCode(Response::HTTP_BAD_REQUEST);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return $this->setheaders($response, "POST");
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* @Route("/api/product/update", name="product_udpate", methods = {"OPTIONS","POST"})
|
|
68
|
-
*/
|
|
69
|
-
public function update()
|
|
70
|
-
{
|
|
71
|
-
try
|
|
72
|
-
{
|
|
73
|
-
//PARAMS
|
|
74
|
-
$params = json_decode(file_get_contents('php://input'), true);
|
|
75
|
-
|
|
76
|
-
//GET PRODUCT
|
|
77
|
-
$request = Request::createFromGlobals();
|
|
78
|
-
if ($request->isMethod('POST')) {
|
|
79
|
-
$product = $this->getDoctrine()->getRepository(Product::class)->find($request->request->get('productId'));
|
|
80
|
-
if (!$product) {
|
|
81
|
-
throw $this->createNotFoundException('product not found');
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
//ENTITY MANAGER
|
|
85
|
-
$entityManager = $this->getDoctrine()->getManager();
|
|
86
|
-
$product->setName($params['name']);
|
|
87
|
-
$product->setPrice($params['price']);
|
|
88
|
-
$product->setDescription($params['description']);
|
|
89
|
-
$entityManager->merge($product);
|
|
90
|
-
$entityManager->flush();
|
|
91
|
-
|
|
92
|
-
//OUTPUT
|
|
93
|
-
$response = new Response(json_encode($product->toArray()));
|
|
94
|
-
} else{
|
|
95
|
-
$response = new Response();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
$response -> setStatusCode(Response::HTTP_OK);
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
catch (\Exception $e) {
|
|
102
|
-
$response = New Response(json_encode(array('error' => $e->getMessage())));
|
|
103
|
-
$response -> setStatusCode(Response::HTTP_BAD_REQUEST);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return $this->setheaders($response,"POST");
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* @Route("/api/product/delete/{id}", name="product_delete", methods = {"OPTIONS","DELETE"})
|
|
113
|
-
*/
|
|
114
|
-
public function delete($id)
|
|
115
|
-
{
|
|
116
|
-
|
|
117
|
-
try {
|
|
118
|
-
$request = Request::createFromGlobals();
|
|
119
|
-
|
|
120
|
-
if ($request->isMethod('DELETE')) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
//GET PRODUCT
|
|
124
|
-
$repository = $this->getDoctrine()->getRepository(Product::class);
|
|
125
|
-
$product = $repository->find($id);
|
|
126
|
-
if (!$product) {
|
|
127
|
-
throw $this->createNotFoundException('product not found');
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
//OUTPUT
|
|
131
|
-
$response = new Response(json_encode($product->toArray()));
|
|
132
|
-
|
|
133
|
-
//ENTITY MANAGER
|
|
134
|
-
$entityManager = $this->getDoctrine()->getManager();
|
|
135
|
-
$entityManager->remove($product);
|
|
136
|
-
$entityManager->flush();
|
|
137
|
-
|
|
138
|
-
}else{
|
|
139
|
-
$response = new Response();
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
$response -> setStatusCode(Response::HTTP_OK);
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
catch (\Exception $e) {
|
|
146
|
-
$response = New Response(json_encode(array('error' => $e->getMessage())));
|
|
147
|
-
$response -> setStatusCode(Response::HTTP_BAD_REQUEST);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
return $this->setheaders($response,"DELETE");
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* @Route("/api/products", name="products", methods = {"OPTIONS", "GET"})
|
|
158
|
-
*/
|
|
159
|
-
public function products()
|
|
160
|
-
{
|
|
161
|
-
|
|
162
|
-
$response = [];
|
|
163
|
-
try
|
|
164
|
-
{
|
|
165
|
-
//GET PRODUCTS
|
|
166
|
-
$repository = $this->getDoctrine()->getRepository(Product::class);
|
|
167
|
-
$products = $repository->findAll();
|
|
168
|
-
foreach ($products as $product) {
|
|
169
|
-
$response[] = $product->toArray();
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
//OUTPUT
|
|
173
|
-
$response = new Response(json_encode(array('items' => $response)));
|
|
174
|
-
$response -> setStatusCode(Response::HTTP_OK);
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
catch (\Exception $e) {
|
|
178
|
-
$response = New Response(json_encode(array('error' => $e->getMessage())));
|
|
179
|
-
$response -> setStatusCode(Response::HTTP_BAD_REQUEST);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
return $this->setheaders($response,"GET");
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
//CORS
|
|
187
|
-
function setheaders($response,$method) {
|
|
188
|
-
$response->headers->set('Content-Type', 'application/json');
|
|
189
|
-
$response->headers->set('Access-Control-Allow-Origin', 'http://localhost:4200');
|
|
190
|
-
$response->headers->set('Access-Control-Allow-Headers','Cache-Control,X-Requested-With,Content-Type');
|
|
191
|
-
$response->headers->set('Access-Control-Allow-Credentials','true');
|
|
192
|
-
$response->headers->set('Cache-Control','no-cache');
|
|
193
|
-
$response->headers->set('Access-Control-Allow-Methods',$method);
|
|
194
|
-
return $response;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
1
|
+
<?php
|
|
2
|
+
namespace App\Controller;
|
|
3
|
+
use App\Entity\Product;
|
|
4
|
+
use App\Controller\OutputController;
|
|
5
|
+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
6
|
+
use Symfony\Component\Routing\Annotation\Route;
|
|
7
|
+
use Symfony\Component\HttpFoundation\Response;
|
|
8
|
+
use Symfony\Component\HttpFoundation\Request;
|
|
9
|
+
use Symfony\Component\HttpFoundation\AcceptHeader;
|
|
10
|
+
use Doctrine\ORM\ORMException;
|
|
11
|
+
use Doctrine\DBAL\DBALException;
|
|
12
|
+
|
|
13
|
+
class ProductController extends AbstractController
|
|
14
|
+
{
|
|
15
|
+
/**
|
|
16
|
+
* @Route("/api/product", name="product_create", methods = {"OPTIONS","POST"})
|
|
17
|
+
*/
|
|
18
|
+
public function create()
|
|
19
|
+
{
|
|
20
|
+
try
|
|
21
|
+
{
|
|
22
|
+
$params = json_decode(file_get_contents('php://input'), true);
|
|
23
|
+
|
|
24
|
+
$request = Request::createFromGlobals();
|
|
25
|
+
|
|
26
|
+
if ($request->isMethod('POST')) {
|
|
27
|
+
//ENTITY MANAGER
|
|
28
|
+
$entityManager = $this->getDoctrine()->getManager();
|
|
29
|
+
$product = new Product();
|
|
30
|
+
$product->setName($params['name']);
|
|
31
|
+
$product->setPrice($params['price']);
|
|
32
|
+
$product->setDescription($params['description']);
|
|
33
|
+
|
|
34
|
+
$entityManager->persist($product);
|
|
35
|
+
$entityManager->flush();
|
|
36
|
+
|
|
37
|
+
//GET PRODUCT
|
|
38
|
+
$product = $this->getDoctrine()->getRepository(Product::class)->find($product->getProductId());
|
|
39
|
+
if (!$product) {
|
|
40
|
+
throw $this->createNotFoundException('error');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//OUTPUT
|
|
44
|
+
$response = new Response(json_encode($product->toArray()));
|
|
45
|
+
|
|
46
|
+
}else{
|
|
47
|
+
$response = new Response();
|
|
48
|
+
$response -> setStatusCode(Response::HTTP_OK);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
$response -> setStatusCode(Response::HTTP_OK);
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
catch (\Exception $e) {
|
|
57
|
+
$response = New Response(json_encode(array('error' => $e->getMessage())));
|
|
58
|
+
$response -> setStatusCode(Response::HTTP_BAD_REQUEST);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return $this->setheaders($response, "POST");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @Route("/api/product/update", name="product_udpate", methods = {"OPTIONS","POST"})
|
|
68
|
+
*/
|
|
69
|
+
public function update()
|
|
70
|
+
{
|
|
71
|
+
try
|
|
72
|
+
{
|
|
73
|
+
//PARAMS
|
|
74
|
+
$params = json_decode(file_get_contents('php://input'), true);
|
|
75
|
+
|
|
76
|
+
//GET PRODUCT
|
|
77
|
+
$request = Request::createFromGlobals();
|
|
78
|
+
if ($request->isMethod('POST')) {
|
|
79
|
+
$product = $this->getDoctrine()->getRepository(Product::class)->find($request->request->get('productId'));
|
|
80
|
+
if (!$product) {
|
|
81
|
+
throw $this->createNotFoundException('product not found');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//ENTITY MANAGER
|
|
85
|
+
$entityManager = $this->getDoctrine()->getManager();
|
|
86
|
+
$product->setName($params['name']);
|
|
87
|
+
$product->setPrice($params['price']);
|
|
88
|
+
$product->setDescription($params['description']);
|
|
89
|
+
$entityManager->merge($product);
|
|
90
|
+
$entityManager->flush();
|
|
91
|
+
|
|
92
|
+
//OUTPUT
|
|
93
|
+
$response = new Response(json_encode($product->toArray()));
|
|
94
|
+
} else{
|
|
95
|
+
$response = new Response();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
$response -> setStatusCode(Response::HTTP_OK);
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
catch (\Exception $e) {
|
|
102
|
+
$response = New Response(json_encode(array('error' => $e->getMessage())));
|
|
103
|
+
$response -> setStatusCode(Response::HTTP_BAD_REQUEST);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return $this->setheaders($response,"POST");
|
|
107
|
+
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @Route("/api/product/delete/{id}", name="product_delete", methods = {"OPTIONS","DELETE"})
|
|
113
|
+
*/
|
|
114
|
+
public function delete($id)
|
|
115
|
+
{
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
$request = Request::createFromGlobals();
|
|
119
|
+
|
|
120
|
+
if ($request->isMethod('DELETE')) {
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
//GET PRODUCT
|
|
124
|
+
$repository = $this->getDoctrine()->getRepository(Product::class);
|
|
125
|
+
$product = $repository->find($id);
|
|
126
|
+
if (!$product) {
|
|
127
|
+
throw $this->createNotFoundException('product not found');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
//OUTPUT
|
|
131
|
+
$response = new Response(json_encode($product->toArray()));
|
|
132
|
+
|
|
133
|
+
//ENTITY MANAGER
|
|
134
|
+
$entityManager = $this->getDoctrine()->getManager();
|
|
135
|
+
$entityManager->remove($product);
|
|
136
|
+
$entityManager->flush();
|
|
137
|
+
|
|
138
|
+
}else{
|
|
139
|
+
$response = new Response();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
$response -> setStatusCode(Response::HTTP_OK);
|
|
143
|
+
|
|
144
|
+
}
|
|
145
|
+
catch (\Exception $e) {
|
|
146
|
+
$response = New Response(json_encode(array('error' => $e->getMessage())));
|
|
147
|
+
$response -> setStatusCode(Response::HTTP_BAD_REQUEST);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
return $this->setheaders($response,"DELETE");
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @Route("/api/products", name="products", methods = {"OPTIONS", "GET"})
|
|
158
|
+
*/
|
|
159
|
+
public function products()
|
|
160
|
+
{
|
|
161
|
+
|
|
162
|
+
$response = [];
|
|
163
|
+
try
|
|
164
|
+
{
|
|
165
|
+
//GET PRODUCTS
|
|
166
|
+
$repository = $this->getDoctrine()->getRepository(Product::class);
|
|
167
|
+
$products = $repository->findAll();
|
|
168
|
+
foreach ($products as $product) {
|
|
169
|
+
$response[] = $product->toArray();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
//OUTPUT
|
|
173
|
+
$response = new Response(json_encode(array('items' => $response)));
|
|
174
|
+
$response -> setStatusCode(Response::HTTP_OK);
|
|
175
|
+
|
|
176
|
+
}
|
|
177
|
+
catch (\Exception $e) {
|
|
178
|
+
$response = New Response(json_encode(array('error' => $e->getMessage())));
|
|
179
|
+
$response -> setStatusCode(Response::HTTP_BAD_REQUEST);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
return $this->setheaders($response,"GET");
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
//CORS
|
|
187
|
+
function setheaders($response,$method) {
|
|
188
|
+
$response->headers->set('Content-Type', 'application/json');
|
|
189
|
+
$response->headers->set('Access-Control-Allow-Origin', 'http://localhost:4200');
|
|
190
|
+
$response->headers->set('Access-Control-Allow-Headers','Cache-Control,X-Requested-With,Content-Type');
|
|
191
|
+
$response->headers->set('Access-Control-Allow-Credentials','true');
|
|
192
|
+
$response->headers->set('Cache-Control','no-cache');
|
|
193
|
+
$response->headers->set('Access-Control-Allow-Methods',$method);
|
|
194
|
+
return $response;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
|
|
3
|
-
namespace App\Entity;
|
|
4
|
-
|
|
5
|
-
use Doctrine\ORM\Mapping as ORM;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
|
|
9
|
-
* @ORM\Table(name="product")
|
|
10
|
-
*/
|
|
11
|
-
class Product
|
|
12
|
-
{
|
|
13
|
-
/**
|
|
14
|
-
* @ORM\Id()
|
|
15
|
-
* @ORM\GeneratedValue()
|
|
16
|
-
* @ORM\Column(type="integer")
|
|
17
|
-
*/
|
|
18
|
-
private $productId;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @ORM\Column(type="string", length=255)
|
|
22
|
-
*/
|
|
23
|
-
private $name;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @ORM\Column(type="integer")
|
|
27
|
-
*/
|
|
28
|
-
private $price;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @ORM\Column(type="text", nullable=true)
|
|
32
|
-
*/
|
|
33
|
-
private $description;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
public function getProductId(): ?int
|
|
37
|
-
{
|
|
38
|
-
return $this->productId;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
public function setProductId(int $productId): self
|
|
42
|
-
{
|
|
43
|
-
$this->productId = $productId;
|
|
44
|
-
|
|
45
|
-
return $this;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
public function getName(): ?string
|
|
49
|
-
{
|
|
50
|
-
return $this->name;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
public function setName(string $name): self
|
|
54
|
-
{
|
|
55
|
-
$this->name = $name;
|
|
56
|
-
|
|
57
|
-
return $this;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
public function getPrice(): ?int
|
|
61
|
-
{
|
|
62
|
-
return $this->price;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public function setPrice(int $price): self
|
|
66
|
-
{
|
|
67
|
-
$this->price = $price;
|
|
68
|
-
|
|
69
|
-
return $this;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
public function getDescription(): ?string
|
|
73
|
-
{
|
|
74
|
-
return $this->description;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
public function setDescription(?string $description): self
|
|
78
|
-
{
|
|
79
|
-
$this->description = $description;
|
|
80
|
-
|
|
81
|
-
return $this;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
public function toArray() {
|
|
85
|
-
$vars = get_object_vars ( $this );
|
|
86
|
-
$array = array ();
|
|
87
|
-
foreach ( $vars as $key => $value ) {
|
|
88
|
-
$array [ltrim ( $key, '_' )] = $value;
|
|
89
|
-
}
|
|
90
|
-
return $array;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace App\Entity;
|
|
4
|
+
|
|
5
|
+
use Doctrine\ORM\Mapping as ORM;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
|
|
9
|
+
* @ORM\Table(name="product")
|
|
10
|
+
*/
|
|
11
|
+
class Product
|
|
12
|
+
{
|
|
13
|
+
/**
|
|
14
|
+
* @ORM\Id()
|
|
15
|
+
* @ORM\GeneratedValue()
|
|
16
|
+
* @ORM\Column(type="integer")
|
|
17
|
+
*/
|
|
18
|
+
private $productId;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @ORM\Column(type="string", length=255)
|
|
22
|
+
*/
|
|
23
|
+
private $name;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @ORM\Column(type="integer")
|
|
27
|
+
*/
|
|
28
|
+
private $price;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @ORM\Column(type="text", nullable=true)
|
|
32
|
+
*/
|
|
33
|
+
private $description;
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
public function getProductId(): ?int
|
|
37
|
+
{
|
|
38
|
+
return $this->productId;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public function setProductId(int $productId): self
|
|
42
|
+
{
|
|
43
|
+
$this->productId = $productId;
|
|
44
|
+
|
|
45
|
+
return $this;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public function getName(): ?string
|
|
49
|
+
{
|
|
50
|
+
return $this->name;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public function setName(string $name): self
|
|
54
|
+
{
|
|
55
|
+
$this->name = $name;
|
|
56
|
+
|
|
57
|
+
return $this;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public function getPrice(): ?int
|
|
61
|
+
{
|
|
62
|
+
return $this->price;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public function setPrice(int $price): self
|
|
66
|
+
{
|
|
67
|
+
$this->price = $price;
|
|
68
|
+
|
|
69
|
+
return $this;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public function getDescription(): ?string
|
|
73
|
+
{
|
|
74
|
+
return $this->description;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public function setDescription(?string $description): self
|
|
78
|
+
{
|
|
79
|
+
$this->description = $description;
|
|
80
|
+
|
|
81
|
+
return $this;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public function toArray() {
|
|
85
|
+
$vars = get_object_vars ( $this );
|
|
86
|
+
$array = array ();
|
|
87
|
+
foreach ( $vars as $key => $value ) {
|
|
88
|
+
$array [ltrim ( $key, '_' )] = $value;
|
|
89
|
+
}
|
|
90
|
+
return $array;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|