Skip to content

Commit

Permalink
#110 add multiple status to stand
Browse files Browse the repository at this point in the history
  • Loading branch information
jozefbalun committed Aug 14, 2017
1 parent 9294fa1 commit ecdb4a0
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 22 deletions.
5 changes: 2 additions & 3 deletions app/Domain/Stand/Stand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,21 @@ class Stand extends Model

public $table = 'stands';

public $fillable = ['name', 'descriptions', 'photo', 'place_name', 'note', 'service_tag', 'latitude', 'longitude'];
public $fillable = ['name', 'descriptions', 'photo', 'place_name', 'note', 'status', 'latitude', 'longitude'];

protected static $logAttributes = [
'name',
'descriptions',
'photo',
'place_name',
'service_tag',
'status',
'latitude',
'longitude',
];

public $dates = ['deleted_at'];

public $casts = [
'service_tag' => 'boolean',
'latitude' => 'decimal',
'longitude' => 'decimal',
];
Expand Down
23 changes: 23 additions & 0 deletions app/Domain/Stand/StandStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace BikeShare\Domain\Stand;

use ReflectionClass;

class StandStatus
{

const ACTIVE = 'active';
const INACTIVE = 'inactive';
const ACTIVE_SERVICE_RETURN_ONLY = 'active_service_return_only';
const ACTIVE_RENT_ONLY = 'active_rent_only';
const ACTIVE_RETURN_ONLY = 'active_return_only';


public function toArray()
{
$constants = (new ReflectionClass(self::class))->getConstants();

return $constants;
}
}
2 changes: 1 addition & 1 deletion app/Domain/Stand/StandTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function transform(Stand $stand)
'photo' => $stand->photo,
'description' => $stand->description,
'place_name' => $stand->place_name,
'service_tag' => $stand->service_tag,
'status' => $stand->status,
'distance' => $stand->distance ? round($stand->distance * 1000) : null,
];
}
Expand Down
6 changes: 2 additions & 4 deletions app/Http/Controllers/Stands/StandsApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
namespace BikeShare\Http\Controllers\Stands;

use BikeShare\Domain\Bike\BikeStatus;
use BikeShare\Domain\Stand\Requests\CreateStandRequest;
use BikeShare\Domain\Stand\Requests\UpdateStandRequest;
use BikeShare\Domain\Stand\StandsRepository;
use BikeShare\Http\Controllers\Controller;
use Illuminate\Http\Request;
use BikeShare\Http\Requests;

class StandsApiController extends Controller
{
Expand Down Expand Up @@ -36,9 +33,10 @@ public function index()
/**
* Display the specified resource.
*
* @param int $uuid
* @param $slug
*
* @return \Illuminate\Http\Response
*
*/
public function show($slug)
{
Expand Down
19 changes: 14 additions & 5 deletions app/Http/Controllers/Stands/StandsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use BikeShare\Domain\Bike\BikeStatus;
use BikeShare\Domain\Stand\Requests\CreateStandRequest;
use BikeShare\Domain\Stand\Requests\UpdateStandRequest;
use BikeShare\Domain\Stand\StandService;
use BikeShare\Domain\Stand\StandsRepository;
use BikeShare\Domain\Stand\StandStatus;
use BikeShare\Http\Controllers\Controller;
use Illuminate\Http\Request;
use BikeShare\Http\Requests;
Expand Down Expand Up @@ -47,7 +49,9 @@ public function index()
*/
public function create()
{
return view('stands.create');
return view('stands.create', [
'statuses' => with(new StandStatus())->toArray(),
]);
}


Expand Down Expand Up @@ -78,9 +82,11 @@ public function store(CreateStandRequest $request)
public function show($uuid)
{
$stand = $this->standRepo->findByUuid($uuid);
$bikes = $stand->bikes()->with(['rents' => function ($query) {
$query->latest()->with('user')->first();
}])->where('status', BikeStatus::FREE)->get();
$bikes = $stand->bikes()->with([
'rents' => function ($query) {
$query->latest()->with('user')->first();
},
])->where('status', BikeStatus::FREE)->get();

return view('stands.show', [
'stand' => $stand,
Expand All @@ -100,8 +106,11 @@ public function edit($uuid)
{
$stand = $this->standRepo->findByUuid($uuid);

// FORMAT AND SEND STATUSESS TO FE

return view('stands.edit', [
'stand' => $stand,
'statuses' => with(new StandStatus())->toArray(),
]);
}

Expand All @@ -110,7 +119,7 @@ public function edit($uuid)
* Update the specified resource in storage.
*
* @param UpdateStandRequest|Request $request
* @param int $uuid
* @param int $uuid
*
* @return \Illuminate\Http\Response
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class ServiceTagStringInStandsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('stands', function (Blueprint $table) {
$table->dropColumn('service_tag');
$table->string('status')->nullable()->after('place_name');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('stands', function (Blueprint $table) {
$table->dropColumn('status');
$table->boolean('service_tag')->nullable()->after('place_name');
});
}
}
2 changes: 1 addition & 1 deletion resources/docs/_api-data-sources.apib
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
+ photo: null
+ description: dsdsdss
+ place_name: Miletocova
+ service_tag: true (boolean)
+ status: active (string)
+ distance: 190 (number)
2 changes: 1 addition & 1 deletion resources/docs/api-docs.apib
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,5 @@ Closest stands for my current gps location
+ photo: null
+ description: dsdsdss
+ place_name: Miletocova
+ service_tag: true (boolean)
+ status: active (string)
+ distance: 190 (number)
9 changes: 6 additions & 3 deletions resources/views/stands/_form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@

<!-- radio -->
<div class="form-group">
<label>
<input type="checkbox" name="service_tag" id="is-service" class="minimal" value="1" {{ ((($stand->service_tag ?? old('service_tag')) == 1) ? 'checked' : '') }}>
Is service stand ?
<label for="status">
<select name="status" class="form-control" id="status">
@foreach($statuses as $key => $name)
<option value="{{ $key }}" {{ ((($stand->status ?? old("status")) == $key) ? 'selected' : '') }}>{{ $name }}</option>
@endforeach
</select>
</label>
</div>

Expand Down
4 changes: 2 additions & 2 deletions resources/views/stands/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<th>Description</th>
<th>Bikes count</th>
<th>place name</th>
<th>Is service</th>
<th>Status</th>
<th>lat</th>
<th>lng</th>
<th>Action</th>
Expand All @@ -37,7 +37,7 @@
<td>{{ $stand->description }}</td>
<td>{{ $stand->bikes->count() }}</td>
<td>{{ $stand->place_name }}</td>
<td>{{ $stand->service_tag ? 'Yes' : 'No' }}</td>
<td>{{ $stand->status }}</td>
<td>{{ $stand->latitude }}</td>
<td>{{ $stand->longitude }}</td>
<td>
Expand Down
4 changes: 2 additions & 2 deletions routes/web-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
Route::group(['prefix' => 'app.json', 'middleware' => 'auth'], function () {

Route::group(['prefix' => 'stands', 'namespace' => 'Stands'], function () {
Route::get('', 'StandsApiController@index')->name('app.stands.index');
Route::get('{slug}', 'StandsApiController@show')->name('app.stands.show');
Route::get('', 'StandsApiController@index')->name('app.json.stands.index');
Route::get('{slug}', 'StandsApiController@show')->name('app.json.stands.show');
});

Route::group(['prefix' => 'bikes', 'namespace' => 'Bikes'], function () {
Expand Down

0 comments on commit ecdb4a0

Please sign in to comment.