Skip to content

Commit

Permalink
Refactored code
Browse files Browse the repository at this point in the history
  • Loading branch information
VampireAotD committed Nov 19, 2023
1 parent 879cfaf commit 4398d92
Show file tree
Hide file tree
Showing 36 changed files with 231 additions and 86 deletions.
4 changes: 4 additions & 0 deletions docker/nginx/conf.d/default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ server {
location ~ /\.(?!well-known).* {
deny all;
}

location ~* (?:#.*#|\.(?:bak|conf|dist|fla|in[ci]|log|orig|psd|sh|sql|sw[op])|~)$ {
deny all;
}
}
49 changes: 49 additions & 0 deletions src/app/DTO/UseCase/Metric/MetricDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace App\DTO\UseCase\Metric;

use App\Models\Anime;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Database\Eloquent\Collection;

/**
* Class MetricDTO
* @package App\DTO\UseCase\Metric
* @template-implements Arrayable<string, mixed>
*/
readonly class MetricDTO implements Arrayable
{
/**
* @param int $animeCount
* @param int $usersCount
* @param array<int> $animePerMonth
* @param array<string, int> $animePerDomain
* @param Collection<int, Anime> $latestAnime
*/
public function __construct(
public int $animeCount,
public int $usersCount,
public array $animePerMonth,
public array $animePerDomain,
public Collection $latestAnime,
) {
}

/**
* Get the instance as an array.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
return [
'animeCount' => $this->animeCount,
'usersCount' => $this->usersCount,
'animePerMonth' => $this->animePerMonth,
'animePerDomain' => $this->animePerDomain,
'latestAnime' => $this->latestAnime,
];
}
}
2 changes: 1 addition & 1 deletion src/app/Http/Controllers/Dashboard/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public function __construct(private readonly MetricUseCase $metricUseCase)

public function index(): Response
{
return Inertia::render('Dashboard/Dashboard', $this->metricUseCase->getAnimeMetrics());
return Inertia::render('Dashboard/Dashboard', $this->metricUseCase->getAnimeMetrics()->toArray());
}
}
3 changes: 3 additions & 0 deletions src/app/Services/AnimeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public function getParsedAnimePerMonth(): array
return array_replace($initial, $perMonth);
}

/**
* @return Collection<int, Anime>
*/
public function getTenLatestAnime(): Collection
{
return $this->animeRepository->withFilters([new RelationFilter(['image:model_id,path'])])->getLatestAnime();
Expand Down
17 changes: 9 additions & 8 deletions src/app/UseCase/Metric/MetricUseCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\UseCase\Metric;

use App\DTO\UseCase\Metric\MetricDTO;
use App\Services\AnimeService;
use App\Services\AnimeUrlService;
use App\Services\UserService;
Expand All @@ -21,15 +22,15 @@ public function __construct(
) {
}

public function getAnimeMetrics(): array
public function getAnimeMetrics(): MetricDTO
{
// TODO add cache decorator for repositories
return [
'animeCount' => $this->animeService->countAnime(),
'usersCount' => $this->userService->countUsers(),
'animePerMonth' => $this->animeService->getParsedAnimePerMonth(),
'animePerDomain' => $this->animeUrlService->countAnimePerDomain(),
'latestAnime' => $this->animeService->getTenLatestAnime(),
];
return new MetricDTO(
$this->animeService->countAnime(),
$this->userService->countUsers(),
$this->animeService->getParsedAnimePerMonth(),
$this->animeUrlService->countAnimePerDomain(),
$this->animeService->getTenLatestAnime(),
);
}
}
2 changes: 1 addition & 1 deletion src/database/factories/AnimeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function definition(): array
'title' => $this->faker->title,
'status' => $this->faker->randomElement(AnimeStatusEnum::values()),
'episodes' => (string) $this->faker->randomNumber(),
'rating' => $this->faker->randomFloat(),
'rating' => $this->faker->randomAnimeRating(),
];
}
}
3 changes: 0 additions & 3 deletions src/resources/css/app.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
@import 'primevue/resources/themes/lara-dark-indigo/theme.css';
@import 'primeicons/primeicons.css';

@tailwind base;
@tailwind components;
@tailwind utilities;
File renamed without changes.
File renamed without changes.
36 changes: 36 additions & 0 deletions src/resources/js/Components/Input/SearchInput.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<script setup lang="ts">
import InputText from 'primevue/inputtext';
import { ComponentPublicInstance, onMounted, ref } from 'vue';
const query = ref<string | null>(null);
const searchInput = ref<InputText | null>(null);
const focus = (event: KeyboardEvent) => {
if (event.ctrlKey && event.key === 'k') {
event.preventDefault();
const input = searchInput.value as ComponentPublicInstance<{
$el: HTMLInputElement;
}>;
input?.$el?.focus();
}
};
onMounted(() => window.addEventListener('keydown', focus));
</script>

<template>
<span class="p-input-icon-left">
<i class="pi pi-search text-zinc-600 dark:text-white" />

<InputText
ref="searchInput"
v-model="query"
name="search"
class="text-xs ring-1 bg-transparent ring-gray-200 dark:ring-zinc-600 focus:ring-red-300 pl-10 pr-5 text-gray-600 dark:text-white py-3 rounded-full w-full outline-none focus:ring-1"
placeholder="Search (CTRL + K)"
/>
</span>
</template>

<style scoped></style>
19 changes: 0 additions & 19 deletions src/resources/js/Components/Input/Searchbar.vue

This file was deleted.

File renamed without changes.
6 changes: 3 additions & 3 deletions src/resources/js/Layouts/AuthenticatedLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import DropdownLink from '@/Components/DropdownLink.vue';
import NavLink from '@/Components/NavLink.vue';
import ResponsiveNavLink from '@/Components/ResponsiveNavLink.vue';
import { Link } from '@inertiajs/vue3';
import Searchbar from '@/Components/Input/Searchbar.vue';
import SearchInput from '@/Components/Input/SearchInput.vue';
import ThemeSwitcher from '@/Components/ThemeSwitcher.vue';
import Footer from '@/Components/Footer.vue';
Expand Down Expand Up @@ -66,7 +66,7 @@ const showingNavigationDropdown = ref(false);

<div class="hidden sm:flex sm:items-center sm:ml-6">
<div class="flex items-center justify-between">
<Searchbar class="mr-3" />
<SearchInput class="mr-3" />

<ThemeSwitcher />
</div>
Expand Down Expand Up @@ -163,7 +163,7 @@ const showingNavigationDropdown = ref(false);
class="sm:hidden"
>
<div class="pt-2 pb-3 space-y-1">
<Searchbar />
<SearchInput />
<ThemeSwitcher />
</div>

Expand Down
8 changes: 4 additions & 4 deletions src/resources/js/Pages/Anime/Partials/AddAnimeForm.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script setup lang="ts">
import TextInput from '@/Components/TextInput.vue';
import InputLabel from '@/Components/InputLabel.vue';
import InputError from '@/Components/InputError.vue';
import PrimaryButton from '@/Components/PrimaryButton.vue';
import TextInput from '@/Components/Input/TextInput.vue';
import InputLabel from '@/Components/Input/InputLabel.vue';
import InputError from '@/Components/Input/InputError.vue';
import PrimaryButton from '@/Components/Button/PrimaryButton.vue';
import { useForm, usePage } from '@inertiajs/vue3';
import { ScrapeResult } from '@/types/pusher/types';
import { useToast } from 'primevue/usetoast';
Expand Down
10 changes: 8 additions & 2 deletions src/resources/js/Pages/Anime/Partials/DataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@ const openModal = () => {
const handleUpdate = (event: DataTablePageEvent) => {
router.get(
route('anime.index'),
{ page: event.page + 1, per_page: event.rows },
{ preserveScroll: true }
{
page: event.page + 1,
per_page: event.rows,
},
{
preserveScroll: true,
only: ['pagination'],
}
);
};
</script>
Expand Down
2 changes: 1 addition & 1 deletion src/resources/js/Pages/Anime/Show.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AnimeWithRelations } from '@/types/anime/types';
import { computed } from 'vue';
import { Head } from '@inertiajs/vue3';
import ExternalLink from '@/Components/ExternalLink.vue';
import DangerButton from '@/Components/DangerButton.vue';
import DangerButton from '@/Components/Button/DangerButton.vue';
const props = defineProps<{
anime: AnimeWithRelations;
Expand Down
8 changes: 4 additions & 4 deletions src/resources/js/Pages/Auth/ConfirmPassword.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script setup lang="ts">
import GuestLayout from '@/Layouts/GuestLayout.vue';
import InputError from '@/Components/InputError.vue';
import InputLabel from '@/Components/InputLabel.vue';
import PrimaryButton from '@/Components/PrimaryButton.vue';
import TextInput from '@/Components/TextInput.vue';
import InputError from '@/Components/Input/InputError.vue';
import InputLabel from '@/Components/Input/InputLabel.vue';
import PrimaryButton from '@/Components/Button/PrimaryButton.vue';
import TextInput from '@/Components/Input/TextInput.vue';
import { Head, useForm } from '@inertiajs/vue3';
const form = useForm({
Expand Down
8 changes: 4 additions & 4 deletions src/resources/js/Pages/Auth/Login.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script setup lang="ts">
import Checkbox from '@/Components/Checkbox.vue';
import GuestLayout from '@/Layouts/GuestLayout.vue';
import InputError from '@/Components/InputError.vue';
import InputLabel from '@/Components/InputLabel.vue';
import PrimaryButton from '@/Components/PrimaryButton.vue';
import TextInput from '@/Components/TextInput.vue';
import InputError from '@/Components/Input/InputError.vue';
import InputLabel from '@/Components/Input/InputLabel.vue';
import PrimaryButton from '@/Components/Button/PrimaryButton.vue';
import TextInput from '@/Components/Input/TextInput.vue';
import { Head, useForm } from '@inertiajs/vue3';
defineProps<{
Expand Down
8 changes: 4 additions & 4 deletions src/resources/js/Pages/Auth/Register.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script setup lang="ts">
import GuestLayout from '@/Layouts/GuestLayout.vue';
import InputError from '@/Components/InputError.vue';
import InputLabel from '@/Components/InputLabel.vue';
import PrimaryButton from '@/Components/PrimaryButton.vue';
import TextInput from '@/Components/TextInput.vue';
import InputError from '@/Components/Input/InputError.vue';
import InputLabel from '@/Components/Input/InputLabel.vue';
import PrimaryButton from '@/Components/Button/PrimaryButton.vue';
import TextInput from '@/Components/Input/TextInput.vue';
import { Head, Link, useForm } from '@inertiajs/vue3';
const form = useForm({
Expand Down
6 changes: 3 additions & 3 deletions src/resources/js/Pages/Auth/VerifyEmail.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { computed } from 'vue';
import GuestLayout from '@/Layouts/GuestLayout.vue';
import PrimaryButton from '@/Components/PrimaryButton.vue';
import PrimaryButton from '@/Components/Button/PrimaryButton.vue';
import { Head, Link, useForm } from '@inertiajs/vue3';
const props = defineProps<{
Expand Down Expand Up @@ -49,8 +49,8 @@ const verificationLinkSent = computed(() => props.status === 'verification-link-
method="post"
as="button"
class="underline text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:focus:ring-offset-gray-800"
>Log Out</Link
>
>Log Out
</Link>
</div>
</form>
</GuestLayout>
Expand Down
2 changes: 1 addition & 1 deletion src/resources/js/Pages/Dashboard/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue';
import { Head } from '@inertiajs/vue3';
import { AnimePerDomain, AnimeWithRelations } from '@/types/anime/types';
import StatisticCards from '@/Pages/Dashboard/Partials/StatisticCards.vue';
import Carousel from '@/Components/Carousel.vue';
import Carousel from '@/Pages/Dashboard/Partials/Carousel.vue';
import Charts from '@/Pages/Dashboard/Partials/Charts.vue';
import { provide } from 'vue';
Expand Down
File renamed without changes.
9 changes: 4 additions & 5 deletions src/resources/js/Pages/Invitation/Partials/InvitationForm.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script setup lang="ts">
import PrimaryButton from '@/Components/PrimaryButton.vue';
import InputError from '@/Components/InputError.vue';
import InputLabel from '@/Components/InputLabel.vue';
import TextInput from '@/Components/TextInput.vue';
import PrimaryButton from '@/Components/Button/PrimaryButton.vue';
import InputError from '@/Components/Input/InputError.vue';
import InputLabel from '@/Components/Input/InputLabel.vue';
import TextInput from '@/Components/Input/TextInput.vue';
import { useForm } from '@inertiajs/vue3';
const form = useForm({
Expand All @@ -29,7 +29,6 @@ const submit = () => {
type="email"
class="mt-1 block w-full"
required
autofocus
autocomplete="email"
/>

Expand Down
12 changes: 6 additions & 6 deletions src/resources/js/Pages/Profile/Partials/DeleteUserForm.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script setup lang="ts">
import DangerButton from '@/Components/DangerButton.vue';
import InputError from '@/Components/InputError.vue';
import InputLabel from '@/Components/InputLabel.vue';
import DangerButton from '@/Components/Button/DangerButton.vue';
import InputError from '@/Components/Input/InputError.vue';
import InputLabel from '@/Components/Input/InputLabel.vue';
import Modal from '@/Components/Modal.vue';
import SecondaryButton from '@/Components/SecondaryButton.vue';
import TextInput from '@/Components/TextInput.vue';
import SecondaryButton from '@/Components/Button/SecondaryButton.vue';
import TextInput from '@/Components/Input/TextInput.vue';
import { useForm } from '@inertiajs/vue3';
import { nextTick, ref } from 'vue';
Expand Down Expand Up @@ -84,7 +84,7 @@ const closeModal = () => {
</div>

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

<DangerButton
class="ml-3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import TelegramLoginWidget from '@/Components/TelegramLoginWidget.vue';
import { TelegramUser } from '@/types/telegram/types';
import { router, usePage } from '@inertiajs/vue3';
import { computed } from 'vue';
import DangerButton from '@/Components/DangerButton.vue';
import DangerButton from '@/Components/Button/DangerButton.vue';
const page = usePage();
const telegramUser = computed(() => page.props.auth.user.telegram_user);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script setup lang="ts">
import InputError from '@/Components/InputError.vue';
import InputLabel from '@/Components/InputLabel.vue';
import PrimaryButton from '@/Components/PrimaryButton.vue';
import TextInput from '@/Components/TextInput.vue';
import InputError from '@/Components/Input/InputError.vue';
import InputLabel from '@/Components/Input/InputLabel.vue';
import PrimaryButton from '@/Components/Button/PrimaryButton.vue';
import TextInput from '@/Components/Input/TextInput.vue';
import { useForm } from '@inertiajs/vue3';
import { ref } from 'vue';
Expand Down
Loading

0 comments on commit 4398d92

Please sign in to comment.