toDo change order
This commit is contained in:
@@ -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',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 <https://lodash.com/>
|
||||
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
|
||||
* Released under MIT license <https://lodash.com/license>
|
||||
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
||||
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
||||
*/
|
||||
|
||||
/**
|
||||
* vuex v3.1.3
|
||||
* (c) 2020 Evan You
|
||||
* @license MIT
|
||||
*/
|
||||
@@ -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');
|
||||
|
||||
});
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user