Skip to content

Commit

Permalink
[RentBook] Add a payment
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsimonbennett committed Jan 1, 2016
1 parent e1230d7 commit 5ac69d8
Show file tree
Hide file tree
Showing 8 changed files with 275 additions and 30 deletions.
4 changes: 4 additions & 0 deletions app/Http/Composer/ComposeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use FullRent\Core\Application\Http\Composer\Dashboard\Properties\DashboardPropertiesIndexComposer;
use FullRent\Core\Application\Http\Composer\Dashboard\Properties\DashboardPropertiesShowComposer;
use FullRent\Core\Application\Http\Composer\Dashboard\Tenancies\DashboardTenanciesShowComposer;
use FullRent\Core\Application\Http\Composer\Dashboard\Tenancies\RentBook\DashboardTenanciesRentBookAddComposer;
use FullRent\Core\Application\Http\Composer\Dashboard\Tenancies\RentBook\DashboardTenanciesRentBookChangeComposer;
use Illuminate\Contracts\View\Factory;
use Illuminate\Support\ServiceProvider;

Expand Down Expand Up @@ -41,6 +43,8 @@ public function boot()
$view->composer('dashboard.properties.edit', DashboardPropertiesEditComposer::class);

$view->composer('dashboard.tenancies.show', DashboardTenanciesShowComposer::class);
$view->composer('dashboard.tenancies.rentbook.add', DashboardTenanciesRentBookAddComposer::class);
$view->composer('dashboard.tenancies.rentbook.change', DashboardTenanciesRentBookChangeComposer::class);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace FullRent\Core\Application\Http\Composer\Dashboard\Tenancies\RentBook;

use FullRent\Core\Application\Http\Composer\Composer;
use Illuminate\Contracts\View\View;
use Illuminate\Routing\Router;

/**
* Class DashboardTenanciesRentBookAddComposer
* @package FullRent\Core\Application\Http\Composer\Dashboard\Tenancies\RentBook
* @author Simon Bennett <simon@bennett.im>
*/
final class DashboardTenanciesRentBookAddComposer implements Composer
{

/** @var Router */
private $router;

/**
* DashboardTenanciesRentBookChangeComposer constructor.
* @param Router $router
*/
public function __construct(Router $router)
{
$this->router = $router;
}

/**
* @param View $view
*/
public function compose(View $view)
{
$view->with('tenancyId', $this->router->current()->parameter('tenancyId'));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
namespace FullRent\Core\Application\Http\Composer\Dashboard\Tenancies\RentBook;

use FullRent\Core\Application\Http\Composer\Composer;
use FullRent\Core\QueryBus\QueryBus;
use FullRent\Core\Tenancy\Queries\FindTenancyRentBookPayment;
use Illuminate\Contracts\View\View;
use Illuminate\Routing\Router;

/**
* Class DashboardTenanciesRentBookChangeComposer
* @package FullRent\Core\Application\Http\Composer\Dashboard\Tenancies\RentBook
* @author Simon Bennett <simon@bennett.im>
*/
final class DashboardTenanciesRentBookChangeComposer implements Composer
{
/** @var QueryBus */
private $queryBus;

/** @var Router */
private $router;

/**
* DashboardTenanciesRentBookChangeComposer constructor.
* @param QueryBus $queryBus
* @param Router $router
*/
public function __construct(QueryBus $queryBus, Router $router)
{
$this->queryBus = $queryBus;
$this->router = $router;
}

/**
* @param View $view
*/
public function compose(View $view)
{
$tenancyId = $this->router->current()->parameter('tenancyId');
$rentPaymentId = $this->router->current()->parameter('rentPaymentId');

$rentPayment = $this->queryBus->query(new FindTenancyRentBookPayment($rentPaymentId));

$view->with(
[
'tenancyId' => $tenancyId,
'rentPaymentId' => $rentPaymentId,
'rentPayment' => $rentPayment
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php
namespace FullRent\Core\Application\Http\Controllers\Tenancies\RentBook;

use FullRent\Core\Application\Http\Controllers\Controller;
use FullRent\Core\Application\Http\Requests\Tenancies\RentBook\ChangeRentBookPaymentInfoRequest;
use FullRent\Core\Tenancy\Commands\AmendScheduledTenancyRentPayment;
use FullRent\Core\Tenancy\Commands\RemoveScheduledRentPayment;
use FullRent\Core\Tenancy\Commands\ScheduleTenancyRentPayment;
use Illuminate\Http\Request;
use SmoothPhp\Contracts\CommandBus\CommandBus;

/**
* Class TenanciesRentBookController
* @package FullRent\Core\Application\Http\Controllers\Tenancies\RentBook
* @author Simon Bennett <simon@bennett.im>
*/
final class TenanciesRentBookController extends Controller
{
/** @var CommandBus */
private $commandBus;

/**
* TenanciesRentBookController constructor.
* @param CommandBus $commandBus
*/
public function __construct(CommandBus $commandBus)
{
$this->commandBus = $commandBus;
}

/**
* @return \Illuminate\View\View
*/
public function change()
{
return view('dashboard.tenancies.rentbook.change');
}

public function add()
{
return view('dashboard.tenancies.rentbook.add');
}


/**
* @param Request $request
* @param $tenancyId
* @return \Illuminate\Http\RedirectResponse
*/
public function addPayment(Request $request, $tenancyId)
{
$this->commandBus->execute(new ScheduleTenancyRentPayment(uuid(),
$tenancyId,
$request->get('rent_amount'),
$request->get('rent_due')));
sleep(2);

return redirect("tenancies/{$tenancyId}#rentbook")
->with($this->notification('Rent Scheduled', 'Your rent payment has been scheduled.'));
}

/**
* @param ChangeRentBookPaymentInfoRequest $request
* @param $tenancyId
* @param $rentPaymentId
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function updateRentPayment(ChangeRentBookPaymentInfoRequest $request, $tenancyId, $rentPaymentId)
{
$this->commandBus->execute(new AmendScheduledTenancyRentPayment($tenancyId,
$rentPaymentId,
$request->get('rent_amount'),
$request->get('rent_due')));

sleep(2);

return redirect("tenancies/{$tenancyId}#rentbook")
->with($this->notification('Rent Updated', 'Your rent payment has been updated'));
}

/**
* @param $tenancyId
* @param $rentPaymentId
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function deleteRentPayment($tenancyId, $rentPaymentId)
{

$this->commandBus->execute(new RemoveScheduledRentPayment($tenancyId, $rentPaymentId));

sleep(2);

return redirect("tenancies/{$tenancyId}#rentbook")
->with($this->notification('Rent Payment Deleted', 'Success the rent payment has been deleted'));
}
}
17 changes: 15 additions & 2 deletions app/Http/Middleware/InjectCompanyMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use FullRent\Core\Application\Http\Models\CompanyModal;
use FullRent\Core\Company\Queries\FindCompanyByDomainQuery;
use FullRent\Core\QueryBus\QueryBus;
use Illuminate\Contracts\Cache\Repository;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
Expand All @@ -23,15 +24,20 @@ final class InjectCompanyMiddleware
/** @var Application */
private $application;

/** @var Repository */
private $cache;

/**
* InjectCompanyMiddleware constructor.
* @param QueryBus $queryBus
* @param Application $application
* @param Repository $cache
*/
public function __construct(QueryBus $queryBus, Application $application)
public function __construct(QueryBus $queryBus, Application $application, Repository $cache)
{
$this->queryBus = $queryBus;
$this->application = $application;
$this->cache = $cache;
}

/**
Expand All @@ -44,7 +50,14 @@ public function __construct(QueryBus $queryBus, Application $application)
public function handle($request, Closure $next)
{

$company = $this->queryBus->query(new FindCompanyByDomainQuery($this->getSubDomain($request)));
$companyName = $this->getSubDomain($request);

$company = $this->cache->remember($companyName . '-check',
5,
function () use ($companyName) {
return $this->queryBus->query(new FindCompanyByDomainQuery($companyName));
}
);

$this->application->bind(CompanyModal::class,
function () use ($company) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
namespace FullRent\Core\Application\Http\Requests\Tenancies\RentBook;

use FullRent\Core\Application\Http\Requests\Request;

/**
* Class ChangeRentBookPaymentInfoRequest
* @package FullRent\Core\Application\Http\Requests\Tenancies\RentBook
* @author Simon Bennett <simon@bennett.im>
*/
final class ChangeRentBookPaymentInfoRequest extends Request
{

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'rent_amount' => 'required',
'rent_due' => 'required|date_format:d/m/Y'
];
}

/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
}
64 changes: 37 additions & 27 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,46 @@
use Illuminate\Routing\Router;


$router->group(['middleware' => 'company'],
$router->group(['middleware' => ['guest', 'company']],
function (Router $router) {
$router->get('auth/login', ['uses' => 'Auth\AuthLoginController@getLogin']);
$router->post('auth/login', ['uses' => 'Auth\AuthLoginController@postLogin']);
});


$router->group(['middleware' => 'guest'],
function (Router $router) {
$router->get('auth/login', ['uses' => 'Auth\AuthLoginController@getLogin']);
$router->post('auth/login', ['uses' => 'Auth\AuthLoginController@postLogin']);
});
$router->group(['middleware' => 'auth'],
function (Router $router) {
$router->get('/', ['uses' => 'DashboardController@index']);


/**
* Properties
*/
$router->get('/properties', ['uses' => 'Properties\PropertiesController@index']);
$router->get('/properties/{propertyId}', ['uses' => 'Properties\PropertiesController@show']);
$router->put('/properties/{propertyId}', ['uses' => 'Properties\PropertiesController@update']);
$router->get('/properties/{propertyId}/edit', ['uses' => 'Properties\PropertiesController@edit']);

/**
* Tenancies
*/
$router->get('/tenancies/{tenancyId}',['uses' => 'Tenancies\TenanciesController@show']);

$router->group(['middleware' => ['auth', 'company']],
function (Router $router) {
$router->get('/', ['uses' => 'DashboardController@index']);


/**
* Properties
*/
$router->get('/properties', ['uses' => 'Properties\PropertiesController@index']);
$router->get('/properties/{propertyId}', ['uses' => 'Properties\PropertiesController@show']);
$router->put('/properties/{propertyId}', ['uses' => 'Properties\PropertiesController@update']);
$router->get('/properties/{propertyId}/edit', ['uses' => 'Properties\PropertiesController@edit']);

/**
* Tenancies
*/
$router->get('/tenancies/{tenancyId}', ['uses' => 'Tenancies\TenanciesController@show']);
$router->get('/tenancies/{tenancyId}/invite', ['uses' => 'Tenancies\TenanciesInviteController@getInviteForm']);
$router->post('/tenancies/{tenancyId}/invite-email', 'Tenancies\TenanciesInviteController@postInviteViaEmail');

/**
* Tenancies Rent Book
*/
$router->get('/tenancies/{tenancyId}/rentbook/add', 'Tenancies\RentBook\TenanciesRentBookController@add');
$router->post('/tenancies/{tenancyId}/rentbook', 'Tenancies\RentBook\TenanciesRentBookController@addPayment');

$router->get('/tenancies/{tenancyId}/rentbook/{rentPaymentId}/change',
'Tenancies\RentBook\TenanciesRentBookController@change');
$router->put('/tenancies/{tenancyId}/rentbook/{rentPaymentId}',
'Tenancies\RentBook\TenanciesRentBookController@updateRentPayment');
$router->get('/tenancies/{tenancyId}/rentbook/{rentPaymentId}/delete',
'Tenancies\RentBook\TenanciesRentBookController@deleteRentPayment');


}
);
}
);
);
2 changes: 1 addition & 1 deletion config/debugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
'db' => array(
'with_params' => true, // Render SQL with the parameters substituted
'timeline' => false, // Add the queries to the timeline
'backtrace' => false, // EXPERIMENTAL: Use a backtrace to find the origin of the query in your files.
'backtrace' => true, // EXPERIMENTAL: Use a backtrace to find the origin of the query in your files.
'explain' => array( // EXPERIMENTAL: Show EXPLAIN output on queries
'enabled' => false,
'types' => array('SELECT'), // array('SELECT', 'INSERT', 'UPDATE', 'DELETE'); for MySQL 5.6.3+
Expand Down

0 comments on commit 5ac69d8

Please sign in to comment.