|
@@ -3,83 +3,81 @@
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
+use App\Models\Server;
|
|
|
+use Exception;
|
|
|
+use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
|
|
+use Illuminate\Http\JsonResponse;
|
|
|
+use Illuminate\Http\RedirectResponse;
|
|
|
use Illuminate\Http\Request;
|
|
|
+use Illuminate\Http\Response;
|
|
|
|
|
|
class ServerController extends Controller
|
|
|
{
|
|
|
/**
|
|
|
* Display a listing of the resource.
|
|
|
*
|
|
|
- * @return \Illuminate\Http\Response
|
|
|
+ * @param Request $request
|
|
|
+ * @return LengthAwarePaginator
|
|
|
*/
|
|
|
- public function index()
|
|
|
+ public function index(Request $request)
|
|
|
{
|
|
|
- //
|
|
|
+ return Server::with('product')->paginate($request->query('per_page') ?? 50);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Show the form for creating a new resource.
|
|
|
- *
|
|
|
- * @return \Illuminate\Http\Response
|
|
|
- */
|
|
|
- public function create()
|
|
|
- {
|
|
|
- //
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Store a newly created resource in storage.
|
|
|
- *
|
|
|
- * @param \Illuminate\Http\Request $request
|
|
|
- * @return \Illuminate\Http\Response
|
|
|
- */
|
|
|
- public function store(Request $request)
|
|
|
- {
|
|
|
- //
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* Display the specified resource.
|
|
|
*
|
|
|
- * @param int $id
|
|
|
- * @return \Illuminate\Http\Response
|
|
|
+ * @param Server $server
|
|
|
+ * @return Server
|
|
|
*/
|
|
|
- public function show($id)
|
|
|
+ public function show(Server $server)
|
|
|
{
|
|
|
- //
|
|
|
+ return $server->load('product');
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * Show the form for editing the specified resource.
|
|
|
+ * Remove the specified resource from storage.
|
|
|
*
|
|
|
- * @param int $id
|
|
|
- * @return \Illuminate\Http\Response
|
|
|
+ * @param Server $server
|
|
|
+ * @return Server
|
|
|
*/
|
|
|
- public function edit($id)
|
|
|
+ public function destroy(Server $server)
|
|
|
{
|
|
|
- //
|
|
|
+ $server->delete();
|
|
|
+ return $server;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * Update the specified resource in storage.
|
|
|
- *
|
|
|
- * @param \Illuminate\Http\Request $request
|
|
|
- * @param int $id
|
|
|
- * @return \Illuminate\Http\Response
|
|
|
+ * suspend server
|
|
|
+ * @param Server $server
|
|
|
+ * @return Server|JsonResponse
|
|
|
*/
|
|
|
- public function update(Request $request, $id)
|
|
|
- {
|
|
|
- //
|
|
|
+ public function suspend(Server $server) {
|
|
|
+ try {
|
|
|
+ $server->suspend();
|
|
|
+ } catch (Exception $exception) {
|
|
|
+ return response()->json(['message' => $exception->getMessage()] , 500);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $server->load('product');
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * Remove the specified resource from storage.
|
|
|
- *
|
|
|
- * @param int $id
|
|
|
- * @return \Illuminate\Http\Response
|
|
|
+ * unsuspend server
|
|
|
+ * @param Server $server
|
|
|
+ * @return Server|JsonResponse
|
|
|
*/
|
|
|
- public function destroy($id)
|
|
|
- {
|
|
|
- //
|
|
|
+ public function unSuspend(Server $server) {
|
|
|
+ try {
|
|
|
+ $server->unSuspend();
|
|
|
+ } catch (Exception $exception) {
|
|
|
+ return response()->json(['message' => $exception->getMessage()] , 500);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $server->load('product');
|
|
|
}
|
|
|
}
|