UI: portal/header refinements, board index UX, and user settings
This commit is contained in:
@@ -11,7 +11,7 @@ class ForumController extends Controller
|
||||
{
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$query = Forum::query();
|
||||
$query = Forum::query()->withoutTrashed();
|
||||
|
||||
$parentParam = $request->query('parent');
|
||||
if (is_array($parentParam) && array_key_exists('exists', $parentParam)) {
|
||||
@@ -57,6 +57,10 @@ class ForumController extends Controller
|
||||
|
||||
$parentId = $this->parseIriId($data['parent'] ?? null);
|
||||
|
||||
if ($data['type'] === 'forum' && !$parentId) {
|
||||
return response()->json(['message' => 'Forums must belong to a category.'], 422);
|
||||
}
|
||||
|
||||
if ($parentId) {
|
||||
$parent = Forum::findOrFail($parentId);
|
||||
if ($parent->type !== 'category') {
|
||||
@@ -87,6 +91,12 @@ class ForumController extends Controller
|
||||
]);
|
||||
|
||||
$parentId = $this->parseIriId($data['parent'] ?? null);
|
||||
$nextType = $data['type'] ?? $forum->type;
|
||||
$nextParentId = array_key_exists('parent', $data) ? $parentId : $forum->parent_id;
|
||||
|
||||
if ($nextType === 'forum' && !$nextParentId) {
|
||||
return response()->json(['message' => 'Forums must belong to a category.'], 422);
|
||||
}
|
||||
|
||||
if (array_key_exists('parent', $data)) {
|
||||
if ($parentId) {
|
||||
@@ -115,8 +125,10 @@ class ForumController extends Controller
|
||||
return response()->json($this->serializeForum($forum));
|
||||
}
|
||||
|
||||
public function destroy(Forum $forum): JsonResponse
|
||||
public function destroy(Request $request, Forum $forum): JsonResponse
|
||||
{
|
||||
$forum->deleted_by = $request->user()?->id;
|
||||
$forum->save();
|
||||
$forum->delete();
|
||||
|
||||
return response()->json(null, 204);
|
||||
|
||||
@@ -11,7 +11,7 @@ class PostController extends Controller
|
||||
{
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$query = Post::query();
|
||||
$query = Post::query()->withoutTrashed();
|
||||
|
||||
$threadParam = $request->query('thread');
|
||||
if (is_string($threadParam)) {
|
||||
@@ -48,8 +48,10 @@ class PostController extends Controller
|
||||
return response()->json($this->serializePost($post), 201);
|
||||
}
|
||||
|
||||
public function destroy(Post $post): JsonResponse
|
||||
public function destroy(Request $request, Post $post): JsonResponse
|
||||
{
|
||||
$post->deleted_by = $request->user()?->id;
|
||||
$post->save();
|
||||
$post->delete();
|
||||
|
||||
return response()->json(null, 204);
|
||||
|
||||
@@ -11,7 +11,7 @@ class ThreadController extends Controller
|
||||
{
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$query = Thread::query();
|
||||
$query = Thread::query()->withoutTrashed()->with('user');
|
||||
|
||||
$forumParam = $request->query('forum');
|
||||
if (is_string($forumParam)) {
|
||||
@@ -31,6 +31,7 @@ class ThreadController extends Controller
|
||||
|
||||
public function show(Thread $thread): JsonResponse
|
||||
{
|
||||
$thread->loadMissing('user');
|
||||
return response()->json($this->serializeThread($thread));
|
||||
}
|
||||
|
||||
@@ -59,8 +60,10 @@ class ThreadController extends Controller
|
||||
return response()->json($this->serializeThread($thread), 201);
|
||||
}
|
||||
|
||||
public function destroy(Thread $thread): JsonResponse
|
||||
public function destroy(Request $request, Thread $thread): JsonResponse
|
||||
{
|
||||
$thread->deleted_by = $request->user()?->id;
|
||||
$thread->save();
|
||||
$thread->delete();
|
||||
|
||||
return response()->json(null, 204);
|
||||
@@ -91,6 +94,7 @@ class ThreadController extends Controller
|
||||
'body' => $thread->body,
|
||||
'forum' => "/api/forums/{$thread->forum_id}",
|
||||
'user_id' => $thread->user_id,
|
||||
'user_name' => $thread->user?->name,
|
||||
'created_at' => $thread->created_at?->toIso8601String(),
|
||||
'updated_at' => $thread->updated_at?->toIso8601String(),
|
||||
];
|
||||
|
||||
47
app/Http/Controllers/UserSettingController.php
Normal file
47
app/Http/Controllers/UserSettingController.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\UserSetting;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UserSettingController extends Controller
|
||||
{
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
$query = UserSetting::query()->where('user_id', $user->id);
|
||||
|
||||
if ($request->filled('key')) {
|
||||
$query->where('key', $request->query('key'));
|
||||
}
|
||||
|
||||
$settings = $query->get()->map(fn (UserSetting $setting) => [
|
||||
'id' => $setting->id,
|
||||
'key' => $setting->key,
|
||||
'value' => $setting->value,
|
||||
]);
|
||||
|
||||
return response()->json($settings);
|
||||
}
|
||||
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'key' => ['required', 'string', 'max:191'],
|
||||
'value' => ['nullable', 'array'],
|
||||
]);
|
||||
|
||||
$setting = UserSetting::updateOrCreate(
|
||||
['user_id' => $request->user()->id, 'key' => $data['key']],
|
||||
['value' => $data['value'] ?? []]
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
'id' => $setting->id,
|
||||
'key' => $setting->key,
|
||||
'value' => $setting->value,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user