add tests for files and refactor
This commit is contained in:
parent
b0cb0db558
commit
010282a7bb
6 changed files with 112 additions and 49 deletions
|
@ -20,17 +20,8 @@ class FileController extends Controller
|
|||
|
||||
public function create(Request $request)
|
||||
{
|
||||
$File = File::create($request->all());
|
||||
|
||||
return response()->json($File, 201);
|
||||
}
|
||||
|
||||
public function update($id, Request $request)
|
||||
{
|
||||
$File = File::findOrFail($id);
|
||||
$File->update($request->all());
|
||||
|
||||
return response()->json($File, 200);
|
||||
$file = File::create($request->only(['data','iid']));
|
||||
return response()->json($file, 201);
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
|
|
|
@ -48,19 +48,11 @@ class ItemController extends Controller
|
|||
$newitem['eid'] = "".$eid;
|
||||
$item = Item::create($newitem);
|
||||
|
||||
if ($request->get('dataImage')) {
|
||||
$pos = strpos($request->get('dataImage'), ",");
|
||||
//$head = substr($request->get('dataImage'), 0, $pos);
|
||||
$image = base64_decode(substr($request->get('dataImage'), $pos + 1), true);
|
||||
if ($image) {
|
||||
$hash = md5(time());
|
||||
if (!file_exists('staticimages'))
|
||||
mkdir('staticimages', 0755, true);
|
||||
file_put_contents('staticimages/' . $hash, $image);
|
||||
$file = File::create(array('hash' => $hash, 'iid' => $item['iid']));
|
||||
$item['file'] = $hash;
|
||||
}
|
||||
if($request->get('dataImage')) {
|
||||
$file = File::create(array('data' => $request->get('dataImage'), 'iid' => $item['iid']));
|
||||
$item['file'] = $file['hash'];
|
||||
}
|
||||
|
||||
return response()->json($item, 201);
|
||||
}
|
||||
|
||||
|
@ -74,19 +66,11 @@ class ItemController extends Controller
|
|||
$item->update(['returned_at' => DB::raw( 'current_timestamp' )]);
|
||||
}
|
||||
|
||||
if ($request->get('dataImage')) {
|
||||
$pos = strpos($request->get('dataImage'), ",");
|
||||
//$head = substr($request->get('dataImage'), 0, $pos);
|
||||
$image = base64_decode(substr($request->get('dataImage'), $pos + 1), true);
|
||||
if ($image) {
|
||||
$hash = md5(time());
|
||||
if (!file_exists('staticimages'))
|
||||
mkdir('staticimages', 0755, true);
|
||||
file_put_contents('staticimages/' . $hash, $image);
|
||||
$file = File::create(array('hash' => $hash, 'iid' => $item['iid']));
|
||||
$item['file'] = $hash;
|
||||
}
|
||||
if($request->get('dataImage')) {
|
||||
$file = File::create(array('data' => $request->get('dataImage'), 'iid' => $item['iid']));
|
||||
$item['file'] = $file['hash'];
|
||||
}
|
||||
|
||||
return response()->json(Item::find($item['uid']), 200);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue