chore: seal Design Vision v1 and monorepo scaffold
Archive the differentiated YuXinGu product docs, AI engineering system, design contract, and Go/Vue scaffold. Next execution prioritizes Cece-parity over early innovation (see .ai/product/STRATEGY.md). Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"success_example": {
|
||||
"code": 0,
|
||||
"message": "success",
|
||||
"data": {
|
||||
"summary": "简版结论占位",
|
||||
"profile_id": "p_123"
|
||||
}
|
||||
},
|
||||
"error_example": {
|
||||
"code": 30001,
|
||||
"message": "invalid birth date"
|
||||
},
|
||||
"list_example": {
|
||||
"code": 0,
|
||||
"message": "success",
|
||||
"data": {
|
||||
"list": [{ "slug": "mbti", "name": "MBTI" }],
|
||||
"total": 1,
|
||||
"page": 1,
|
||||
"page_size": 20
|
||||
}
|
||||
},
|
||||
"_comment": "Never use {success:true} or {ok:true} as root."
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
//go:build ignore
|
||||
|
||||
// EXAMPLE — reference shape for AI. Not compiled into apps/api.
|
||||
package examples
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type apiBody struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data interface{} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
type DecodeInput struct {
|
||||
Year int
|
||||
Month int
|
||||
Day int
|
||||
}
|
||||
|
||||
type DecodeOutput struct {
|
||||
Summary string `json:"summary"`
|
||||
}
|
||||
|
||||
type DecodeService interface {
|
||||
Decode(ctx context.Context, in DecodeInput) (*DecodeOutput, error)
|
||||
}
|
||||
|
||||
type DecodeHandler struct {
|
||||
Svc DecodeService
|
||||
}
|
||||
|
||||
// Decode handles POST /api/v1/reports/decode
|
||||
func (h *DecodeHandler) Decode(c *gin.Context) {
|
||||
var req struct {
|
||||
Year int `json:"year" binding:"required"`
|
||||
Month int `json:"month" binding:"required"`
|
||||
Day int `json:"day" binding:"required"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, apiBody{Code: 10000, Message: "invalid request"})
|
||||
return
|
||||
}
|
||||
out, err := h.Svc.Decode(c.Request.Context(), DecodeInput(req))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, apiBody{Code: 30001, Message: err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, apiBody{Code: 0, Message: "success", Data: out})
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
//go:build ignore
|
||||
|
||||
// EXAMPLE — reference shape for AI. Not compiled into apps/api.
|
||||
package examples
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type DecodeRepo interface {
|
||||
SaveDecode(ctx context.Context, userID string, summary string) error
|
||||
}
|
||||
|
||||
type DecodeServiceImpl struct {
|
||||
Repo DecodeRepo
|
||||
}
|
||||
|
||||
func (s *DecodeServiceImpl) Decode(ctx context.Context, in DecodeInput) (*DecodeOutput, error) {
|
||||
if in.Year < 1900 || in.Month < 1 || in.Month > 12 || in.Day < 1 || in.Day > 31 {
|
||||
return nil, fmt.Errorf("invalid birth date")
|
||||
}
|
||||
// engine would run here
|
||||
summary := "简版结论占位"
|
||||
if err := s.Repo.SaveDecode(ctx, "user-from-ctx", summary); err != nil {
|
||||
return nil, fmt.Errorf("save decode: %w", err)
|
||||
}
|
||||
return &DecodeOutput{Summary: summary}, nil
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
//go:build ignore
|
||||
|
||||
// EXAMPLE — table-driven unit test shape.
|
||||
package examples
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestClampBirthMonth(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
month int
|
||||
wantErr bool
|
||||
}{
|
||||
{name: "ok", month: 6, wantErr: false},
|
||||
{name: "zero", month: 0, wantErr: true},
|
||||
{name: "thirteen", month: 13, wantErr: true},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err := validateMonth(tt.month)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Fatalf("validateMonth(%d) err=%v wantErr=%v", tt.month, err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func validateMonth(m int) error {
|
||||
if m < 1 || m > 12 {
|
||||
return errInvalid
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var errInvalid = errString("invalid")
|
||||
|
||||
type errString string
|
||||
|
||||
func (e errString) Error() string { return string(e) }
|
||||
Reference in New Issue
Block a user