feat: 分类系统 + 标签系统 — Phase 4 完成

分类:Model/Repo/Service/Controller + 管理后台树形页面 + 首页导航栏
标签:Model/Repo/Service/Controller + /tags/{slug} 落地页 + 写文章页输入
Post 加 CategoryID,Create/Update 支持分类和标签
SQL 迁移含 categories/tags/post_tags 表及预设未分类
This commit is contained in:
2026-06-22 00:30:29 +08:00
parent 977c52513a
commit 0b8f6f890d
30 changed files with 988 additions and 13 deletions

View File

@ -3,6 +3,7 @@ package service
import (
"errors"
"fmt"
"strconv"
"time"
"metazone.cc/mce/internal/common"
@ -68,7 +69,7 @@ func (s *PostService) findPostWithAuthor(id uint) (*model.Post, error) {
// Create 创建帖子
// body 为 Vditor 输出的 Markdown后端直接存储不做 HTML 消毒
// MD 是纯文本,无 XSS 注入风险;前端渲染时由 Vditor 转 HTML
func (s *PostService) Create(userID uint, title, body string, visibility, postType, reprintSource, declaration string, reprintProhibited bool) (*model.Post, error) {
func (s *PostService) Create(userID uint, title, body string, visibility, postType, reprintSource, declaration string, reprintProhibited bool, categoryID string) (*model.Post, error) {
status := model.PostStatusApproved
if s.auditEnabled() {
status = model.PostStatusDraft
@ -87,6 +88,11 @@ func (s *PostService) Create(userID uint, title, body string, visibility, postTy
Declaration: declaration,
ReprintProhibited: reprintProhibited,
}
// 解析分类 ID
if cid, err := strconv.ParseUint(categoryID, 10, 64); err == nil && cid > 0 {
id := uint(cid)
post.CategoryID = &id
}
if err := s.repo.Create(post); err != nil {
return nil, err
}