BLOG-126 Post management (list and create) #139

Merged
squid merged 10 commits from BLOG-126_post_management into main 2025-10-15 04:21:15 +08:00
6 changed files with 12 additions and 12 deletions
Showing only changes of commit df5bba022e - Show all commits

View File

@ -1,6 +1,9 @@
import { CreatePostRequestDto } from '$lib/post/adapter/gateway/creatPostRequestDto'; import { CreatePostRequestDto } from '$lib/post/adapter/gateway/creatPostRequestDto';
import type { PostApiService } from '$lib/post/adapter/gateway/postApiService'; import type { PostApiService } from '$lib/post/adapter/gateway/postApiService';
import type { CreatePostParams, PostRepository } from '$lib/post/application/gateway/postRepository'; import type {
CreatePostParams,
PostRepository,
} from '$lib/post/application/gateway/postRepository';
import type { Post } from '$lib/post/domain/entity/post'; import type { Post } from '$lib/post/domain/entity/post';
import type { PostInfo } from '$lib/post/domain/entity/postInfo'; import type { PostInfo } from '$lib/post/domain/entity/postInfo';

View File

@ -38,8 +38,7 @@ export class PostBloc {
case PostEventType.PostLoadedEvent: case PostEventType.PostLoadedEvent:
return this.loadPost(event.id); return this.loadPost(event.id);
case PostEventType.PostCreatedEvent: case PostEventType.PostCreatedEvent:
const { semanticId, title } = event; return this.createPost(event.params);
return this.createPost({ semanticId, title });
} }
} }
@ -95,6 +94,5 @@ interface PostLoadedEvent {
interface PostCreatedEvent { interface PostCreatedEvent {
event: PostEventType.PostCreatedEvent; event: PostEventType.PostCreatedEvent;
semanticId: string; params: CreatePostParams;
title: string;
} }

View File

@ -6,7 +6,7 @@
.string() .string()
.max(100) .max(100)
.regex(/\D/) .regex(/\D/)
.regex(/^[a-zA-Z0-9_\-]+$/), .regex(/^[a-zA-Z0-9_-]+$/),
title: z.string().trim().nonempty().max(100), title: z.string().trim().nonempty().max(100),
}); });

View File

@ -1,5 +1,4 @@
<script lang="ts"> <script lang="ts">
import { goto } from '$app/navigation';
import { StatusType } from '$lib/common/adapter/presenter/asyncState'; import { StatusType } from '$lib/common/adapter/presenter/asyncState';
import { PostBloc, PostEventType } from '$lib/post/adapter/presenter/postBloc'; import { PostBloc, PostEventType } from '$lib/post/adapter/presenter/postBloc';
import CreatePostDialog, { import CreatePostDialog, {
@ -14,7 +13,7 @@
const isLoading = $derived(state.status === StatusType.Loading); const isLoading = $derived(state.status === StatusType.Loading);
async function onCreatePostDialogSubmit(params: CreatePostDialogFormParams) { async function onCreatePostDialogSubmit(params: CreatePostDialogFormParams) {
const state = await postBloc.dispatch({ event: PostEventType.PostCreatedEvent, ...params }); const state = await postBloc.dispatch({ event: PostEventType.PostCreatedEvent, params });
if (state.status === StatusType.Success) { if (state.status === StatusType.Success) {
toast.success(`Post created successfully with ID: ${state.data.id}`); toast.success(`Post created successfully with ID: ${state.data.id}`);

View File

@ -36,7 +36,7 @@
{:else if !isAuthenticated} {:else if !isAuthenticated}
<ErrorPage /> <ErrorPage />
{:else} {:else}
<div class="min-h-content-height grid grid-cols-[auto_1fr]"> <div class="grid min-h-content-height grid-cols-[auto_1fr]">
<DashboardNavbar {links} /> <DashboardNavbar {links} />
{@render children()} {@render children()}
</div> </div>

View File

@ -4,9 +4,9 @@
import PostManagementPage from '$lib/post/framework/ui/PostManagementPage.svelte'; import PostManagementPage from '$lib/post/framework/ui/PostManagementPage.svelte';
import { getContext, setContext } from 'svelte'; import { getContext, setContext } from 'svelte';
const container = getContext<Container>(Container.name); const container = getContext<Container>(Container.name);
const postBloc = container.createPostBloc(); const postBloc = container.createPostBloc();
setContext(PostBloc.name, postBloc); setContext(PostBloc.name, postBloc);
</script> </script>
<PostManagementPage /> <PostManagementPage />