Skip to content

Commit

Permalink
feat: wip - add Movie data fetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Gandhi11 committed Oct 13, 2023
1 parent f086b2d commit 23c0c3a
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 10 deletions.
42 changes: 42 additions & 0 deletions app/Domain/Integrations/SWApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace App\Domain\Integrations;

use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;

// todo: Complete this Class

/**
* Class SWApi
* @url https://swapi.dev/
*/
class SWApi
{
/**
* @var int
*/
public const DEFAULT_TIMEOUT = 100;

/**
* @var int
*/
protected int $timeout = self::DEFAULT_TIMEOUT;

/**
* @return \Illuminate\Http\Client\PendingRequest
*/
public function makeRequest(): PendingRequest
{
// todo: Complete this method
return $this->makeRequestBase();
}

/**
* @return \Illuminate\Http\Client\PendingRequest
*/
protected function makeRequestBase(): PendingRequest
{
return Http::timeout($this->timeout);
}
}
32 changes: 32 additions & 0 deletions app/Domain/Movies/Jobs/MovieDataFetcherJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Domain\Movies\Jobs;

use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

// todo: Complete this Class using the SWApi class
class MovieDataFetcherJob implements ShouldQueue
{
use Dispatchable;

/**
* @return void
*/
public function handle(): void
{
// todo: implement
}

protected function updateMovies(?array $externalMoviesData): ?array
{
// todo: implement
return null;
}

protected function sendEmailNotificationWithDiff(): void
{
// todo: implement
// Send email notification with the diff of the movies data
}
}
14 changes: 14 additions & 0 deletions app/Http/Controllers/MovieDataFetcherController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Http\Controllers;

use Exception;

class MovieDataFetcherController extends Controller
{
public function post(): void
{
throw new Exception('Not implemented');
// MovieDataFetcherJob::dispatch();
}
}
3 changes: 2 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Providers;

use App\Domain\Integrations\SWApi;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
Expand All @@ -11,7 +12,7 @@ class AppServiceProvider extends ServiceProvider
*/
public function register(): void
{
//
$this->app->singleton(SWApi::class);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
],

'swapi' => [
'url' => env('SWAPI_URL', 'https://swapi.dev/api/'),
]

];
68 changes: 59 additions & 9 deletions resources/js/Layouts/AuthenticatedLayout.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,41 @@
<script setup lang="ts">
import { ref } from 'vue';
import ApplicationLogo from '@/Components/ApplicationLogo.vue';
import Dropdown from '@/Components/Dropdown.vue';
import DropdownLink from '@/Components/DropdownLink.vue';
import NavLink from '@/Components/NavLink.vue';
import ResponsiveNavLink from '@/Components/ResponsiveNavLink.vue';
import { Link } from '@inertiajs/vue3';
const showingNavigationDropdown = ref(false);
import { ref } from 'vue';
import ApplicationLogo from '@/Components/ApplicationLogo.vue';
import Dropdown from '@/Components/Dropdown.vue';
import DropdownLink from '@/Components/DropdownLink.vue';
import NavLink from '@/Components/NavLink.vue';
import ResponsiveNavLink from '@/Components/ResponsiveNavLink.vue';
import { Link, useForm } from '@inertiajs/vue3';
import axios from "axios";
import Modal from "@/Components/Modal.vue";
import SecondaryButton from "@/Components/SecondaryButton.vue";
import PrimaryButton from "@/Components/PrimaryButton.vue";
const showingNavigationDropdown = ref(false);
const form = useForm({});
const confirmingFetchData = ref(false);
const confirmFetchDataAction = () => {
confirmingFetchData.value = true;
};
const closeModal = () => {
confirmingFetchData.value = false;
};
function submit() {
confirmingFetchData.value = false;
axios.post(route('movies.fetch-data.post'))
.then((response) => {
alert('Fetch started! You will be notified when it is done.');
})
.catch((error) => {
alert(error.response.data.message);
});
}
</script>

<template>
Expand Down Expand Up @@ -65,6 +93,7 @@ const showingNavigationDropdown = ref(false);

<template #content>
<DropdownLink :href="route('profile.edit')" :active="route().current('profile.edit')"> Profile </DropdownLink>
<button @click="confirmFetchDataAction" class="block w-full px-4 py-2 text-left text-sm leading-5 text-gray-300 hover:bg-gray-800 focus:outline-none focus:bg-gray-800 transition duration-150 ease-in-out"> Fetch Movie Data </button>
<DropdownLink :href="route('logout')" method="post" as="button">
Log Out
</DropdownLink>
Expand Down Expand Up @@ -149,4 +178,25 @@ const showingNavigationDropdown = ref(false);
</main>
</div>
</div>

<Modal :show="confirmingFetchData" @close="closeModal">
<div class="p-6">
<h2 class="text-lg font-medium text-gray-100">
This action take time, are you sure?
</h2>

<div class="mt-6 flex justify-end">
<SecondaryButton @click="closeModal"> Cancel </SecondaryButton>

<PrimaryButton
class="ml-3"
:class="{ 'opacity-25': form.processing }"
:disabled="form.processing"
@click="submit"
>
Confirm
</PrimaryButton>
</div>
</div>
</Modal>
</template>
2 changes: 2 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use App\Http\Controllers\MovieController;
use App\Http\Controllers\MovieDataFetcherController;
use App\Http\Controllers\ProfileController;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Route;
Expand Down Expand Up @@ -38,6 +39,7 @@
Route::get('/movies', [MovieController::class, 'index'])->name('movies.index');
Route::get('/movies/create', [MovieController::class, 'create'])->name('movies.create');
Route::post('/movies/post', [MovieController::class, 'pots'])->name('movies.post');
Route::post('/movies/fetch-data', [MovieDataFetcherController::class, 'post'])->name('movies.fetch-data.post');
});

require __DIR__ . '/auth.php';

0 comments on commit 23c0c3a

Please sign in to comment.