Skip to content

Commit

Permalink
Merge branch 'develop' into develop-miroc
Browse files Browse the repository at this point in the history
* develop:
  refaktor app config singleton
  #110 add multiple status to stand
  • Loading branch information
miroc committed Aug 16, 2017
2 parents 4816886 + b4b6e86 commit 7d8b409
Show file tree
Hide file tree
Showing 21 changed files with 120 additions and 47 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
3 changes: 2 additions & 1 deletion app/Domain/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use BikeShare\Domain\Bike\Bike;
use BikeShare\Domain\Core\Uuid;
use BikeShare\Domain\Rent\RentStatus;
use BikeShare\Http\Services\AppConfig;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
Expand Down Expand Up @@ -64,7 +65,7 @@ class User extends Authenticatable implements JWTSubject

public function setCreditAttribute($value)
{
$this->attributes['credit'] = app('AppConfig')->getRequiredCredit() * $value;
$this->attributes['credit'] = app(AppConfig::class)->getRequiredCredit() * $value;
}


Expand Down
3 changes: 2 additions & 1 deletion app/Domain/User/UserTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use BikeShare\Domain\Bike\BikeTransformer;
use BikeShare\Domain\Rent\RentTransformer;
use BikeShare\Http\Services\AppConfig;
use League\Fractal\TransformerAbstract;

class UserTransformer extends TransformerAbstract
Expand All @@ -24,7 +25,7 @@ public function transform(User $user)
'email' => $user->email,
'note' => $user->note,
'credit' => $user->credit,
'credit_currency' => app('AppConfig')->getCreditCurrency(),
'credit_currency' => app(AppConfig::class)->getCreditCurrency(),
'recommendation' => $user->recommendation,
'limit' => $user->limit,
'locked' => $user->locked,
Expand Down
3 changes: 2 additions & 1 deletion app/Domain/User/UsersRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use App;
use BikeShare\Domain\Core\Repository;
use BikeShare\Http\Services\AppConfig;
use Illuminate\Support\Str;

class UsersRepository extends Repository
Expand Down Expand Up @@ -30,7 +31,7 @@ public function getUsersWithRole($role)
public function create(array $data)
{
$data['limit'] = 1;
if (app('AppConfig')->isCreditEnabled()) {
if (app(AppConfig::class)->isCreditEnabled()) {
$data['credit'] = 0;
}
$data['locked'] = 0;
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/Api/v1/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use BikeShare\Domain\User\UsersRepository;
use BikeShare\Domain\User\UserTransformer;
use BikeShare\Http\Controllers\Api\v1\Controller;
use BikeShare\Http\Services\AppConfig;
use BikeShare\Notifications\RegisterConfirmationNotification;
use Illuminate\Http\Request;

Expand Down Expand Up @@ -61,7 +62,7 @@ public function agree($token)
if (! $user = $this->userRepo->findBy('confirmation_token', $token)) {
return $this->response->errorBadRequest('Bad token');
}
$user->limit = app('AppConfig')->getRegistrationLimits();
$user->limit = app(AppConfig::class)->getRegistrationLimits();
$user->confirmation_token = null;
$user->save();

Expand Down
9 changes: 5 additions & 4 deletions app/Http/Controllers/Api/v1/Coupons/CouponsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use BikeShare\Domain\Coupon\CouponTransformer;
use BikeShare\Domain\Coupon\Requests\CreateCouponRequest;
use BikeShare\Http\Controllers\Api\v1\Controller;
use BikeShare\Http\Services\AppConfig;

class CouponsController extends Controller
{
Expand All @@ -30,11 +31,11 @@ public function index()

public function store(CreateCouponRequest $request)
{
if (! app('AppConfig')->isCreditEnabled()) {
if (! app(AppConfig::class)->isCreditEnabled()) {
return $this->response->error('Credit is not enabled', 409);
}

$value = app('AppConfig')->getRequiredCredit() * $request->get('multiplier');
$value = app(AppConfig::class)->getRequiredCredit() * $request->get('multiplier');

$count = $request->has('count') ? $request->get('count') : 10;
$codes = $this->couponRepo->generateCodes($count);
Expand Down Expand Up @@ -69,7 +70,7 @@ public function show($uuid)

public function sell($uuid)
{
if (! app('AppConfig')->isCreditEnabled()) {
if (! app(AppConfig::class)->isCreditEnabled()) {
return $this->response->error('Credit is not enabled', 409);
}

Expand All @@ -90,7 +91,7 @@ public function sell($uuid)

public function validateCoupon($uuid)
{
if (! app('AppConfig')->isCreditEnabled()) {
if (! app(AppConfig::class)->isCreditEnabled()) {
return $this->response->error('Credit is not enabled', 409);
}

Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Api/v1/Rents/RentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use BikeShare\Http\Services\Rents\Exceptions\RentException;
use BikeShare\Http\Services\Rents\Exceptions\RentExceptionType as ER;
use BikeShare\Http\Services\Rents\RentService;
use BikeShare\Http\Services\AppConfig;
use BikeShare\Notifications\NoteCreated;
use Illuminate\Http\Request;
use Notification;
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
26 changes: 13 additions & 13 deletions app/Http/Services/Rents/RentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,35 +153,35 @@ public function closeRentLog()

public function updateCredit()
{
if (! app('AppConfig')->isCreditEnabled()) {
if (! app(AppConfig::class)->isCreditEnabled()) {
return $this;
}

$realRentCredit = 0;
$timeDiff = $this->rent->started_at->diffInMinutes($this->rent->ended_at);

$freeTime = app('AppConfig')->getFreeTime();
$rentCredit = app('AppConfig')->getRentCredit();
$freeTime = app(AppConfig::class)->getFreeTime();
$rentCredit = app(AppConfig::class)->getRentCredit();
if ($timeDiff > $freeTime) {
$realRentCredit += $rentCredit;
}

// after first paid period, i.e. free_time * 2; if price_cycle enabled
$priceCycle = app('AppConfig')->getPriceCycle();
$priceCycle = app(AppConfig::class)->getPriceCycle();
if ($priceCycle) {
if ($timeDiff > $freeTime * 2) {
$tempTimeDiff = $timeDiff - ($freeTime * 2);

if ($priceCycle == 1) { // flat price per cycle
$cycles = ceil($tempTimeDiff / app('AppConfig')->getFlatPriceCycle());
$cycles = ceil($tempTimeDiff / app(AppConfig::class)->getFlatPriceCycle());
$realRentCredit += ($rentCredit * $cycles);
} elseif ($priceCycle == 2) { // double price per cycle
$cycles = ceil($tempTimeDiff / app('AppConfig')->getDoublePriceCycle());
$cycles = ceil($tempTimeDiff / app(AppConfig::class)->getDoublePriceCycle());
$tmpCreditRent = $rentCredit;

for ($i = 1; $i <= $cycles; $i++) {
$multiplier = $i;
$doublePriceCycleCap = app('AppConfig')->getDoublePriceCycleCap();
$doublePriceCycleCap = app(AppConfig::class)->getDoublePriceCycleCap();

if ($multiplier > $doublePriceCycleCap) {
$multiplier = $doublePriceCycleCap;
Expand All @@ -196,8 +196,8 @@ public function updateCredit()
}
}

if ($timeDiff > app('AppConfig')->getWatchersLongRental() * 60) {
$realRentCredit += app('AppConfig')->getCreditLongRental();
if ($timeDiff > app(AppConfig::class)->getWatchersLongRental() * 60) {
$realRentCredit += app(AppConfig::class)->getCreditLongRental();
}

$this->rent->credit = $realRentCredit;
Expand Down Expand Up @@ -232,8 +232,8 @@ public function checkLongRent()
$rents = app(RentsRepository::class)->findWhere(['status' => RentStatus::OPEN]);

foreach ($rents as $rent) {
if ($rent->started_at->addHours(app('AppConfig')->getWatchersLongRental())->isPast()) {
if (app('AppConfig')->isNotifyUser()) {
if ($rent->started_at->addHours(app(AppConfig::class)->getWatchersLongRental())->isPast()) {
if (app(AppConfig::class)->isNotifyUser()) {
// TODO send notification (sms, email ?) to user about long rental
}
}
Expand All @@ -245,8 +245,8 @@ public function checkLongRent()

public function checkManyRents(User $user = null)
{
$timeToMany = app('AppConfig')->getTimeToMany();
$numberToMany = app('AppConfig')->getNumberToMany();
$timeToMany = app(AppConfig::class)->getTimeToMany();
$numberToMany = app(AppConfig::class)->getNumberToMany();
if ($user) {
$users = collect($user);
} else {
Expand Down
5 changes: 3 additions & 2 deletions app/Notifications/RegisterConfirmationNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace BikeShare\Notifications;

use BikeShare\Domain\User\User;
use BikeShare\Http\Services\AppConfig;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
Expand Down Expand Up @@ -43,13 +44,13 @@ public function via($notifiable)
*/
public function toMail($notifiable)
{
$ruleUrl = app('AppConfig')->getSystemRules();
$ruleUrl = app(AppConfig::class)->getSystemRules();
$agreeUrl = url('/api/auth/agree/' . $notifiable->confirmation_token);

return (new MailMessage)
->subject('Registration')
->greeting("Hello, $notifiable->name!")
->line('you have been registered into community bike share system ' . app('AppConfig')->getSystemName())
->line('you have been registered into community bike share system ' . app(AppConfig::class)->getSystemName())
->line('')
->line('System rules are available here:')
->line($ruleUrl)
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)
Loading

0 comments on commit 7d8b409

Please sign in to comment.