32 lines
867 B
PHP
32 lines
867 B
PHP
|
<?php
|
||
|
use Respect\Validation\Validator as DataValidator;
|
||
|
DataValidator::with('CustomValidations', true);
|
||
|
|
||
|
class AddTopicController extends Controller {
|
||
|
const PATH = '/add-topic';
|
||
|
|
||
|
public function validations() {
|
||
|
return [
|
||
|
'permission' => 'staff_2',
|
||
|
'requestData' => [
|
||
|
'name' => [
|
||
|
'validation' => DataValidator::length(3, 40),
|
||
|
'error' => ERRORS::INVALID_NAME
|
||
|
]
|
||
|
]
|
||
|
];
|
||
|
}
|
||
|
|
||
|
public function handler() {
|
||
|
$topic = new Topic();
|
||
|
$topic->setProperties([
|
||
|
'name' => Controller::request('name'),
|
||
|
'icon' => Controller::request('icon'),
|
||
|
'iconColor' => Controller::request('iconColor')
|
||
|
]);
|
||
|
|
||
|
Response::respondSuccess([
|
||
|
'topicId' => $topic->store()
|
||
|
]);
|
||
|
}
|
||
|
}
|