fix(file): fixed file controller and added method to check file upload
This commit is contained in:
parent
7abd0bf5b1
commit
d02267fd59
1 changed files with 26 additions and 7 deletions
|
@ -27,9 +27,13 @@ class FileController extends Controller
|
|||
$pagination = $request->per_page;
|
||||
}
|
||||
|
||||
$test = File::searchFilter($request);
|
||||
|
||||
return File::searchFilter($request)->with('trackType')->orderBy('artist_name')->paginate($pagination);
|
||||
return File::searchFilter($request)
|
||||
->where('import_status', '=', 0)
|
||||
->with('track_type')
|
||||
->with('owner')
|
||||
->orderBy('artist_name')
|
||||
->paginate($pagination)
|
||||
->toJson();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -85,6 +89,8 @@ class FileController extends Controller
|
|||
$dbFile->id,
|
||||
$dbFile->track_type_id
|
||||
);
|
||||
|
||||
return $dbFile->toJson();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,7 +99,7 @@ class FileController extends Controller
|
|||
* @return mixed
|
||||
*/
|
||||
public function show($id) {
|
||||
return File::whereId($id)->toJson();
|
||||
return File::whereId($id)->first()->toJson();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -104,16 +110,25 @@ class FileController extends Controller
|
|||
* @return mixed
|
||||
*/
|
||||
public function update(Request $request, $id) {
|
||||
// return json_encode(['req' => $request->all(),'id' => $id]);
|
||||
$file = File::whereId($id)->first();
|
||||
$fields = $request->all();
|
||||
//$fields['length'] = new LengthFormatter($fields['length']);
|
||||
$fields['filepath'] = $fields['full_path'];
|
||||
|
||||
$request->length = new LengthFormatter($request->length);
|
||||
//Check Import status
|
||||
if ($fields['import_status'] == 'PipelineStatus.SUCCEED') {
|
||||
$fields['import_status'] = 0;
|
||||
}
|
||||
|
||||
//Check if there is a track type id, if not add "MUSIC" id
|
||||
if (is_null($file->track_type_id)) {
|
||||
$request->track_type_id = TrackType::where('code','MUSICA')->first()->id;
|
||||
$fields['track_type_id'] = TrackType::where('code','MUSICA')->first()->id;
|
||||
}
|
||||
|
||||
$file->fill($request->all())->save();
|
||||
//return json_encode(['req' => $fields,'id' => $id]);
|
||||
|
||||
$file->fill($fields)->save();
|
||||
return $file->toJson();
|
||||
}
|
||||
|
||||
|
@ -129,6 +144,10 @@ class FileController extends Controller
|
|||
return true;
|
||||
}
|
||||
|
||||
public function checkUploadStatus($id) {
|
||||
return File::whereId($id)->first()->only('import_status');
|
||||
}
|
||||
|
||||
//Test Method, must be deleted before finishing
|
||||
public function test() {
|
||||
return view('upload');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue