1
|
|
|
<?php |
2
|
|
|
namespace NOSQL\Api; |
3
|
|
|
|
4
|
|
|
use PSFS\base\dto\JsonResponse; |
5
|
|
|
use PSFS\base\Logger; |
6
|
|
|
use PSFS\base\types\CustomApi; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class NOSQL |
10
|
|
|
* @package NOSQL\Api |
11
|
|
|
* @Api __admin |
12
|
|
|
*/ |
13
|
|
|
class NOSQL extends CustomApi { |
14
|
|
|
/** |
15
|
|
|
* @Injectable |
16
|
|
|
* @var \NOSQL\Services\NOSQLService |
17
|
|
|
*/ |
18
|
|
|
protected $srv; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @GET |
22
|
|
|
* @route /{__DOMAIN__}/APi/{__API__}/types |
23
|
|
|
* @return \PSFS\base\dto\JsonResponse(data=array) |
24
|
|
|
*/ |
25
|
|
|
public function getNOSQLTypes() { |
26
|
|
|
return $this->json(new JsonResponse($this->srv->getTypes(), true), 200); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @GET |
31
|
|
|
* @route /{__DOMAIN__}/APi/{__API__}/validations |
32
|
|
|
* @return \PSFS\base\dto\JsonResponse(data=array) |
33
|
|
|
*/ |
34
|
|
|
public function getFormValidations() { |
35
|
|
|
return $this->json(new JsonResponse($this->srv->getValidations(), true), 200); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @GET |
40
|
|
|
* @route /{__DOMAIN__}/APi/{__API__}/domains |
41
|
|
|
* @return \PSFS\base\dto\JsonResponse(data=array) |
42
|
|
|
*/ |
43
|
|
|
public function readModules() { |
44
|
|
|
return $this->json(new JsonResponse($this->srv->getDomains(), true), 200); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @GET |
49
|
|
|
* @route /{__DOMAIN__}/APi/{__API__}/{module}/collections |
50
|
|
|
* @return \PSFS\base\dto\JsonResponse(data=array) |
51
|
|
|
*/ |
52
|
|
|
public function readCollections($module) { |
53
|
|
|
return $this->json(new JsonResponse($this->srv->getCollections($module), true), 200); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @PUT |
58
|
|
|
* @param string $module |
59
|
|
|
* @payload \NOSQL\Dto\CollectionDto[] |
60
|
|
|
* @route /{__DOMAIN__}/APi/{__API__}/{module}/collections |
61
|
|
|
* @return \PSFS\base\dto\JsonResponse(data=boolean) |
62
|
|
|
*/ |
63
|
|
|
public function storeCollections($module) { |
64
|
|
|
$success = true; |
65
|
|
|
$code = 200; |
66
|
|
|
try { |
67
|
|
|
$this->srv->setCollections($module, $this->getRequest()->getRawData()); |
68
|
|
|
} catch(\Exception $exception) { |
69
|
|
|
$success = false; |
70
|
|
|
$code = 400; |
71
|
|
|
Logger::log($exception->getMessage(), LOG_WARNING); |
72
|
|
|
} |
73
|
|
|
return $this->json(new JsonResponse($success, $success), $code); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @POST |
78
|
|
|
* @param string $module |
79
|
|
|
* @route /{__DOMAIN__}/APi/{__API__}/{module}/sync |
80
|
|
|
* @return \PSFS\base\dto\JsonResponse(data=boolean) |
81
|
|
|
*/ |
82
|
|
|
public function syncCollections($module) { |
83
|
|
|
$code = 200; |
84
|
|
|
try { |
85
|
|
|
$success = $this->srv->syncCollections($module); |
86
|
|
|
} catch(\Exception $exception) { |
87
|
|
|
$success = false; |
88
|
|
|
$code = 400; |
89
|
|
|
Logger::log($exception->getMessage(), LOG_WARNING); |
90
|
|
|
} |
91
|
|
|
return $this->json(new JsonResponse($success, $success), $code); |
|
|
|
|
92
|
|
|
|
93
|
|
|
} |
94
|
|
|
} |