From 390ad23e039a558aecb51da762211a08b0d8c50f Mon Sep 17 00:00:00 2001 From: faulty Date: Fri, 3 Feb 2023 09:05:29 +0100 Subject: [PATCH] fix: working copy, caching ASP, notworking orders though --- .../Controllers/Main/ShowingController.php | 4 + app/Models/User.php | 5 ++ app/Providers/AuthServiceProvider.php | 5 +- app/View/Components/CacheImage.php | 2 +- config/auth.php | 4 + ...1_11_22_000000_create_addresses_table.php} | 12 +-- .../2014_10_12_000000_create_users_table.php | 1 + ...01_create_personal_access_tokens_table.php | 2 +- docker-compose.yml | 2 + public/css/{extra.css => main/jumbotron.css} | 0 public/css/{ => main}/main.css | 0 public/css/main/movies.css | 1 + public/css/{ => main}/order.css | 8 +- public/css/manage/forms.css | 51 ++++++++++++ public/css/{ => manage}/manage.css | 82 +------------------ public/css/manage/movies.css | 63 ++++++++++++++ public/css/movies.css | 31 ------- public/js/order.js | 10 ++- resources/views/auth/login.blade.php | 2 +- .../views/components/movie-cards.blade.php | 12 +++ .../views/components/movie-list.blade.php | 17 ++++ .../components/seat-chooser.blade.old.php | 33 -------- .../views/components/seat-chooser.blade.php | 1 - resources/views/dash.blade.php | 2 +- resources/views/main/home.blade.php | 2 +- resources/views/main/layout.blade.php | 2 +- resources/views/main/movies/index.blade.php | 14 +--- resources/views/main/order.blade.php | 3 +- resources/views/manage/layout.blade.php | 2 +- resources/views/manage/movies/index.blade.php | 14 +--- .../views/manage/showings/create.blade.php | 9 ++ routes/api.php | 44 ++++++++++ 32 files changed, 246 insertions(+), 194 deletions(-) rename database/migrations/{2022_11_22_000000_create_addresses_table.php => 2011_11_22_000000_create_addresses_table.php} (54%) rename public/css/{extra.css => main/jumbotron.css} (100%) rename public/css/{ => main}/main.css (100%) create mode 100644 public/css/main/movies.css rename public/css/{ => main}/order.css (91%) create mode 100644 public/css/manage/forms.css rename public/css/{ => manage}/manage.css (59%) create mode 100644 public/css/manage/movies.css delete mode 100644 public/css/movies.css create mode 100644 resources/views/components/movie-cards.blade.php create mode 100644 resources/views/components/movie-list.blade.php delete mode 100644 resources/views/components/seat-chooser.blade.old.php create mode 100644 resources/views/manage/showings/create.blade.php diff --git a/app/Http/Controllers/Main/ShowingController.php b/app/Http/Controllers/Main/ShowingController.php index df75349..f3e62f3 100644 --- a/app/Http/Controllers/Main/ShowingController.php +++ b/app/Http/Controllers/Main/ShowingController.php @@ -19,6 +19,10 @@ public function showAllShowings() public function order($id) { + // if not authenticated piss off + if (!auth()->check()) { + return redirect()->route('login'); + } return view('main.order', ['title' => "Order Tickets", 'showing' => \App\Models\Showing::findOrfail($id)]); } } diff --git a/app/Models/User.php b/app/Models/User.php index 0977180..69ed44f 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -104,4 +104,9 @@ public function orders() return $this->hasMany('App\Models\Order', 'user_id', 'user_id'); } + public function address() + { + return $this->hasOne('App\Models\Address', 'address_id', 'address_id'); + } + } diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 33b83f5..ab063d1 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -2,7 +2,8 @@ namespace App\Providers; -// use Illuminate\Support\Facades\Gate; +use Laravel\Passport\Passport; +use Illuminate\Support\Facades\Gate; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; class AuthServiceProvider extends ServiceProvider @@ -24,7 +25,5 @@ class AuthServiceProvider extends ServiceProvider public function boot() { $this->registerPolicies(); - - // } } diff --git a/app/View/Components/CacheImage.php b/app/View/Components/CacheImage.php index 0eaa153..3a5972b 100644 --- a/app/View/Components/CacheImage.php +++ b/app/View/Components/CacheImage.php @@ -23,7 +23,7 @@ public function handleCache() { if (!\Cache::has($this->src)) { $image = file_get_contents($this->src); - \Cache::put($this->src, $image, 60 * 24 * 7); + \Cache::put($this->src, $image, 60 * 24 * 7); // 1 week } return \Cache::get($this->src); } diff --git a/config/auth.php b/config/auth.php index d8c6cee..e4ad889 100644 --- a/config/auth.php +++ b/config/auth.php @@ -40,6 +40,10 @@ 'driver' => 'session', 'provider' => 'users', ], + 'api' => [ + 'driver' => 'passport', + 'provider' => 'users' + ] ], /* diff --git a/database/migrations/2022_11_22_000000_create_addresses_table.php b/database/migrations/2011_11_22_000000_create_addresses_table.php similarity index 54% rename from database/migrations/2022_11_22_000000_create_addresses_table.php rename to database/migrations/2011_11_22_000000_create_addresses_table.php index 3ec4299..5ecc2a4 100644 --- a/database/migrations/2022_11_22_000000_create_addresses_table.php +++ b/database/migrations/2011_11_22_000000_create_addresses_table.php @@ -15,12 +15,12 @@ public function up() Schema::create('addresses', function (Blueprint $table) { $table->id('address_id'); $table->timestamps(); - $table->addColumn('string', 'address_street', ['length' => 255]); - $table->addColumn('string', 'address_city', ['length' => 255]); - $table->addColumn('string', 'address_state', ['length' => 255]); - $table->addColumn('string', 'address_zip', ['length' => 255]); - $table->addColumn('string', 'address_country', ['length' => 255])->default('Netherlands'); - $table->addColumn('string', 'address_phone', ['length' => 255])->nullable(); + $table->string('address_street', 255); + $table->string('address_city', 255); + $table->string('address_state', 255); + $table->string('address_zip', 255); + $table->string('address_country', 255)->default('Netherlands'); + $table->string('address_phone', 255)->nullable(); }); } diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index bbd9d2e..8a13b6a 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -20,6 +20,7 @@ public function up() $table->timestamp('email_verified_at')->nullable(); $table->string('password'); $table->enum('role', ['default', 'employee', 'manage', 'admin'])->default('default'); + $table->foreignId('address_id')->nullable()->constrained('addresses', 'address_id')->onDelete('cascade'); $table->rememberToken(); $table->timestamps(); }); diff --git a/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php b/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php index 8b3b49a..6c81fd2 100644 --- a/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php +++ b/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php @@ -14,7 +14,7 @@ public function up() { Schema::create('personal_access_tokens', function (Blueprint $table) { - $table->id('personal_access_token_id'); + $table->id(); $table->morphs('tokenable'); $table->string('name'); $table->string('token', 64)->unique(); diff --git a/docker-compose.yml b/docker-compose.yml index 006b328..cf6b9f8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,6 +18,8 @@ services: image: phpmyadmin/phpmyadmin container_name: phpmyadmin restart: always + links: + - mysql ports: - "8080:80" environment: diff --git a/public/css/extra.css b/public/css/main/jumbotron.css similarity index 100% rename from public/css/extra.css rename to public/css/main/jumbotron.css diff --git a/public/css/main.css b/public/css/main/main.css similarity index 100% rename from public/css/main.css rename to public/css/main/main.css diff --git a/public/css/main/movies.css b/public/css/main/movies.css new file mode 100644 index 0000000..ba1eea1 --- /dev/null +++ b/public/css/main/movies.css @@ -0,0 +1 @@ +@import "../manage/movies.css"; diff --git a/public/css/order.css b/public/css/main/order.css similarity index 91% rename from public/css/order.css rename to public/css/main/order.css index fc4fab6..1eae7c0 100644 --- a/public/css/order.css +++ b/public/css/main/order.css @@ -2,8 +2,10 @@ body { /* center with spacing on the left and right*/ margin: 0 auto; width: 100%; - max-width: 1000px; padding: 0 20px 3rem; + + display: grid; + place-content: center; } #seat-chooser { @@ -51,3 +53,7 @@ #summary-dyn .seat .price { margin: 0.5rem; float: right; } + +#order-button { + margin-bottom: 10rem; +} diff --git a/public/css/manage/forms.css b/public/css/manage/forms.css new file mode 100644 index 0000000..e952331 --- /dev/null +++ b/public/css/manage/forms.css @@ -0,0 +1,51 @@ +.form { + display: flex; + flex-direction: column; + margin: 0.5rem 0; + padding: 0.5rem; + background: var(--second-bg); + border-radius: 0.5rem; +} + +.form .form-group { + display: flex; + flex-direction: column; + margin: 0.5rem 0; +} + +.form .form-group label { + margin: 0.5rem 0; +} + +.form .form-group button, +.form .form-group select, +.form .form-group textarea, +.form .form-group input { + padding: 0.5rem; + border-radius: 0.5rem; + background: var(--default-bg); + color: var(--default-text); + outline: none; + border: none; +} + +.form .form-group button:hover, +.form .form-group select:hover, +.form .form-group textarea:hover, +.form .form-group input:hover, +.form .form-group button:focus, +.form .form-group select:focus, +.form .form-group textarea:focus, +.form .form-group input:focus { + filter: brightness(1.5); +} + +form .form-group button { + background: var(--highlight-bg); + color: var(--highlight-text); + cursor: pointer; +} + +form .form-group button:hover { + filter: brightness(1.5); +} diff --git a/public/css/manage.css b/public/css/manage/manage.css similarity index 59% rename from public/css/manage.css rename to public/css/manage/manage.css index 18b85d1..a0c27dc 100644 --- a/public/css/manage.css +++ b/public/css/manage/manage.css @@ -9,6 +9,7 @@ header { align-items: center; width: 100%; z-index: 1; + box-shadow: #111111 0 0 10px; } header span { @@ -91,90 +92,9 @@ .card .big-stat { font-weight: bold; } -#movies { - display: flex; - flex-direction: column; -} - -#movies a { - display: flex; - flex-direction: row; - margin: 0.5rem 0; - padding: 0.5rem; - background: var(--second-bg); - border-radius: 0.5rem; -} - -#movies a img { - width: 10vw; - height: 16vw; - object-fit: cover; - transition: transform 0.5s; -} - -#movies a:hover { - filter: brightness(1.5); -} - -#movies a .details { - display: flex; - flex-direction: column; - margin-left: 1rem; -} /* form */ -.form { - display: flex; - flex-direction: column; - margin: 0.5rem 0; - padding: 0.5rem; - background: var(--second-bg); - border-radius: 0.5rem; -} - -.form .form-group { - display: flex; - flex-direction: column; - margin: 0.5rem 0; -} - -.form .form-group label { - margin: 0.5rem 0; -} - -.form .form-group button, -.form .form-group select, -.form .form-group textarea, -.form .form-group input { - padding: 0.5rem; - border-radius: 0.5rem; - background: var(--default-bg); - color: var(--default-text); - outline: none; - border: none; -} - -.form .form-group button:hover, -.form .form-group select:hover, -.form .form-group textarea:hover, -.form .form-group input:hover, -.form .form-group button:focus, -.form .form-group select:focus, -.form .form-group textarea:focus, -.form .form-group input:focus { - filter: brightness(1.5); -} - -form .form-group button { - background: var(--highlight-bg); - color: var(--highlight-text); - cursor: pointer; -} - -form .form-group button:hover { - filter: brightness(1.5); -} #showings { display: flex; diff --git a/public/css/manage/movies.css b/public/css/manage/movies.css new file mode 100644 index 0000000..7ddf529 --- /dev/null +++ b/public/css/manage/movies.css @@ -0,0 +1,63 @@ +#movie-grid { + display: flex; + flex-wrap: wrap; + justify-content: space-between; + flex-direction: row; + gap: 1rem; +} + +#movie-grid a { + position: relative; +} + +#movie-grid a .details { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + display: grid; + place-content: center; + align-content: center; + background: #000; + opacity: 0; + color: var(--default-text); + transition: all .5s; + + max-height: 100%; + max-width: 100%; +} + +#movie-grid a:hover .details { + opacity: 0.7; +} + +/* --- */ + + +#movie-list { + display: flex; + flex-direction: column; +} + +#movie-list a { + display: flex; + flex-direction: row; + margin: 0.5rem 0; + padding: 0.5rem; + background: var(--second-bg); + border-radius: 0.5rem; +} + +#movie-list a img { + width: 10vw; + height: 16vw; + object-fit: cover; + transition: transform 0.5s; +} + +#movie-list a .details { + display: flex; + flex-direction: column; + margin-left: 1rem; +} diff --git a/public/css/movies.css b/public/css/movies.css deleted file mode 100644 index 232b0c8..0000000 --- a/public/css/movies.css +++ /dev/null @@ -1,31 +0,0 @@ -#movies { - display: flex; - flex-wrap: wrap; - justify-content: space-between; - flex-direction: row; - gap: 1rem; -} - -/* Show .details on top of image */ -#movies a { - position: relative; -} - -#movies a .details { - position: absolute; - top: 0; - left: 0; - width: 100%; - height: 100%; - display: grid; - place-content: center; - align-content: center; - background: var(--second-bg); - opacity: 0; - color: var(--default-text); - transition: all .5s; -} - -#movies a:hover .details { - opacity: 0.7; -} diff --git a/public/js/order.js b/public/js/order.js index 3bcb429..28f37f0 100644 --- a/public/js/order.js +++ b/public/js/order.js @@ -62,7 +62,7 @@ } ); - window.freq.set('seat-chooser', sc); + window.sc = sc; })(); let total = 0; @@ -84,13 +84,14 @@ document.querySelector('button#order-button').addEventListener('click', (e) => { window.sc.selectedSeats.forEach(seat => { seats.push({ seat: seat.id, - ticket: seat.ticket.id + price: seat.ticket.id, }); }); fetch(`/api/order`, { method: 'POST', headers: { - 'Content-Type': 'application/json' + 'Content-Type': 'application/json', + 'Authorization': 'Bearer ' + document.querySelector('#order-button').getAttribute('data-token') || '' }, body: JSON.stringify({ showing: sc.showingId, @@ -98,7 +99,8 @@ document.querySelector('button#order-button').addEventListener('click', (e) => { }) }).then(res => { if (res.ok) { - window.location = '/order/complete'; + // window.location = '/order/complete'; + console.log('Order placed'); } else { alert('Error placing order'); } diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 9e2c05f..359e1e2 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -8,7 +8,7 @@

{{ __('Login') }}

-
+ @csrf

diff --git a/resources/views/components/movie-cards.blade.php b/resources/views/components/movie-cards.blade.php new file mode 100644 index 0000000..ba13dfb --- /dev/null +++ b/resources/views/components/movie-cards.blade.php @@ -0,0 +1,12 @@ + diff --git a/resources/views/components/movie-list.blade.php b/resources/views/components/movie-list.blade.php new file mode 100644 index 0000000..cc98317 --- /dev/null +++ b/resources/views/components/movie-list.blade.php @@ -0,0 +1,17 @@ +@push('head') + +@endpush + + diff --git a/resources/views/components/seat-chooser.blade.old.php b/resources/views/components/seat-chooser.blade.old.php deleted file mode 100644 index faa6102..0000000 --- a/resources/views/components/seat-chooser.blade.old.php +++ /dev/null @@ -1,33 +0,0 @@ -@extends('layout') - -@push('head') - - -@endpush - -
-
-
-
Loading...
-
-
- -
- @foreach($seatmatrix as $row) -
- @foreach($row as $seat) - @if($seat) -
-
{{ $seat->seat_row }}-{{ $seat->seat_column }}
-
- @else -
- @endif - @endforeach -
- @endforeach -
diff --git a/resources/views/components/seat-chooser.blade.php b/resources/views/components/seat-chooser.blade.php index dfc3924..3cdcaeb 100644 --- a/resources/views/components/seat-chooser.blade.php +++ b/resources/views/components/seat-chooser.blade.php @@ -7,7 +7,6 @@ @endpush
-

Loading...

diff --git a/resources/views/dash.blade.php b/resources/views/dash.blade.php index d4528a1..7a9823e 100644 --- a/resources/views/dash.blade.php +++ b/resources/views/dash.blade.php @@ -16,7 +16,7 @@

Orders


- +

Permissions


diff --git a/resources/views/main/home.blade.php b/resources/views/main/home.blade.php index 8910949..a5197e2 100644 --- a/resources/views/main/home.blade.php +++ b/resources/views/main/home.blade.php @@ -1,7 +1,7 @@ @extends('main.layout') @push('head') - + @endpush diff --git a/resources/views/main/layout.blade.php b/resources/views/main/layout.blade.php index 0a7d0f0..271c0ad 100644 --- a/resources/views/main/layout.blade.php +++ b/resources/views/main/layout.blade.php @@ -2,7 +2,7 @@ @push('head') - + @endpush @section('body') diff --git a/resources/views/main/movies/index.blade.php b/resources/views/main/movies/index.blade.php index 54ccded..5cd887f 100644 --- a/resources/views/main/movies/index.blade.php +++ b/resources/views/main/movies/index.blade.php @@ -1,7 +1,7 @@ @extends('main.layout') @push('head') - + @endpush @section('content') @@ -9,17 +9,7 @@

Now playing:


-
@endsection diff --git a/resources/views/main/order.blade.php b/resources/views/main/order.blade.php index e53c589..0674155 100644 --- a/resources/views/main/order.blade.php +++ b/resources/views/main/order.blade.php @@ -30,6 +30,5 @@
Total: €0.00
- - + @endsection diff --git a/resources/views/manage/layout.blade.php b/resources/views/manage/layout.blade.php index 98bf12c..b86ae30 100644 --- a/resources/views/manage/layout.blade.php +++ b/resources/views/manage/layout.blade.php @@ -5,7 +5,7 @@ @push('head') - + @endpush @section('body') diff --git a/resources/views/manage/movies/index.blade.php b/resources/views/manage/movies/index.blade.php index 5442df0..51e7767 100644 --- a/resources/views/manage/movies/index.blade.php +++ b/resources/views/manage/movies/index.blade.php @@ -8,17 +8,5 @@ Add Movie


- + @endsection diff --git a/resources/views/manage/showings/create.blade.php b/resources/views/manage/showings/create.blade.php new file mode 100644 index 0000000..fc1a1ac --- /dev/null +++ b/resources/views/manage/showings/create.blade.php @@ -0,0 +1,9 @@ +@extends('manage.layout') + +@push('head') + +@endpush + +@section('content') + +@endsection diff --git a/routes/api.php b/routes/api.php index a146d41..484c207 100644 --- a/routes/api.php +++ b/routes/api.php @@ -112,3 +112,47 @@ $user->save(); return $user->cinemas; })->name('api.user.assignment'); + +// POST /api/order +Route::middleware('auth:sanctum')->post('/order', function (Request $request) { + // [0] showing = showing_id + // [1] seats = [{seat: seat_id, price: price_id}, ...] + + // check user + if ($request->user()->exists()) { + return response()->json(['error' => 'user not logged in'], 400); + } + + if (!isset($request->showing) || !isset($request->seats)) { // check if user is logged in and showings and seats are set + return response()->json(['error' => 'showing or seats not set'], 400); + } + + if ($request->user()->addresses()->count() == 0) { // check if user has an address + return response()->json(['error' => 'no address set'], 400); + } + + $order = (new App\Models\Order)->create([ + 'user_id' => $request->user()->user_id, + 'order_number' => substr(str_shuffle(str_repeat($x = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil(10 / strlen($x)))), 1, 10), + 'order_status' => 'pending', + 'billing_address_id' => Auth::user()->address()->address_id + ]); + $order->save(); + + // create tickets for each seat + foreach ($request->seats as $seat) { + Log::info('Creating ticket for seat ' . $seat['seat']); + $ticket = (new App\Models\Ticket)->create([ + 'seat_id' => $seat['seat'], + 'price_id' => $seat['price'], + 'showing_id' => $request->showing, + 'order_id' => $order->order_id, + 'user_id' => $request->user()->user_id + ]); + $ticket->save(); + } + + Log::info('Order created: ' . $order->order_number); + + return $order; +})->name('api.order');