@@ 17-121 (lines=105) @@ | ||
14 | /** |
|
15 | * @author Lukas Homza <[email protected]> |
|
16 | */ |
|
17 | class PackageController extends BaseController { |
|
18 | /** |
|
19 | * @param \Illuminate\Http\Request $request |
|
20 | * @param \App\Satis\ConfigManager $configManager |
|
21 | * @param string|null $packageId |
|
22 | * |
|
23 | * @throws \HttpInvalidParamException |
|
24 | */ |
|
25 | protected function addOrUpdatePackage(Request $request, ConfigManager $configManager, $packageId = null) { |
|
26 | $input = new Collection($request->all()); |
|
27 | ||
28 | $validator = Validator::make( |
|
29 | $request->all(), |
|
30 | ['name' => 'required|regex:#[A-Za-z0-9][A-Za-z0-9_.-]*/[A-Za-z0-9][A-Za-z0-9_.-]#'], |
|
31 | [ |
|
32 | 'name.required' => 'Package name must be provided.', |
|
33 | 'name.regex' => 'Package name must be in valid format. E.g. organization/package' |
|
34 | ] |
|
35 | ); |
|
36 | ||
37 | if($validator->fails()) { |
|
38 | Response::json($validator->errors()->first('name')) |
|
39 | ->setStatusCode(400) |
|
40 | ->send(); |
|
41 | } else { |
|
42 | try { |
|
43 | $output = $configManager->addOrUpdatePackage($packageId, $input); |
|
44 | ||
45 | Response::json(['command_output' => $output]) |
|
46 | ->send(); |
|
47 | } catch(PackageBuildFailedException $e) { |
|
48 | Response::json() |
|
49 | ->setStatusCode(500) |
|
50 | ->send(); |
|
51 | } catch(RepositoryNotFoundException $e) { |
|
52 | Response::json() |
|
53 | ->setStatusCode(404) |
|
54 | ->send(); |
|
55 | } |
|
56 | } |
|
57 | } |
|
58 | ||
59 | /** |
|
60 | * @param \App\Satis\ConfigManager $configManager |
|
61 | * @param string|null $packageId |
|
62 | */ |
|
63 | public function get(ConfigManager $configManager, $packageId = null) { |
|
64 | try { |
|
65 | $repositories = $configManager->getPackages($packageId); |
|
66 | ||
67 | Response::make($repositories) |
|
68 | ->send(); |
|
69 | } catch(RepositoryNotFoundException $e) { |
|
70 | Response::json() |
|
71 | ->setStatusCode(404) |
|
72 | ->send(); |
|
73 | } catch(PackageBuildFailedException $e) { |
|
74 | Response::json($e->getMessage()) |
|
75 | ->setStatusCode(500) |
|
76 | ->send(); |
|
77 | } |
|
78 | } |
|
79 | ||
80 | /** |
|
81 | * @param \Illuminate\Http\Request $request |
|
82 | * @param \App\Satis\ConfigManager $configManager |
|
83 | * |
|
84 | * @throws \HttpInvalidParamException |
|
85 | */ |
|
86 | public function add(Request $request, ConfigManager $configManager) { |
|
87 | $this->addOrUpdatePackage($request, $configManager, null); |
|
88 | } |
|
89 | ||
90 | /** |
|
91 | * @param \Illuminate\Http\Request $request |
|
92 | * @param \App\Satis\ConfigManager $configManager |
|
93 | * @param string $packageId |
|
94 | * |
|
95 | * @throws \HttpInvalidParamException |
|
96 | */ |
|
97 | public function update(Request $request, ConfigManager $configManager, $packageId) { |
|
98 | $this->addOrUpdatePackage($request, $configManager, $packageId); |
|
99 | } |
|
100 | ||
101 | /** |
|
102 | * @param \App\Satis\ConfigManager $configManager |
|
103 | * @param string $packageId |
|
104 | */ |
|
105 | public function delete(ConfigManager $configManager, $packageId) { |
|
106 | try { |
|
107 | $configManager->deletePackage($packageId); |
|
108 | ||
109 | Response::json() |
|
110 | ->send(); |
|
111 | } catch(RepositoryNotFoundException $e) { |
|
112 | Response::json() |
|
113 | ->setStatusCode(404) |
|
114 | ->send(); |
|
115 | } catch(PackageBuildFailedException $e) { |
|
116 | Response::json($e->getMessage()) |
|
117 | ->setStatusCode(500) |
|
118 | ->send(); |
|
119 | } |
|
120 | } |
|
121 | } |
|
122 |
@@ 18-121 (lines=104) @@ | ||
15 | /** |
|
16 | * @author Lukas Homza <[email protected]> |
|
17 | */ |
|
18 | class RepositoryController extends BaseController { |
|
19 | /** |
|
20 | * @param \Illuminate\Http\Request $request |
|
21 | * @param \App\Satis\ConfigManager $configManager |
|
22 | * @param string|null $repositoryId |
|
23 | * |
|
24 | * @throws \HttpInvalidParamException |
|
25 | */ |
|
26 | protected function addOrUpdateRepository(Request $request, ConfigManager $configManager, $repositoryId = null) { |
|
27 | $input = new Collection($request->all()); |
|
28 | ||
29 | $validator = Validator::make( |
|
30 | $request->all(), |
|
31 | ['url' => 'required'], |
|
32 | [ |
|
33 | 'url.required' => 'Repository url must be provided.' |
|
34 | ] |
|
35 | ); |
|
36 | ||
37 | if($validator->fails()) { |
|
38 | Response::json($validator->errors()->first('url')) |
|
39 | ->setStatusCode(400) |
|
40 | ->send(); |
|
41 | } else { |
|
42 | try { |
|
43 | $output = $configManager->addOrUpdateRepository($repositoryId, $input); |
|
44 | ||
45 | Response::json(['command_output' => $output]) |
|
46 | ->send(); |
|
47 | } catch(PackageBuildFailedException $e) { |
|
48 | Response::json() |
|
49 | ->setStatusCode(500) |
|
50 | ->send(); |
|
51 | } catch(RepositoryNotFoundException $e) { |
|
52 | Response::json() |
|
53 | ->setStatusCode(404) |
|
54 | ->send(); |
|
55 | } |
|
56 | } |
|
57 | } |
|
58 | ||
59 | /** |
|
60 | * @param \App\Satis\ConfigManager $configManager |
|
61 | * @param string|null $repositoryId |
|
62 | */ |
|
63 | public function get(ConfigManager $configManager, $repositoryId = null) { |
|
64 | try { |
|
65 | $repositories = $configManager->getRepositories($repositoryId); |
|
66 | ||
67 | Response::make($repositories) |
|
68 | ->send(); |
|
69 | } catch(RepositoryNotFoundException $e) { |
|
70 | Response::json() |
|
71 | ->setStatusCode(404) |
|
72 | ->send(); |
|
73 | } catch(PackageBuildFailedException $e) { |
|
74 | Response::json($e->getMessage()) |
|
75 | ->setStatusCode(500) |
|
76 | ->send(); |
|
77 | } |
|
78 | } |
|
79 | ||
80 | /** |
|
81 | * @param \Illuminate\Http\Request $request |
|
82 | * @param \App\Satis\ConfigManager $configManager |
|
83 | * |
|
84 | * @throws \HttpInvalidParamException |
|
85 | */ |
|
86 | public function add(Request $request, ConfigManager $configManager) { |
|
87 | $this->addOrUpdateRepository($request, $configManager, null); |
|
88 | } |
|
89 | ||
90 | /** |
|
91 | * @param \Illuminate\Http\Request $request |
|
92 | * @param \App\Satis\ConfigManager $configManager |
|
93 | * @param string $repositoryId |
|
94 | * |
|
95 | * @throws \HttpInvalidParamException |
|
96 | */ |
|
97 | public function update(Request $request, ConfigManager $configManager, $repositoryId) { |
|
98 | $this->addOrUpdateRepository($request, $configManager, $repositoryId); |
|
99 | } |
|
100 | ||
101 | /** |
|
102 | * @param \App\Satis\ConfigManager $configManager |
|
103 | * @param string $repositoryId |
|
104 | */ |
|
105 | public function delete(ConfigManager $configManager, $repositoryId) { |
|
106 | try { |
|
107 | $configManager->deleteRepository($repositoryId); |
|
108 | ||
109 | Response::json() |
|
110 | ->send(); |
|
111 | } catch(RepositoryNotFoundException $e) { |
|
112 | Response::json() |
|
113 | ->setStatusCode(404) |
|
114 | ->send(); |
|
115 | } catch(PackageBuildFailedException $e) { |
|
116 | Response::json($e->getMessage()) |
|
117 | ->setStatusCode(500) |
|
118 | ->send(); |
|
119 | } |
|
120 | } |
|
121 | } |
|
122 |