接口响应与文档文案全部改为英文
- 错误响应、健康检查等运行时文案改为英文 - 种子数据英文化,新增迁移 v5 更新存量内置数据(不覆盖手工修改) - Swagger 注释与 docs/ 文档全英文化 - 补充英文文案断言与 v5 迁移测试
This commit is contained in:
16 files changed
+603
-489
No files matched your search
+35
-35
@@ -13,8 +13,8 @@ import (
|
||||
|
||||
// Request 创建/更新便签请求。
|
||||
type Request struct {
|
||||
Title string `json:"title" binding:"required,max=200" example:"购物清单"`
|
||||
Content string `json:"content" example:"牛奶、鸡蛋"`
|
||||
Title string `json:"title" binding:"required,max=200" example:"Shopping list"`
|
||||
Content string `json:"content" example:"Milk, eggs"`
|
||||
}
|
||||
|
||||
// ListResponse 便签分页列表响应。
|
||||
@@ -26,16 +26,16 @@ type ListResponse struct {
|
||||
}
|
||||
|
||||
// @Summary List notes
|
||||
// @Description 分页查询便签列表,按 id 倒序返回。page 从 1 开始;page_size 取值 1-100,默认 20。
|
||||
// @Description List notes ordered by id DESC. page starts at 1; page_size is 1-100, default 20.
|
||||
// @Tags notes
|
||||
// @Produce json
|
||||
// @Param page query int false "页码,默认 1" example(1)
|
||||
// @Param page_size query int false "每页数量,默认 20,最大 100" example(20)
|
||||
// @Param page query int false "Page number, default 1" example(1)
|
||||
// @Param page_size query int false "Page size, default 20, max 100" example(20)
|
||||
// @Success 200 {object} note.ListResponse
|
||||
// @Failure 500 {object} httpx.ErrorResponse
|
||||
// @Security BearerAuth
|
||||
// @Failure 401 {object} httpx.ErrorResponse "未登录或登录已过期"
|
||||
// @Failure 403 {object} httpx.ErrorResponse "账号已被禁用"
|
||||
// @Failure 401 {object} httpx.ErrorResponse "unauthorized or session expired"
|
||||
// @Failure 403 {object} httpx.ErrorResponse "account disabled"
|
||||
// @Router /notes [get]
|
||||
func List(db *gorm.DB) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
@@ -68,23 +68,23 @@ func List(db *gorm.DB) gin.HandlerFunc {
|
||||
}
|
||||
|
||||
// @Summary Create a note
|
||||
// @Description 创建便签。title 必填且最长 200 字符,content 可选。
|
||||
// @Description Create a note. title is required (max 200 chars); content is optional.
|
||||
// @Tags notes
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param note body note.Request true "便签内容"
|
||||
// @Param note body note.Request true "Note payload"
|
||||
// @Success 201 {object} model.Note
|
||||
// @Failure 400 {object} httpx.ErrorResponse "参数无效"
|
||||
// @Failure 400 {object} httpx.ErrorResponse "invalid request"
|
||||
// @Failure 500 {object} httpx.ErrorResponse
|
||||
// @Security BearerAuth
|
||||
// @Failure 401 {object} httpx.ErrorResponse "未登录或登录已过期"
|
||||
// @Failure 403 {object} httpx.ErrorResponse "账号已被禁用"
|
||||
// @Failure 401 {object} httpx.ErrorResponse "unauthorized or session expired"
|
||||
// @Failure 403 {object} httpx.ErrorResponse "account disabled"
|
||||
// @Router /notes [post]
|
||||
func Create(db *gorm.DB) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
var req Request
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, httpx.ErrorResponse{Error: "参数无效: " + err.Error()})
|
||||
c.JSON(http.StatusBadRequest, httpx.ErrorResponse{Error: "invalid request: " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -98,17 +98,17 @@ func Create(db *gorm.DB) gin.HandlerFunc {
|
||||
}
|
||||
|
||||
// @Summary Get a note
|
||||
// @Description 按 id 查询单个便签。
|
||||
// @Description Get a note by id.
|
||||
// @Tags notes
|
||||
// @Produce json
|
||||
// @Param id path int true "便签 ID" example(1)
|
||||
// @Param id path int true "Note ID" example(1)
|
||||
// @Success 200 {object} model.Note
|
||||
// @Failure 400 {object} httpx.ErrorResponse "id 无效"
|
||||
// @Failure 404 {object} httpx.ErrorResponse "记录不存在"
|
||||
// @Failure 400 {object} httpx.ErrorResponse "invalid id"
|
||||
// @Failure 404 {object} httpx.ErrorResponse "record not found"
|
||||
// @Failure 500 {object} httpx.ErrorResponse
|
||||
// @Security BearerAuth
|
||||
// @Failure 401 {object} httpx.ErrorResponse "未登录或登录已过期"
|
||||
// @Failure 403 {object} httpx.ErrorResponse "账号已被禁用"
|
||||
// @Failure 401 {object} httpx.ErrorResponse "unauthorized or session expired"
|
||||
// @Failure 403 {object} httpx.ErrorResponse "account disabled"
|
||||
// @Router /notes/{id} [get]
|
||||
func Get(db *gorm.DB) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
@@ -127,19 +127,19 @@ func Get(db *gorm.DB) gin.HandlerFunc {
|
||||
}
|
||||
|
||||
// @Summary Update a note
|
||||
// @Description 全量更新便签的 title 与 content,字段校验规则同创建。
|
||||
// @Description Update title and content; validation is the same as create.
|
||||
// @Tags notes
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "便签 ID" example(1)
|
||||
// @Param note body note.Request true "便签内容"
|
||||
// @Param id path int true "Note ID" example(1)
|
||||
// @Param note body note.Request true "Note payload"
|
||||
// @Success 200 {object} model.Note
|
||||
// @Failure 400 {object} httpx.ErrorResponse "参数无效或 id 无效"
|
||||
// @Failure 404 {object} httpx.ErrorResponse "记录不存在"
|
||||
// @Failure 400 {object} httpx.ErrorResponse "invalid request or id"
|
||||
// @Failure 404 {object} httpx.ErrorResponse "record not found"
|
||||
// @Failure 500 {object} httpx.ErrorResponse
|
||||
// @Security BearerAuth
|
||||
// @Failure 401 {object} httpx.ErrorResponse "未登录或登录已过期"
|
||||
// @Failure 403 {object} httpx.ErrorResponse "账号已被禁用"
|
||||
// @Failure 401 {object} httpx.ErrorResponse "unauthorized or session expired"
|
||||
// @Failure 403 {object} httpx.ErrorResponse "account disabled"
|
||||
// @Router /notes/{id} [put]
|
||||
func Update(db *gorm.DB) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
@@ -150,7 +150,7 @@ func Update(db *gorm.DB) gin.HandlerFunc {
|
||||
|
||||
var req Request
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, httpx.ErrorResponse{Error: "参数无效: " + err.Error()})
|
||||
c.JSON(http.StatusBadRequest, httpx.ErrorResponse{Error: "invalid request: " + err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -172,17 +172,17 @@ func Update(db *gorm.DB) gin.HandlerFunc {
|
||||
}
|
||||
|
||||
// @Summary Delete a note
|
||||
// @Description 按 id 删除便签,成功时返回 204 且无响应体。
|
||||
// @Description Delete a note by id; returns 204 with no body on success.
|
||||
// @Tags notes
|
||||
// @Produce json
|
||||
// @Param id path int true "便签 ID" example(1)
|
||||
// @Success 204 "删除成功"
|
||||
// @Failure 400 {object} httpx.ErrorResponse "id 无效"
|
||||
// @Failure 404 {object} httpx.ErrorResponse "记录不存在"
|
||||
// @Param id path int true "Note ID" example(1)
|
||||
// @Success 204 "Deleted"
|
||||
// @Failure 400 {object} httpx.ErrorResponse "invalid id"
|
||||
// @Failure 404 {object} httpx.ErrorResponse "record not found"
|
||||
// @Failure 500 {object} httpx.ErrorResponse
|
||||
// @Security BearerAuth
|
||||
// @Failure 401 {object} httpx.ErrorResponse "未登录或登录已过期"
|
||||
// @Failure 403 {object} httpx.ErrorResponse "账号已被禁用"
|
||||
// @Failure 401 {object} httpx.ErrorResponse "unauthorized or session expired"
|
||||
// @Failure 403 {object} httpx.ErrorResponse "account disabled"
|
||||
// @Router /notes/{id} [delete]
|
||||
func Delete(db *gorm.DB) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
@@ -197,7 +197,7 @@ func Delete(db *gorm.DB) gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
if result.RowsAffected == 0 {
|
||||
c.JSON(http.StatusNotFound, httpx.ErrorResponse{Error: "记录不存在"})
|
||||
c.JSON(http.StatusNotFound, httpx.ErrorResponse{Error: "record not found"})
|
||||
return
|
||||
}
|
||||
c.Status(http.StatusNoContent)
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"rill/internal/model"
|
||||
@@ -80,6 +81,9 @@ func TestNoteCRUD(t *testing.T) {
|
||||
if w.Code != http.StatusNotFound {
|
||||
t.Errorf("删除后详情状态码 = %d, 期望 %d", w.Code, http.StatusNotFound)
|
||||
}
|
||||
if !strings.Contains(w.Body.String(), "record not found") {
|
||||
t.Errorf("错误文案应为英文: %s", w.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestNoteValidation(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user