diff --git a/app/Http/Controllers/ToDoController.php b/app/Http/Controllers/ToDoController.php index 892e151..719236d 100644 --- a/app/Http/Controllers/ToDoController.php +++ b/app/Http/Controllers/ToDoController.php @@ -45,11 +45,25 @@ class ToDoController extends Controller return response([], 204); } + public function changeOrder(ToDoList $toDoList, ToDo $toDo) + { + $this->authorize('update', $toDoList); + + $toDoChanged = $toDoList->toDos()->where('order', (int) request()['new-order'])->first(); + + $toDoChanged->update(['order' => (int) $toDo->order]); + $toDo->update(['order' => (int) request()['new-order']]); + + return (new ToDoResource($toDo)) + ->response() + ->setStatusCode(200); + } + private function validateData() { return request()->validate([ 'name' => 'required', - 'order' => 'integer|min:1|max:1000000' + 'order' => 'integer|min:1|max:1000000', ]); } } diff --git a/public/js/app.js.LICENSE.txt b/public/js/app.js.LICENSE.txt deleted file mode 100644 index 26358a1..0000000 --- a/public/js/app.js.LICENSE.txt +++ /dev/null @@ -1,22 +0,0 @@ -/*! - * Vue.js v2.6.11 - * (c) 2014-2019 Evan You - * Released under the MIT License. - */ - -/*! https://mths.be/punycode v1.4.1 by @mathias */ - -/** - * @license - * Lodash - * Copyright OpenJS Foundation and other contributors - * Released under MIT license - * Based on Underscore.js 1.8.3 - * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors - */ - -/** - * vuex v3.1.3 - * (c) 2020 Evan You - * @license MIT - */ diff --git a/routes/api.php b/routes/api.php index cb7b5bd..f248b77 100644 --- a/routes/api.php +++ b/routes/api.php @@ -31,5 +31,6 @@ Route::middleware('auth:api')->group(function () { Route::post('/images/users/{users}', 'ImageController@users'); Route::post('/images/memos/{memo}', 'ImageController@memos'); + Route::patch('/to-do-lists/{toDoList}/to-do/{toDo}/change', 'ToDoController@changeOrder'); }); diff --git a/tests/Feature/ToDoItemsTest.php b/tests/Feature/ToDoItemsTest.php index 7a93107..f114a3e 100644 --- a/tests/Feature/ToDoItemsTest.php +++ b/tests/Feature/ToDoItemsTest.php @@ -220,6 +220,36 @@ class ToDoItemsTest extends TestCase ->assertStatus(403); } + /** @test */ + public function a_to_do_can_changer_of_order() + { + $this->withoutExceptionHandling(); + $this->actingAs($user = factory(User::class)->create(), 'api'); + $toDoList = factory(ToDoList::class)->create(['id' => 123, 'user_id' => $user->id]); + $this->post('/api/to-do-lists/123/to-do', ['name' => 'Test name to do']); + $toDoReplaced = $this->post('/api/to-do-lists/123/to-do', ['name' => 'Test 2 name to do']); + $this->post('/api/to-do-lists/123/to-do', ['name' => 'Test 3 name to do']); + $this->post('/api/to-do-lists/123/to-do', ['name' => 'Test 4 name to do']); + $todoMove = $this->post('/api/to-do-lists/123/to-do', ['name' => 'Test 5 name to do']); + + + $response = $this->patch('/api/to-do-lists/'. $toDoList->id .'/to-do/'. $todoMove['data']['to_do_id'] .'/change', ['new-order' => $toDoReplaced['data']['attributes']['data']['order']]) + ->assertStatus(200) + ->assertJson([ + 'data' => [ + 'to_do_id' => $todoMove['data']['to_do_id'], + 'attributes' => [ + 'data' => [ + 'order' => $toDoReplaced['data']['attributes']['data']['order'], + ] + ] + ], + 'links' => [ + 'self' => url('/to-do-lists/'. $toDoList->id), + ] + ]); + } + /** @test */ public function a_to_do_list_can_be_delete() {