133 lines
3.6 KiB
PHP
133 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Services\Api\StationService;
|
|
use Illuminate\Http\Request;
|
|
|
|
class StationController extends Controller
|
|
{
|
|
protected $stationService;
|
|
|
|
public function __construct(StationService $stationService)
|
|
{
|
|
$this->stationService = $stationService;
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$response = $this->stationService->getAllStations();
|
|
|
|
if (!$response['success']) {
|
|
return back()->with('error', $response['message']);
|
|
}
|
|
|
|
return view('pages.station-locator.index', [
|
|
'stations' => $response['data']
|
|
]);
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
return view('pages.station-locator.create');
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$response = $this->stationService->createStation($request->all());
|
|
|
|
if (!$response['success']) {
|
|
return back()->withInput()->with('error', $response['message']);
|
|
}
|
|
|
|
return redirect()->route('stations.index')
|
|
->with('success', 'Station created successfully');
|
|
}
|
|
|
|
public function edit($id)
|
|
{
|
|
$response = $this->stationService->getStation($id);
|
|
|
|
if (!$response['success']) {
|
|
return back()->with('error', $response['message']);
|
|
}
|
|
|
|
return view('pages.station-locator.edit', [
|
|
'station' => $response['data']
|
|
]);
|
|
}
|
|
|
|
public function update(Request $request, $id)
|
|
{
|
|
$response = $this->stationService->updateStation($id, $request->all());
|
|
|
|
if (!$response['success']) {
|
|
return back()->withInput()->with('error', $response['message']);
|
|
}
|
|
|
|
return redirect()->route('stations.index')
|
|
->with('success', 'Station updated successfully');
|
|
}
|
|
|
|
public function destroy($id)
|
|
{
|
|
$response = $this->stationService->deleteStation($id);
|
|
|
|
if (!$response['success']) {
|
|
return back()->with('error', $response['message']);
|
|
}
|
|
|
|
return redirect()->route('stations.index')
|
|
->with('success', 'Station deleted successfully');
|
|
}
|
|
|
|
public function fuelPrices()
|
|
{
|
|
$response = $this->stationService->getFuelPrices();
|
|
|
|
if (!$response['success']) {
|
|
return back()->with('error', $response['message']);
|
|
}
|
|
|
|
return view('pages.fuel-price-on-demand', [
|
|
'fuelPrices' => $response['data']
|
|
]);
|
|
}
|
|
|
|
public function updateFuelPrices(Request $request)
|
|
{
|
|
$response = $this->stationService->updateFuelPrices($request->all());
|
|
|
|
if (!$response['success']) {
|
|
return back()->withInput()->with('error', $response['message']);
|
|
}
|
|
|
|
return redirect()->route('fuel-prices.index')
|
|
->with('success', 'Fuel prices updated successfully');
|
|
}
|
|
|
|
public function fuelPriceSchedule()
|
|
{
|
|
$response = $this->stationService->getFuelPriceSchedule();
|
|
|
|
if (!$response['success']) {
|
|
return back()->with('error', $response['message']);
|
|
}
|
|
|
|
return view('pages.fuel-price-schedule', [
|
|
'schedules' => $response['data']
|
|
]);
|
|
}
|
|
|
|
public function storeFuelPriceSchedule(Request $request)
|
|
{
|
|
$response = $this->stationService->createFuelPriceSchedule($request->all());
|
|
|
|
if (!$response['success']) {
|
|
return back()->withInput()->with('error', $response['message']);
|
|
}
|
|
|
|
return redirect()->route('fuel-prices.schedule')
|
|
->with('success', 'Fuel price schedule created successfully');
|
|
}
|
|
}
|