Dever v0.0.2

This commit is contained in:
Codex committed 2026-11-27 06:03:56 +00:00
commit e6e175ebcf
816 files changed
+120349

No files matched your search

@@ -0,0 +1 @@
负责文章草稿、发布和公开阅读。字段见 [data/article.dv](data/article.dv),主流程见 [flow/article.dv](flow/article.dv),完整用法见 [项目说明](../../../README.md),符号说明见 [文章主题](doc/article.md)。
@@ -0,0 +1,17 @@
post create = app.create
put edit = app.edit
post publish = app.publish
post unpublish = app.unpublish
delete remove = app.remove
get list = app.list
post createCategory = app.createCategory
put assignCategory = app.assignCategory
post moderate = app.moderate
@@ -0,0 +1,7 @@
public get list = app.browse
public get detail = app.detail
public post comment = app.comment
public get comments = app.comments
@@ -0,0 +1,12 @@
type Status {
Draft
Published
}
type Article {
title: Text(1, 120)
body: Text(1, 20000) raw
status: Status default Draft index
published_at: DateTime?
category_id: data.category.id?
}
@@ -0,0 +1,3 @@
type Category {
name: Text(1, 80) unique
}
@@ -0,0 +1,12 @@
type Status {
Pending
Approved
Rejected
}
type Comment {
article_id: data.id
author: Text(1, 40)
body: Text(1, 2000)
status: Status default Pending index
}
@@ -0,0 +1,33 @@
# 文章
## content.article.app.publish
只有草稿可以发布。条件更新与结果检查在同一个事务内完成;成功无业务输出,不为回传整条文章再查询一次。
## content.article.app.edit
仅编辑草稿。数据模型处理字段规范化和长度约束,业务不重复检查。本例采用最后一次成功写入生效,不提供多人编辑的版本冲突检测。
## content.article.app.browse
公开返回已发布文章,每页十条。后台完整列表绑定需要身份与角色权限的 HTTP GET。
## content.article.app.comment
只有已发布的文章可以评论,其他情况按不存在处理。在事务中以条件更新锁定文章,再写评论,避免检查发布状态后被并发撤回。评论默认待审核,不在公开列表中出现。`article_id` 是普通外键;自动关系不参与默认接口输出。
## content.article.app.moderate
审核只处理待审核的评论,决定由 `app.verdict` 的规则表选择,条件更新与结果检查在同一个事务内完成;已审核的评论再次审核按冲突处理。
## content.article.app.comments
公开返回已发布文章通过审核的评论,每页二十条,按创建时间升序。撤回后不再公开评论。
## content.article.app.createCategory
分类名称在数据模型中唯一,重复创建由数据库约束拒绝。
## content.article.app.assignCategory
把文章归入分类;文章不存在时按不存在处理。`category_id` 是普通外键,文章直接输出存储字段。
@@ -0,0 +1,65 @@
transaction flow create(title: Text, body: Text) (article: data.Article) {
article = data.create({ title = title, body = body })
}
transaction flow edit(article_id: data.id, title: Text, body: Text) () {
changed = data.update({ where = id == article_id and status == Draft }, { title = title, body = body })
check changed == 1 else Conflict
}
transaction flow publish(article_id: data.id) () {
now = dever.time.now()
changed = data.update({ where = id == article_id and status == Draft }, { status = Published, published_at = now })
check changed == 1 else Conflict
}
transaction flow unpublish(article_id: data.id) () {
changed = data.update({ where = id == article_id and status == Published }, { status = Draft, published_at = null })
check changed == 1 else Conflict
}
transaction flow remove(article_id: data.id) () {
changed = data.delete({ where = id == article_id and status == Draft })
check changed == 1 else Conflict
}
flow list(page: Int >= 1) (articles: data.Page) {
articles = data.page(order = [created_at.desc, id.desc], page = page, size = 10)
}
flow browse(page: Int >= 1) (articles: data.Page) {
articles = data.page(status == Published, order = [published_at.desc, id.desc], page = page, size = 10)
}
flow detail(article_id: data.id) (article: data.Article) {
found = data.first(id == article_id and status == Published)
check found != null else NotFound
article = found
}
transaction flow createCategory(name: Text) (category: data.category.Category) {
category = data.category.create({ name = name })
}
transaction flow assignCategory(article_id: data.id, category_id: data.category.id) () {
changed = data.update({ where = id == article_id }, { category_id = category_id })
check changed == 1 else NotFound
}
transaction flow comment(article_id: data.id, author: Text, body: Text) (comment: data.comment.Comment) {
accepted = data.update({ where = id == article_id and status == Published }, { status = Published })
check accepted == 1 else NotFound
comment = data.comment.create({ article_id = article_id, author = author, body = body })
}
transaction flow moderate(comment_id: data.comment.id, approve: Bool) () {
chosen = app.verdict(approve)
changed = data.comment.update({ where = id == comment_id and status == Pending }, { status = chosen })
check changed == 1 else Conflict
}
flow comments(target_id: data.id, page: Int >= 1) (comments: data.comment.Page) {
article = data.first(id == target_id and status == Published)
check article != null else NotFound
comments = data.comment.page(article_id == target_id and status == Approved, order = [created_at.asc, id.asc], page = page, size = 20)
}
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,5 @@
rule verdict(approve: Bool) (status: data.comment.Status)
approve {
true => Approved
false => Rejected
}