| @@ 148-166 (lines=19) @@ | ||
| 145 | * @param int $id |
|
| 146 | * @return array |
|
| 147 | */ |
|
| 148 | public function build(Request $request, $id) |
|
| 149 | { |
|
| 150 | $repo = new ServerRepository; |
|
| 151 | ||
| 152 | try { |
|
| 153 | $server = $repo->changeBuild($id, $request->intersect([ |
|
| 154 | 'allocation_id', 'add_allocations', 'remove_allocations', |
|
| 155 | 'memory', 'swap', 'io', 'cpu', |
|
| 156 | ])); |
|
| 157 | ||
| 158 | return ['id' => $id]; |
|
| 159 | } catch (DisplayValidationException $ex) { |
|
| 160 | throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true)); |
|
| 161 | } catch (DisplayException $ex) { |
|
| 162 | throw new ResourceException($ex->getMessage()); |
|
| 163 | } catch (\Exception $ex) { |
|
| 164 | throw new ServiceUnavailableHttpException('Unable to update server on system due to an error.'); |
|
| 165 | } |
|
| 166 | } |
|
| 167 | ||
| 168 | /** |
|
| 169 | * Suspend Server. |
|
| @@ 84-102 (lines=19) @@ | ||
| 81 | * @param Request $request |
|
| 82 | * @return array |
|
| 83 | */ |
|
| 84 | public function create(Request $request) |
|
| 85 | { |
|
| 86 | $repo = new UserRepository; |
|
| 87 | ||
| 88 | try { |
|
| 89 | $user = $user->create($request->only([ |
|
| 90 | 'email', 'password', 'name_first', |
|
| 91 | 'name_last', 'username', 'root_admin', |
|
| 92 | ])); |
|
| 93 | ||
| 94 | return ['id' => $user->id]; |
|
| 95 | } catch (DisplayValidationException $ex) { |
|
| 96 | throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true)); |
|
| 97 | } catch (DisplayException $ex) { |
|
| 98 | throw new ResourceException($ex->getMessage()); |
|
| 99 | } catch (\Exception $ex) { |
|
| 100 | throw new ServiceUnavailableHttpException('Unable to create a user on the system due to an error.'); |
|
| 101 | } |
|
| 102 | } |
|
| 103 | ||
| 104 | /** |
|
| 105 | * Update an Existing User. |
|
| @@ 111-129 (lines=19) @@ | ||
| 108 | * @param int $id |
|
| 109 | * @return array |
|
| 110 | */ |
|
| 111 | public function update(Request $request, $id) |
|
| 112 | { |
|
| 113 | $repo = new UserRepository; |
|
| 114 | ||
| 115 | try { |
|
| 116 | $user = $repo->update($id, $request->only([ |
|
| 117 | 'email', 'password', 'name_first', |
|
| 118 | 'name_last', 'username', 'root_admin', |
|
| 119 | ])); |
|
| 120 | ||
| 121 | return ['id' => $id]; |
|
| 122 | } catch (DisplayValidationException $ex) { |
|
| 123 | throw new ResourceException('A validation error occured.', json_decode($ex->getMessage(), true)); |
|
| 124 | } catch (DisplayException $ex) { |
|
| 125 | throw new ResourceException($ex->getMessage()); |
|
| 126 | } catch (\Exception $ex) { |
|
| 127 | throw new ServiceUnavailableHttpException('Unable to update a user on the system due to an error.'); |
|
| 128 | } |
|
| 129 | } |
|
| 130 | ||
| 131 | /** |
|
| 132 | * Delete a User. |
|