Skip to content

Commit

Permalink
Create journal when new airline is created #667
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeelio committed Apr 26, 2020
1 parent b21201c commit 11a4bd8
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 7 deletions.
3 changes: 3 additions & 0 deletions app/Contracts/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Illuminate\Validation\Validator;
use Prettus\Repository\Eloquent\BaseRepository;

/**
* @mixin \Prettus\Repository\Eloquent\BaseRepository
*/
abstract class Repository extends BaseRepository
{
/**
Expand Down
6 changes: 6 additions & 0 deletions app/Database/seeds/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
options: ''
type: text
description: 'Enter your Google Analytics Tracking ID'
- key: units.currency
name: 'Currency'
group: units
value: USD
type: select
description: 'The currency to use'
- key: units.distance
name: 'Distance Units'
group: units
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Admin/AirlinesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function create()
public function store(CreateAirlineRequest $request)
{
$input = $request->all();
$airlines = $this->airlineRepo->create($input);
$this->airlineSvc->createAirline($input);

Flash::success('Airlines saved successfully.');
return redirect(route('admin.airlines.index'));
Expand Down
3 changes: 3 additions & 0 deletions app/Repositories/AirlineRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Prettus\Repository\Contracts\CacheableInterface;
use Prettus\Repository\Traits\CacheableRepository;

/**
* @mixin \App\Models\Airline
*/
class AirlineRepository extends Repository implements CacheableInterface
{
use CacheableRepository;
Expand Down
15 changes: 15 additions & 0 deletions app/Services/AirlineService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ public function __construct(
$this->subfleetRepo = $subfleetRepo;
}

/**
* Create a new airline, and initialize the journal
*
* @param array $attr
*
* @return \App\Models\Airline
*/
public function createAirline(array $attr): Airline
{
$airline = $this->airlineRepo->create($attr);
$airline->initJournal(setting('units.currency'));

return $airline;
}

/**
* Can the airline be deleted? Check if there are flights, etc associated with it
*
Expand Down
11 changes: 5 additions & 6 deletions modules/Installer/Http/Controllers/InstallerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
namespace Modules\Installer\Http\Controllers;

use App\Contracts\Controller;
use App\Models\User;
use App\Repositories\AirlineRepository;
use App\Services\AirlineService;
use App\Services\AnalyticsService;
use App\Services\Installer\DatabaseService;
use App\Services\Installer\InstallerService;
Expand All @@ -24,7 +23,7 @@

class InstallerController extends Controller
{
private $airlineRepo;
private $airlineSvc;
private $analyticsSvc;
private $dbSvc;
private $envSvc;
Expand All @@ -36,7 +35,7 @@ class InstallerController extends Controller
/**
* InstallerController constructor.
*
* @param AirlineRepository $airlineRepo
* @param AirlineService $airlineSvc
* @param AnalyticsService $analyticsSvc
* @param DatabaseService $dbService
* @param ConfigService $envService
Expand All @@ -46,7 +45,7 @@ class InstallerController extends Controller
* @param UserService $userService
*/
public function __construct(
AirlineRepository $airlineRepo,
AirlineService $airlineRepo,
AnalyticsService $analyticsSvc,
DatabaseService $dbService,
ConfigService $envService,
Expand Down Expand Up @@ -311,7 +310,7 @@ public function usersetup(Request $request)
'country' => $request->get('airline_country'),
];

$airline = $this->airlineRepo->create($attrs);
$airline = $this->airlineSvc->create($attrs);

/**
* Create the user, and associate to the airline
Expand Down

0 comments on commit 11a4bd8

Please sign in to comment.