refactor items table
This commit is contained in:
parent
836fb96f42
commit
8ab469e017
4 changed files with 56 additions and 22 deletions
|
@ -38,7 +38,7 @@ class ItemController extends Controller
|
|||
public function showOneItem($event, $id)
|
||||
{
|
||||
$eid = Event::where('slug','=',$event)->first()->eid;
|
||||
return response()->json(Item::byEvent($eid)->where('item_uid', '=', $id)->first());
|
||||
return response()->json(Item::byEvent($eid)->where('uid', '=', $id)->first());
|
||||
}
|
||||
|
||||
public function create($event, Request $request)
|
||||
|
@ -46,8 +46,6 @@ class ItemController extends Controller
|
|||
$eid = Event::where('slug','=',$event)->first()->eid;
|
||||
$newitem = $request->except(['dataImage']);
|
||||
$newitem['eid'] = "".$eid;
|
||||
$newitem['wo'] = "";
|
||||
$newitem['wann'] = "";
|
||||
$item = Item::create($newitem);
|
||||
|
||||
if ($request->get('dataImage')) {
|
||||
|
@ -69,7 +67,7 @@ class ItemController extends Controller
|
|||
public function update($event, $id, Request $request)
|
||||
{
|
||||
$eid = Event::where('slug', $event)->first()->eid;
|
||||
$item = Item::where('eid', $eid)->where('item_uid', $id)->first();
|
||||
$item = Item::where('eid', $eid)->where('uid', $id)->first();
|
||||
$item->update($request->except(['file', 'box', 'dataImage']));
|
||||
|
||||
if($request->get('returned')===true){
|
||||
|
@ -89,13 +87,13 @@ class ItemController extends Controller
|
|||
$item['file'] = $hash;
|
||||
}
|
||||
}
|
||||
return response()->json(Item::find($item['item_uid']), 200);
|
||||
return response()->json(Item::find($item['uid']), 200);
|
||||
}
|
||||
|
||||
public function delete($event, $id)
|
||||
{
|
||||
$eid = Event::where('slug','=',$event)->first()->eid;
|
||||
Item::where('eid', $eid)->where('item_uid', $id)->first()->delete();
|
||||
Item::where('eid', $eid)->where('uid', $id)->first()->delete();
|
||||
return response()->json(array("status"=>'Deleted Successfully'), 200);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ class Item extends Model
|
|||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'iid', 'item_uid', 'description', 'wann', 'wo', 'eid', 'cid', 'returned_at'
|
||||
'iid', 'uid', 'description', 'eid', 'cid', 'returned_at'
|
||||
];
|
||||
|
||||
|
||||
|
@ -26,7 +26,7 @@ class Item extends Model
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = ['created_at','updated_at', 'deleted_at', 'returned_at', 'eid', 'iid', 'wann', 'wo'];
|
||||
protected $hidden = ['created_at','updated_at', 'deleted_at', 'returned_at', 'eid', 'iid'];
|
||||
|
||||
public static function restored($callback)
|
||||
{
|
||||
|
@ -34,8 +34,8 @@ class Item extends Model
|
|||
|
||||
public static function create(array $attributes = [])
|
||||
{
|
||||
$uid = static::query()->where('eid',$attributes['eid'])->max('item_uid') + 1;
|
||||
$attributes['item_uid'] = $uid;
|
||||
$uid = static::query()->where('eid',$attributes['eid'])->max('uid') + 1;
|
||||
$attributes['uid'] = $uid;
|
||||
static::query()->create($attributes);
|
||||
return Item::find($uid);
|
||||
}
|
||||
|
|
36
database/migrations/2020_01_18_212520_cleanup_tables.php
Normal file
36
database/migrations/2020_01_18_212520_cleanup_tables.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CleanupTables extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('items', function (Blueprint $table) {
|
||||
$table->dropColumn('wo');
|
||||
});
|
||||
Schema::table('items', function (Blueprint $table) {
|
||||
$table->dropColumn('wann');
|
||||
});
|
||||
Schema::table('items', function (Blueprint $table) {
|
||||
$table->renameColumn('item_uid','uid');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
|
@ -32,7 +32,7 @@ class ItemTest extends TestCase
|
|||
|
||||
$this->assertResponseOk();
|
||||
$this->assertEquals(1, count($response));
|
||||
$this->assertEquals(1, $response[0]['item_uid']);
|
||||
$this->assertEquals(1, $response[0]['uid']);
|
||||
$this->assertEquals('1', $response[0]['description']);
|
||||
$this->assertEquals($box->name, $response[0]['box']);
|
||||
$this->assertEquals($box->cid, $response[0]['cid']);
|
||||
|
@ -51,7 +51,7 @@ class ItemTest extends TestCase
|
|||
|
||||
$this->assertResponseOk();
|
||||
$this->assertEquals(1, count($response));
|
||||
$this->assertEquals(1, $response[0]['item_uid']);
|
||||
$this->assertEquals(1, $response[0]['uid']);
|
||||
$this->assertEquals('1', $response[0]['description']);
|
||||
$this->assertEquals($box->name, $response[0]['box']);
|
||||
$this->assertEquals($box->cid, $response[0]['cid']);
|
||||
|
@ -81,7 +81,7 @@ class ItemTest extends TestCase
|
|||
$response = $this->response->getOriginalContent();
|
||||
|
||||
$this->assertResponseStatus(201);
|
||||
$this->assertEquals(1, $response['item_uid']);
|
||||
$this->assertEquals(1, $response['uid']);
|
||||
$this->assertEquals('1', $response['description']);
|
||||
$this->assertEquals($box->name, $response['box']);
|
||||
$this->assertEquals($box->cid, $response['cid']);
|
||||
|
@ -89,7 +89,7 @@ class ItemTest extends TestCase
|
|||
|
||||
$items = Item::all();
|
||||
$this->assertEquals(1, count($items));
|
||||
$this->assertEquals(1, $items[0]['item_uid']);
|
||||
$this->assertEquals(1, $items[0]['uid']);
|
||||
$this->assertEquals('1', $items[0]['description']);
|
||||
$this->assertEquals($box->name, $items[0]['box']);
|
||||
$this->assertEquals($box->cid, $items[0]['cid']);
|
||||
|
@ -112,15 +112,15 @@ class ItemTest extends TestCase
|
|||
$box = Container::create(['name'=>'BOX']);
|
||||
$item = Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'wann'=>'', 'wo'=>'','description'=>'1']);
|
||||
|
||||
$this->assertEquals(1, $item['item_uid']);
|
||||
$this->assertEquals(1, $item['uid']);
|
||||
$this->assertEquals('1', $item['description']);
|
||||
$this->assertEquals($box->cid, $item['cid']);
|
||||
|
||||
$this->put('/1/EVENT/item/'.$item->item_uid,['description'=>'2']);
|
||||
$this->put('/1/EVENT/item/'.$item->uid,['description'=>'2']);
|
||||
$response = $this->response->getOriginalContent();
|
||||
|
||||
$this->assertResponseOk();
|
||||
$this->assertEquals(1, $response['item_uid']);
|
||||
$this->assertEquals(1, $response['uid']);
|
||||
$this->assertEquals('2', $response['description']);
|
||||
$this->assertEquals($box->name, $response['box']);
|
||||
$this->assertEquals($box->cid, $response['cid']);
|
||||
|
@ -128,7 +128,7 @@ class ItemTest extends TestCase
|
|||
|
||||
$items = Item::all();
|
||||
$this->assertEquals(1, count($items));
|
||||
$this->assertEquals(1, $items[0]['item_uid']);
|
||||
$this->assertEquals(1, $items[0]['uid']);
|
||||
$this->assertEquals('2', $items[0]['description']);
|
||||
$this->assertEquals($box->name, $items[0]['box']);
|
||||
$this->assertEquals($box->cid, $items[0]['cid']);
|
||||
|
@ -143,7 +143,7 @@ class ItemTest extends TestCase
|
|||
|
||||
$this->assertEquals(2, count(Item::all()));
|
||||
|
||||
$this->delete('/1/EVENT/item/'.$item->item_uid);
|
||||
$this->delete('/1/EVENT/item/'.$item->uid);
|
||||
|
||||
$this->assertResponseOk();
|
||||
$this->assertEquals(1, count(Item::all()));
|
||||
|
@ -158,17 +158,17 @@ class ItemTest extends TestCase
|
|||
|
||||
$this->assertEquals(2, count(Item::all()));
|
||||
|
||||
$this->delete('/1/EVENT/item/'.$item1->item_uid);
|
||||
$this->delete('/1/EVENT/item/'.$item1->uid);
|
||||
|
||||
$this->assertResponseOk();
|
||||
$this->assertEquals(1, count(Item::all()));
|
||||
|
||||
$item3 = Item::create(['cid'=>$box->cid, 'eid' => $event->eid, 'wann'=>'', 'wo'=>'','description'=>'3']);
|
||||
|
||||
$this->assertEquals(3, $item3['item_uid']);
|
||||
$this->assertEquals(3, $item3['uid']);
|
||||
$this->assertEquals(2, count(Item::all()));
|
||||
|
||||
$this->delete('/1/EVENT/item/'.$item2->item_uid);
|
||||
$this->delete('/1/EVENT/item/'.$item2->uid);
|
||||
|
||||
$this->assertResponseOk();
|
||||
$this->assertEquals(1, count(Item::all()));
|
||||
|
|
Loading…
Reference in a new issue