Skip to content

Commit

Permalink
Merge pull request #43 from WailanTirajoh/feat/pint
Browse files Browse the repository at this point in the history
Feat/pint
  • Loading branch information
WailanTirajoh authored Apr 9, 2024
2 parents 7f495b8 + af50639 commit f41bf71
Show file tree
Hide file tree
Showing 73 changed files with 389 additions and 265 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ DB_DATABASE=hotel_app
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=pusher
BROADCAST_DRIVER=reverb
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Run lint

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
lint:
name: Run pint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.2"
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv
coverage: none

- name: Run composer install
run: composer install -n --prefer-dist

- name: Prepare Laravel Application
run: |
cp .env.example .env
php artisan key:generate
- name: Run pint
run: ./vendor/bin/pint --test
3 changes: 2 additions & 1 deletion app/Events/NewReservationEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class NewReservationEvent implements ShouldBroadcast
use Dispatchable, InteractsWithSockets, SerializesModels;

public $message;

public $random_key;

/**
Expand All @@ -33,7 +34,7 @@ public function __construct($message, $user)
*/
public function broadcastOn()
{
return new Channel('reservation.' . $this->random_key);
return new Channel('reservation.'.$this->random_key);
}

public function broadcastWith()
Expand Down
3 changes: 1 addition & 2 deletions app/Events/RefreshDashboardEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
Expand All @@ -15,6 +13,7 @@ class RefreshDashboardEvent implements ShouldBroadcast
use Dispatchable, InteractsWithSockets, SerializesModels;

public $message;

/**
* Create a new event instance.
*
Expand Down
4 changes: 3 additions & 1 deletion app/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Helper
{
public static function convertToRupiah($price)
{
return "Rp. " . number_format($price, 2, ',', '.');
return 'Rp. '.number_format($price, 2, ',', '.');
}

public static function thisMonth()
Expand Down Expand Up @@ -47,6 +47,7 @@ public static function getDateDifference($check_in, $check_out)
$check_in = strtotime($check_in);
$check_out = strtotime($check_out);
$date_difference = $check_out - $check_in;

return round($date_difference / (60 * 60 * 24));
}

Expand All @@ -65,6 +66,7 @@ public static function getColorByDay($day)
} else {
$color = 'bg-success';
}

return $color;
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\Models\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
Expand Down
10 changes: 6 additions & 4 deletions app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use App\Http\Requests\PostLoginRequest;
use App\Models\User;
use Illuminate\Auth\Events\PasswordReset;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Auth\Events\PasswordReset;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Password;
use Illuminate\Support\Str;
Expand All @@ -16,16 +16,18 @@ class AuthController extends Controller
public function postLogin(PostLoginRequest $request)
{
if (Auth::attempt($request->only('email', 'password'))) {
return redirect('dashboard')->with('success', 'Welcome ' . auth()->user()->name);
return redirect('dashboard')->with('success', 'Welcome '.auth()->user()->name);
}

return redirect('login')->with('failed', 'Incorrect email / password');
}

public function logout()
{
$name = auth()->user()->name;
Auth::logout();
return redirect('login')->with('success', 'Logout success, goodbye ' . $name);

return redirect('login')->with('success', 'Logout success, goodbye '.$name);
}

public function forgotPassword(Request $request)
Expand Down Expand Up @@ -53,7 +55,7 @@ public function resetPassword(Request $request)
$request->only('email', 'password', 'password_confirmation', 'token'),
function (User $user, string $password) {
$user->forceFill([
'password' => Hash::make($password)
'password' => Hash::make($password),
])->setRememberToken(Str::random(60));

$user->save();
Expand Down
17 changes: 8 additions & 9 deletions app/Http/Controllers/ChartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Models\Transaction;
use Carbon\Carbon;
use Illuminate\Http\Request;

class ChartController extends Controller
{
Expand All @@ -14,8 +13,8 @@ public function dialyGuestPerMonth()
$month = Carbon::now()->format('m');
$days_in_month = cal_days_in_month(CAL_GREGORIAN, $month, $year);

$day_array = array();
$guests_count_array = array();
$day_array = [];
$guests_count_array = [];

for ($i = 1; $i <= $days_in_month; $i++) {
$day_array[] = $i;
Expand All @@ -25,31 +24,31 @@ public function dialyGuestPerMonth()
$max_no = max($guests_count_array);
$max = round(($max_no + 10 / 2) / 10) * 10;

return array(
return [
'day' => $day_array,
'guest_count_data' => $guests_count_array,
'max' => $max
);
'max' => $max,
];
}

private function countGuestsPerDay($year, $month, $day)
{
$time = strtotime($month . '/' . $day . '/' . $year);
$time = strtotime($month.'/'.$day.'/'.$year);
$date = date('Y-m-d', $time);

return Transaction::where([['check_in', '<=', $date], ['check_out', '>=', $date]])->count();
}

public function dialyGuest($year, $month, $day)
{
$time = strtotime($month . '/' . $day . '/' . $year);
$time = strtotime($month.'/'.$day.'/'.$year);
$date = date('Y-m-d', $time);

$transactions = Transaction::where([['check_in', '<=', $date], ['check_out', '>=', $date]])->get();

return view('dashboard.chart_detail', [
'transactions' => $transactions,
'date' => $date
'date' => $date,
]);
}
}
22 changes: 13 additions & 9 deletions app/Http/Controllers/CustomerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use App\Http\Requests\StoreCustomerRequest;
use App\Models\Customer;
use App\Models\User;
use App\Repositories\Interface\ImageRepositoryInterface;
use App\Repositories\Interface\CustomerRepositoryInterface;
use App\Repositories\Interface\ImageRepositoryInterface;
use Illuminate\Http\Request;

class CustomerController extends Controller
Expand All @@ -21,6 +21,7 @@ public function __construct(CustomerRepositoryInterface $customerRepository)
public function index(Request $request)
{
$customers = $this->customerRepository->get($request);

return view('customer.index', ['customers' => $customers]);
}

Expand All @@ -32,7 +33,8 @@ public function create()
public function store(StoreCustomerRequest $request)
{
$customer = $this->customerRepository->store($request);
return redirect('customer')->with('success', 'Customer ' . $customer->name . ' created');

return redirect('customer')->with('success', 'Customer '.$customer->name.' created');
}

public function show(Customer $customer)
Expand All @@ -48,14 +50,15 @@ public function edit(Customer $customer)
public function update(Customer $customer, StoreCustomerRequest $request)
{
$customer->update($request->all());
return redirect('customer')->with('success', 'customer ' . $customer->name . ' udpated!');

return redirect('customer')->with('success', 'customer '.$customer->name.' udpated!');
}

public function destroy(Customer $customer, ImageRepositoryInterface $imageRepository)
{
try {
$user = User::find($customer->user->id);
$avatar_path = public_path('img/user/' . $user->name . '-' . $user->id);
$avatar_path = public_path('img/user/'.$user->name.'-'.$user->id);

$customer->delete();
$user->delete();
Expand All @@ -64,13 +67,14 @@ public function destroy(Customer $customer, ImageRepositoryInterface $imageRepos
$imageRepository->destroy($avatar_path);
}

return redirect('customer')->with('success', 'Customer ' . $customer->name . ' deleted!');
return redirect('customer')->with('success', 'Customer '.$customer->name.' deleted!');
} catch (\Exception $e) {
$errorMessage = "";
if ($e->errorInfo[0] == "23000") {
$errorMessage = "Data still connected to other tables";
$errorMessage = '';
if ($e->errorInfo[0] == '23000') {
$errorMessage = 'Data still connected to other tables';
}
return redirect('customer')->with('failed', 'Customer ' . $customer->name . ' cannot be deleted! ' . $errorMessage);

return redirect('customer')->with('failed', 'Customer '.$customer->name.' cannot be deleted! '.$errorMessage);
}
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function index()
->orderBy('id', 'DESC')->get();

return view('dashboard.index', [
'transactions' => $transactions
'transactions' => $transactions,
]);
}
}
6 changes: 2 additions & 4 deletions app/Http/Controllers/EventController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

namespace App\Http\Controllers;

use App\Events\MyEvent;
use App\Events\NewReservationEvent;
use App\Events\TestEvent;
use App\Models\User;
use Illuminate\Http\Request;

class EventController extends Controller
{
Expand All @@ -15,8 +13,8 @@ public function sendEvent()
// event(new TestEvent('Sent from my Laravel application'));
$message = 'Reservation added';
$superAdmins = User::where('role', 'Super')->get();
foreach($superAdmins as $superAdmin) {
event(new NewReservationEvent($message,$superAdmin));
foreach ($superAdmins as $superAdmin) {
event(new NewReservationEvent($message, $superAdmin));
}
// return view('event.index');
}
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/FacilityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ class FacilityController extends Controller
public function index()
{
$facilities = Facility::paginate(5);

return view('facility.index', [
'facilities' => $facilities
'facilities' => $facilities,
]);
}

Expand Down
2 changes: 0 additions & 2 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
{
/**
Expand Down
10 changes: 4 additions & 6 deletions app/Http/Controllers/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

namespace App\Http\Controllers;

use App\Helpers\Helper;
use app\Helpers\ImageService;
use App\Http\Requests\StoreImageRequest;
use App\Models\Image;
use App\Models\Room;
use App\Repositories\Interface\ImageRepositoryInterface;
use Illuminate\Http\Request;

class ImageController extends Controller
{
Expand All @@ -21,7 +18,7 @@ public function __construct(ImageRepositoryInterface $imageRepository)

public function store(StoreImageRequest $request, Room $room)
{
$path = public_path('img/room/' . $room->number);
$path = public_path('img/room/'.$room->number);
$file = $request->file('image');

$lastFileName = $this->imageRepository->uploadImage($path, $file);
Expand All @@ -36,11 +33,12 @@ public function store(StoreImageRequest $request, Room $room)

public function destroy(Image $image)
{
$path = public_path('img/room/' . $image->room->number . '/' . $image->url);
$path = public_path('img/room/'.$image->room->number.'/'.$image->url);
if (file_exists($path)) {
unlink($path);
}
$image->delete();
return redirect()->back()->with('success', 'Image ' . $image->url . ' has been deleted!');

return redirect()->back()->with('success', 'Image '.$image->url.' has been deleted!');
}
}
4 changes: 2 additions & 2 deletions app/Http/Controllers/NotificationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class NotificationsController extends Controller
{
public function markAllAsRead()
{
auth()->user()->unreadNotifications->markAsRead();

return redirect()->back();
}

Expand All @@ -18,6 +17,7 @@ public function routeTo($id)
if ($notification) {
$notification->markAsRead();
}

return redirect($notification->data['url']);
}
}
Loading

0 comments on commit f41bf71

Please sign in to comment.