Feature/blog cms public api#12
Open
vH192Hv wants to merge 7 commits into
Open
Conversation
- Add Post model with title, slug, content, excerpt, coverImage, status, timestamps - Add Tag model with name and slug - Add PostTag join table for many-to-many relationship - Add PostStatus enum (DRAFT, PUBLISHED, ARCHIVED) - Add posts relation to User model Co-Authored-By: Claude <noreply@anthropic.com>
- Add seedBlogPosts function with sample posts and tags - Register seed in main.wasp.ts db.seeds array Co-Authored-By: Claude <noreply@anthropic.com>
- Define getAllPosts, getPost, getPostBySlug, getPublishedPosts queries - Define createPost, updatePost, deletePost actions - Define getAllTags, createTag, deleteTag tag operations - Register blogCmsSpec in main.wasp.ts Co-Authored-By: Claude <noreply@anthropic.com>
- Add isValidSlug, generateSlug with regex format + length checks - Add ALLOWED_TRANSITIONS map and transition validation helpers - File is browser+server safe (no wasp/server imports) Co-Authored-By: Claude <noreply@anthropic.com>
…rmissions) - Post queries: getAllPosts (admin, paginated, filters), getPost (admin, by ID), getPostBySlug (public, PUBLISHED only), getPublishedPosts (public, paginated) - Post mutations: createPost (slug gen/validate, status validation), updatePost (status transitions, tag replacement, publishedAt mgmt), deletePost (by ID with existence check) - Tag operations: getAllTags (with post count), createTag (name/slug uniqueness), deleteTag (cascade removes PostTag entries) - Permission guard: requireAdmin on all mutating + admin-read operations - Slug helpers imported from shared utils.ts - Status transitions validated via isAllowedTransition from utils.ts Co-Authored-By: Claude <noreply@anthropic.com>
- GET /api/blog/:slug returns published post with author and tags - Returns 400 for missing slug, 404 for non-published or missing posts - Proper Date serialization (toISOString) for all timestamp fields - No authentication required Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
设计方案
新增公开 REST API
响应格式
成功 (200):
{ "id": "uuid", "title": "Post Title", "slug": "post-slug", "content": "Markdown content...", "excerpt": "Short description", "coverImage": "https://...", "status": "PUBLISHED", "authorId": "uuid", "author": { "id": "uuid", "username": "admin" }, "tags": [ { "id": "uuid", "name": "Getting Started", "slug": "getting-started" } ], "publishedAt": "2026-01-01T00:00:00.000Z", "createdAt": "2025-12-01T00:00:00.000Z", "updatedAt": "2026-01-01T00:00:00.000Z" }未找到或未发布 (404):
{ "error": "Post not found" }缺少参数 (400):
{ "error": "Slug parameter is required" }安全设计
.toISOString()序列化Wasp Spec 声明
与现有查询的关系
此 API 端点补充了 Branch 2 中已实现的 Wasp Query:
getPostBySlug— Wasp Query(同功能,供 Wasp 前端调用)getPublishedPostBySlugApi— REST API(供外部消费者如 Astro 博客调用)两者返回相同数据结构,仅调用方式不同。
执行方案
operations.ts添加GetPublishedPostBySlugApi类型导入getPublishedPostBySlugApihandler(slug 校验 + 404 + Date 序列化)blog-cms.wasp.ts声明 API 路由api()spec 签名格式适配 Wasp v0.24+文件变更
template/app/src/blog-cms/operations.tstemplate/app/src/blog-cms/blog-cms.wasp.ts🔽 依赖 PR2 (operations) — 合并顺序第 3(与 PR3 并行)