From 39aa8530424310663c888f9e02224158961532e3 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Tue, 30 Oct 2018 18:41:29 +0100 Subject: PHP is crap --- api/Posts/Console/AddPostCommand.php | 59 ----------------- api/Posts/Controllers/PostController.php | 57 ----------------- api/Posts/Events/PostWasCreated.php | 16 ----- api/Posts/Events/PostWasDeleted.php | 16 ----- api/Posts/Events/PostWasUpdated.php | 16 ----- api/Posts/Exceptions/PostNotFoundException.php | 13 ---- api/Posts/Models/MediaPost.php | 28 --------- api/Posts/Models/Post.php | 41 ------------ api/Posts/Models/PostType.php | 19 ------ api/Posts/Models/TextPost.php | 28 --------- api/Posts/PostServiceProvider.php | 23 ------- api/Posts/Repositories/PostRepository.php | 60 ------------------ api/Posts/Requests/CreatePostRequest.php | 30 --------- api/Posts/Services/PostService.php | 87 -------------------------- api/Posts/routes.php | 7 --- 15 files changed, 500 deletions(-) delete mode 100644 api/Posts/Console/AddPostCommand.php delete mode 100644 api/Posts/Controllers/PostController.php delete mode 100644 api/Posts/Events/PostWasCreated.php delete mode 100644 api/Posts/Events/PostWasDeleted.php delete mode 100644 api/Posts/Events/PostWasUpdated.php delete mode 100644 api/Posts/Exceptions/PostNotFoundException.php delete mode 100644 api/Posts/Models/MediaPost.php delete mode 100644 api/Posts/Models/Post.php delete mode 100644 api/Posts/Models/PostType.php delete mode 100644 api/Posts/Models/TextPost.php delete mode 100644 api/Posts/PostServiceProvider.php delete mode 100644 api/Posts/Repositories/PostRepository.php delete mode 100644 api/Posts/Requests/CreatePostRequest.php delete mode 100644 api/Posts/Services/PostService.php delete mode 100644 api/Posts/routes.php (limited to 'api/Posts') diff --git a/api/Posts/Console/AddPostCommand.php b/api/Posts/Console/AddPostCommand.php deleted file mode 100644 index 977afb6..0000000 --- a/api/Posts/Console/AddPostCommand.php +++ /dev/null @@ -1,59 +0,0 @@ -postRepository = $postRepository; - } - - /** - * Execute the console command. - * - * @return mixed - */ - public function handle() - { - $post = $this->postRepository->create([ - 'name' => $this->argument('name'), - 'email' => $this->argument('email'), - 'password' => $this->argument('password') - ]); - - $this->info(sprintf('A post was created with ID %s', $post->id)); - } -} \ No newline at end of file diff --git a/api/Posts/Controllers/PostController.php b/api/Posts/Controllers/PostController.php deleted file mode 100644 index 105c7c2..0000000 --- a/api/Posts/Controllers/PostController.php +++ /dev/null @@ -1,57 +0,0 @@ -postService = $postService; - } - - public function getAll() - { - $resourceOptions = $this->parseResourceOptions(); - - $data = $this->postService->getAll($resourceOptions); - $parsedData = $this->parseData($data, $resourceOptions, 'posts'); - - return $this->response($parsedData); - } - - public function getById($postId) - { - $resourceOptions = $this->parseResourceOptions(); - - $data = $this->postService->getById($postId, $resourceOptions); - $parsedData = $this->parseData($data, $resourceOptions, 'post'); - - return $this->response($parsedData); - } - - public function create(CreatePostRequest $request) - { - $data = $request->get('post', []); - - return $this->response($this->postService->create($data), 201); - } - - public function update($postId, Request $request) - { - $data = $request->get('post', []); - - return $this->response($this->postService->update($postId, $data)); - } - - public function delete($postId) - { - return $this->response($this->postService->delete($postId)); - } -} diff --git a/api/Posts/Events/PostWasCreated.php b/api/Posts/Events/PostWasCreated.php deleted file mode 100644 index 8cdcbf8..0000000 --- a/api/Posts/Events/PostWasCreated.php +++ /dev/null @@ -1,16 +0,0 @@ -post = $post; - } -} diff --git a/api/Posts/Events/PostWasDeleted.php b/api/Posts/Events/PostWasDeleted.php deleted file mode 100644 index 5def797..0000000 --- a/api/Posts/Events/PostWasDeleted.php +++ /dev/null @@ -1,16 +0,0 @@ -post = $post; - } -} diff --git a/api/Posts/Events/PostWasUpdated.php b/api/Posts/Events/PostWasUpdated.php deleted file mode 100644 index 441e884..0000000 --- a/api/Posts/Events/PostWasUpdated.php +++ /dev/null @@ -1,16 +0,0 @@ -post = $post; - } -} diff --git a/api/Posts/Exceptions/PostNotFoundException.php b/api/Posts/Exceptions/PostNotFoundException.php deleted file mode 100644 index 2f9c55d..0000000 --- a/api/Posts/Exceptions/PostNotFoundException.php +++ /dev/null @@ -1,13 +0,0 @@ -belongsTo('Api\Posts\Models\Post'); - } -} diff --git a/api/Posts/Models/Post.php b/api/Posts/Models/Post.php deleted file mode 100644 index b907808..0000000 --- a/api/Posts/Models/Post.php +++ /dev/null @@ -1,41 +0,0 @@ -belongsTo('Api\Users\Models\User'); - } - - public function post_type() - { - return $this->belongsTo('Api\Posts\Models\PostType', 'post_types_id', 'id'); - } - - public function media_post() - { - return $this->hasOne('Api\Posts\Models\MediaPost'); - } - - public function text_post() - { - return $this->hasOne('Api\Posts\Models\TextPost'); - } -} diff --git a/api/Posts/Models/PostType.php b/api/Posts/Models/PostType.php deleted file mode 100644 index de8d0f3..0000000 --- a/api/Posts/Models/PostType.php +++ /dev/null @@ -1,19 +0,0 @@ -hasMany('Api\Posts\Models\Post', 'post_types_id', 'id'); - } -} diff --git a/api/Posts/Models/TextPost.php b/api/Posts/Models/TextPost.php deleted file mode 100644 index 30593a1..0000000 --- a/api/Posts/Models/TextPost.php +++ /dev/null @@ -1,28 +0,0 @@ -belongsTo('Api\Posts\Models\Post'); - } -} diff --git a/api/Posts/PostServiceProvider.php b/api/Posts/PostServiceProvider.php deleted file mode 100644 index 181b308..0000000 --- a/api/Posts/PostServiceProvider.php +++ /dev/null @@ -1,23 +0,0 @@ - [ - // listeners for when a post is created - ], - PostWasDeleted::class => [ - // listeners for when a post is deleted - ], - PostWasUpdated::class => [ - // listeners for when a post is updated - ] - ]; -} diff --git a/api/Posts/Repositories/PostRepository.php b/api/Posts/Repositories/PostRepository.php deleted file mode 100644 index c554e82..0000000 --- a/api/Posts/Repositories/PostRepository.php +++ /dev/null @@ -1,60 +0,0 @@ -with('post_type'); - $this->applyResourceOptions($query, $options); - $posts = $query->get(); - $joinedPosts = []; - - foreach ($posts as $post) { - $postType = 'Api\Posts\Models\\' . $post["post_type"]["type"] . 'Post'; - $postTypeClass = new $postType(); - $post["post"] = $postTypeClass::query()->where('id', $post->id)->first(); - array_push($joinedPosts, $post); - } - return $joinedPosts; - } - - public function getJoinedById($postId) - { - $query = Post::query()->with('post_type')->where('id', $postId); - $post = $query->first(); - - $postType = 'Api\Posts\Models\\' . $post["post_type"]["type"] . 'Post'; - $postTypeClass = new $postType(); - $post["post"] = $postTypeClass::query()->where('id', $post["id"])->first(); - return $post; - } - - public function create(array $data) - { - $post = $this->getModel(); - - $post->fill($data); - $post->save(); - - return $post; - } - - public function update(Post $post, array $data) - { - $post->fill($data); - - $post->save(); - - return $post; - } -} diff --git a/api/Posts/Requests/CreatePostRequest.php b/api/Posts/Requests/CreatePostRequest.php deleted file mode 100644 index be777ac..0000000 --- a/api/Posts/Requests/CreatePostRequest.php +++ /dev/null @@ -1,30 +0,0 @@ - 'array|required', - 'post.email' => 'required|email', - 'post.name' => 'required|string', - 'post.password' => 'required|string|min:8' - ]; - } - - public function attributes() - { - return [ - 'post.email' => 'the post\'s email' - ]; - } -} diff --git a/api/Posts/Services/PostService.php b/api/Posts/Services/PostService.php deleted file mode 100644 index 0232af2..0000000 --- a/api/Posts/Services/PostService.php +++ /dev/null @@ -1,87 +0,0 @@ -auth = $auth; - $this->database = $database; - $this->dispatcher = $dispatcher; - $this->postRepository = $postRepository; - } - - public function getAll($options = []) - { - return $this->postRepository->getJoined($options); - } - - public function getById($postId, array $options = []) - { - $post = $this->getRequestedPost($postId); - - return $post; - } - - public function create($data) - { - $post = $this->postRepository->create($data); - - $this->dispatcher->fire(new PostWasCreated($post)); - - return $post; - } - - public function update($postId, array $data) - { - $post = $this->getRequestedPost($postId); - - $this->postRepository->update($post, $data); - - $this->dispatcher->fire(new PostWasUpdated($post)); - - return $post; - } - - public function delete($postId) - { - $post = $this->getRequestedPost($postId); - - $this->postRepository->delete($postId); - - $this->dispatcher->fire(new PostWasDeleted($post)); - } - - private function getRequestedPost($postId) - { - $post = $this->postRepository->getJoinedById($postId); - - if (is_null($post)) { - throw new PostNotFoundException(); - } - - return $post; - } -} diff --git a/api/Posts/routes.php b/api/Posts/routes.php deleted file mode 100644 index c3b90e4..0000000 --- a/api/Posts/routes.php +++ /dev/null @@ -1,7 +0,0 @@ -get('/posts', 'PostController@getAll'); -$router->get('/posts/{id}', 'PostController@getById'); -$router->post('/posts', 'PostController@create'); -$router->put('/posts/{id}', 'PostController@update'); -$router->delete('/posts/{id}', 'PostController@delete'); -- cgit v1.2.3