Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
SethSharp committed Feb 19, 2024
1 parent 5cad2ee commit 965917c
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 23 deletions.
1 change: 1 addition & 0 deletions app/Domain/Blog/Actions/StoreBlogAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function __invoke(StoreBlogRequest $storeBlogRequest): Blog
$blog = Blog::create([
'author_id' => auth()->user()->id,
...$storeBlogRequest->validated(),
'published_at' => null
]);

$blog->tags()->sync($tags);
Expand Down
1 change: 1 addition & 0 deletions app/Domain/Blog/Actions/UpdateBlogAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function __invoke(Blog $blog, UpdateBlogRequest $updateBlogRequest): Blog

$blog->update([
...$updateBlogRequest->validated(),
'published_at' => null
]);

$blog->tags()->sync($tags);
Expand Down
3 changes: 2 additions & 1 deletion app/Domain/Blog/Models/Blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class Blog extends Model
protected $guarded = [];

protected $casts = [
'is_draft' => 'bool'
'is_draft' => 'bool',
'published_at' => 'timestamp'
];

public function author(): BelongsTo
Expand Down
7 changes: 1 addition & 6 deletions app/Domain/Blog/Policies/BlogPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class BlogPolicy
{
public function before(User $user): ?bool
public function before(User $user, string $ability): ?bool
{
if ($user->hasRole(User::ROLE_ADMIN)) {
return true;
Expand All @@ -30,9 +30,4 @@ public function view(User $user): bool
{
return $user->hasRole(User::ROLE_AUTHOR);
}

public function viewPublic(User $user, Blog $blog): bool
{
return ! $blog->isDraft();
}
}
11 changes: 10 additions & 1 deletion app/Http/Controllers/Views/Blogs/ShowBlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,23 @@
namespace App\Http\Controllers\Views\Blogs;

use Illuminate\View\View;
use App\Domain\Iam\Models\User;
use App\Domain\Blog\Models\Blog;
use App\Http\Controllers\Controller;

class ShowBlogController extends Controller
{
public function __invoke(Blog $blog): View
{
$this->authorize('viewPublic', [Blog::class, $blog]);
if ($blog->isDraft()) {
if (auth()->check()) {
if (! auth()->user()->hasRole([User::ROLE_ADMIN])) {
abort(403, 'Blog is currently in a draft status');
}
} else {
abort(403, 'Blog is currently in a draft status');
}
}

return view('blogs.show', [
'blog' => $blog
Expand Down
18 changes: 9 additions & 9 deletions resources/js/Layouts/AuthenticatedLayout.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script setup>
import { ref } from 'vue'
import {ref} from 'vue'
import ApplicationLogo from '@/Components/ApplicationLogo.vue'
import Dropdown from '@/Components/Dropdowns/Dropdown.vue'
import DropdownLink from '@/Components/Dropdowns/DropdownLink.vue'
import NavLink from '@/Components/Links/NavLink.vue'
import ResponsiveNavLink from '@/Components/Links/ResponsiveNavLink.vue'
import { Head, Link } from '@inertiajs/vue3'
import {Head, Link} from '@inertiajs/vue3'
import Notifications from '@/Components/Notifications.vue'
defineProps({
Expand All @@ -32,7 +32,7 @@ const links = [
</script>

<template>
<Head :title="title" />
<Head :title="title"/>

<div>
<div class="min-h-screen bg-gray-100">
Expand All @@ -43,7 +43,7 @@ const links = [
<div class="flex">
<!-- Logo -->
<div class="shrink-0 flex items-center">
<Link :href="route('dashboard.home')">
<Link :href="route('dashboard.blogs.index')">
<ApplicationLogo
class="block h-9 w-auto fill-current text-gray-800"
/>
Expand Down Expand Up @@ -154,8 +154,8 @@ const links = [
>
<div class="pt-2 pb-3 space-y-1">
<ResponsiveNavLink
:href="route('dashboard.home')"
:active="route().current('dashboard.home')"
:href="route('dashboard.blogs.index')"
:active="route().current('dashboard.blogs.*')"
>
Dashboard
</ResponsiveNavLink>
Expand Down Expand Up @@ -187,18 +187,18 @@ const links = [
<!-- Page Heading -->
<header class="bg-white shadow" v-if="$slots.header">
<div class="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">
<slot name="header" />
<slot name="header"/>
</div>
</header>

<!-- Page Content -->
<main>
<div class="bg-white rounded-xl m-6 p-12">
<slot />
<slot/>
</div>
</main>

<Notifications :errors="$page.props.errors" :success="$page.props.success" />
<Notifications :errors="$page.props.errors" :success="$page.props.success"/>
</div>
</div>
</template>
8 changes: 4 additions & 4 deletions resources/js/Layouts/ProfileLayout.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<script setup>
import ApplicationLogo from '@/Components/ApplicationLogo.vue'
import { Link } from '@inertiajs/vue3'
import {Link} from '@inertiajs/vue3'
</script>

<template>
<div class="min-h-screen flex flex-col sm:justify-center items-center pt-6 sm:pt-0 bg-gray-100">
<div>
<a href="/">
<ApplicationLogo class="w-20 h-20 fill-current text-gray-500" />
<ApplicationLogo class="w-20 h-20 fill-current text-gray-500"/>
</a>
</div>

<div
class="w-full max-w-xl mt-6 px-6 py-4 bg-white shadow-md overflow-hidden sm:rounded-lg"
class="w-3/4 mt-6 px-6 py-4 bg-white shadow-md overflow-hidden sm:rounded-lg"
>
<slot />
<slot/>
</div>
</div>
</template>
2 changes: 1 addition & 1 deletion resources/views/components/blogs/card.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</div>

<div class="flex justify-end font-medium text-gray-400">
<span class="mr-4 my-3"> {{$blog->published_at}} </span>
<span class="mr-4 my-3"> {{ Carbon\Carbon::parse($blog->published_at)->diffForHumans() }} </span>
</div>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion resources/views/livewire/blogs/show-blog.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

<div class="mt-2 text-gray-400 font-medium text-lg">
@if($blog->published_at)
Published by {{ $blog->author->name }} {{ $blog->published_at->diffForHumans() }}
Published
by {{ $blog->author->name }} {{ Carbon\Carbon::parse($blog->published_at)->diffForHumans() }}
@else
This blog is in a draft status
@endif
Expand Down

0 comments on commit 965917c

Please sign in to comment.