init
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?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;
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user