52 lines
1.1 KiB
PHP
52 lines
1.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
Flight::route('POST /v1/api/image/add', function()
|
||
|
|
{
|
||
|
|
|
||
|
|
|
||
|
|
$model = new ImagesModel();
|
||
|
|
$allow_fields = ['url', 'user_id', 'caption'];
|
||
|
|
$validation = new ValidationService();
|
||
|
|
$request = new Auth_common_function();
|
||
|
|
$validation->save_rules($model->get_all_validation_rule());
|
||
|
|
$_POST = Flight::request()->data->getData();
|
||
|
|
if ($validation->validate($_POST))
|
||
|
|
{
|
||
|
|
$result = $model->create([
|
||
|
|
'url' => $request->get_input_post('url'),
|
||
|
|
'user_id' => $request->get_input_post('user_id'),
|
||
|
|
'caption' => $request->get_input_post('caption'),
|
||
|
|
]);
|
||
|
|
|
||
|
|
if ($result)
|
||
|
|
{
|
||
|
|
echo json_encode([
|
||
|
|
'code' => 200,
|
||
|
|
'error' => false,
|
||
|
|
'id' => $result
|
||
|
|
]);
|
||
|
|
http_response_code(200);
|
||
|
|
exit;
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
echo json_encode([
|
||
|
|
'code' => 409,
|
||
|
|
'error' => false
|
||
|
|
]);
|
||
|
|
http_response_code(409);
|
||
|
|
exit;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
$message = $validation->get_errors();
|
||
|
|
$result['error'] = true;
|
||
|
|
$result['http_code'] = 403;
|
||
|
|
$result['message'] = $message;
|
||
|
|
|
||
|
|
echo json_encode($result);
|
||
|
|
http_response_code(403);
|
||
|
|
exit;
|
||
|
|
}
|
||
|
|
});
|