forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MessageRestController.php
58 lines (46 loc) · 1.77 KB
/
MessageRestController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* MessageRestController
*
* @package OpenEMR
* @link http://www.open-emr.org
* @author Matthew Vita <[email protected]>
* @copyright Copyright (c) 2018 Matthew Vita <[email protected]>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/
namespace OpenEMR\RestControllers;
use OpenEMR\Services\MessageService;
use OpenEMR\RestControllers\RestControllerHelper;
class MessageRestController
{
private $messageService;
public function __construct()
{
$this->messageService = new MessageService();
}
public function put($pid, $mid, $data)
{
$validationResult = $this->messageService->validate($data);
$validationHandlerResult = RestControllerHelper::validationHandler($validationResult);
if (is_array($validationHandlerResult)) {
return $validationHandlerResult;
}
$serviceResult = $this->messageService->update($pid, $mid, $data);
return RestControllerHelper::responseHandler($serviceResult, array("mid" => $mid), 200);
}
public function post($pid, $data)
{
$validationResult = $this->messageService->validate($data);
$validationHandlerResult = RestControllerHelper::validationHandler($validationResult);
if (is_array($validationHandlerResult)) {
return $validationHandlerResult;
}
$serviceResult = $this->messageService->insert($pid, $data);
return RestControllerHelper::responseHandler($serviceResult, array("mid" => $serviceResult), 201);
}
public function delete($pid, $mid)
{
$serviceResult = $this->messageService->delete($pid, $mid);
return RestControllerHelper::responseHandler($serviceResult, true, 200);
}
}