Completed
Push — master ( 716c72...0a3015 )
by Christoph
09:06
created

AliasesController::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
/**
3
 * @author Tahaa Karim <[email protected]>
4
 *
5
 * ownCloud - Mail
6
 *
7
 * This code is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Affero General Public License, version 3,
9
 * as published by the Free Software Foundation.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU Affero General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Affero General Public License, version 3,
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
18
 *
19
 */
20
21
namespace OCA\Mail\Controller;
22
23
use OCA\Mail\Db\Alias;
24
use OCP\IRequest;
25
use OCA\Mail\Service\AliasesService;
26
use OCP\AppFramework\Controller;
27
use OCP\AppFramework\Http\JSONResponse;
28
use OCP\AppFramework\Http;
29
use OCP\IUserSession;
30
31
class AliasesController extends Controller {
32
33
	/** @var AliasesService */
34
	private $aliasService;
35
36
	/**
37
	 * @var \OCP\IUser
38
	 */
39
	private $currentUser;
40
41
	/**
42
	 * @param string $appName
43
	 * @param IRequest $request
44
	 * @param AliasesService $aliasesService
45
	 */
46
	public function __construct($appName, IRequest $request, AliasesService $aliasesService, IUserSession $userSession) {
47
		parent::__construct($appName, $request);
48
		$this->aliasService = $aliasesService;
49
		$this->currentUser = $userSession->getUser();
50
	}
51
52
	/**
53
	 * @NoAdminRequired
54
	 * @NoCSRFRequired
55
	 * @param int $accountId
56
	 * @return Alias[]
57
	 */
58
	public function index($accountId) {
59
		return $this->aliasService->findAll($accountId, $this->currentUser->getUID());
60
	}
61
62
	/**
63
	 * @NoAdminRequired
64
	 * @NoCSRFRequired
65
	 */
66
	public function show() {
67
		$response = new JSONResponse();
68
		$response->setStatus(Http::STATUS_NOT_IMPLEMENTED);
69
		return $response;
70
	}
71
72
	/**
73
	 * @NoAdminRequired
74
	 * @NoCSRFRequired
75
	 */
76
	public function update() {
77
		$response = new JSONResponse();
78
		$response->setStatus(Http::STATUS_NOT_IMPLEMENTED);
79
		return $response;
80
	}
81
82
	/**
83
	 * @NoAdminRequired
84
	 * @NoCSRFRequired
85
	 * @param int $id
86
	 * @return Alias[]
87
	 */
88
	public function destroy($id) {
89
		return $this->aliasService->delete($id, $this->currentUser->getUID());
90
	}
91
92
	/**
93
	 * @NoAdminRequired
94
	 * @NoCSRFRequired
95
	 * @param int $accountId
96
	 * @param string $alias
97
	 * @param string $aliasName
98
	 * @return Alias[]
99
	 */
100
	public function create($accountId, $alias, $aliasName) {
101
		return $this->aliasService->create($accountId, $alias, $aliasName);
102
	}
103
}
104