WorkBuddy 7682abd85c fix(api): give failures real HTTP semantics; fix 401/403 confusion and CORS default
Phase 23B ended with an E2E assertion changed to expect "HTTP 200 + body.code
== BAD_REQUEST", documented at the time as "this project's convention". That
description was accurate about the code and wrong about the intent: it described
a defect, and I made the test accommodate it instead of fixing it.

Auditing it found the convention was already broken, not merely risky:

- ~100 sites (105, across 30 controllers) do `return ApiResponse.error(...)` /
  `forbidden()` / `notFound()` with no exception and no `@ResponseStatus`, so
  the HTTP status is always 200. Gateways and APM cannot separate 4xx from 5xx;
  callers cannot tell "fix your request" (400) from "don't retry" (403) from
  "check state first" (409) from "retry later" (429).
- miniapp/utils/api.js already had 401/403/429 branches that could never be
  reached, since the backend never returned those codes. The concrete damage:
  an expired token returned 403, so `onSessionExpired` never fired and users
  were stuck with no way back to the login flow.
- SecurityConfig had no `authenticationEntryPoint`, so Spring's default
  `Http403ForbiddenEntryPoint` returned 403 for unauthenticated calls, with a
  framework body that has no `code` field at all.
- CorsConfig defaulted `allowed-origins` to `*` together with
  `allowCredentials(true)`, while its comment claimed "localhost only by
  default". Comment contradicting code is worse than no comment: it reads as
  safe.
- Only 4 files / 15 assertions in the whole backend suite touched HTTP status,
  which is how this survived.

Approach: one definition, two applications, zero controller changes.
- ApiResponseCode gains an `httpStatus` field — the single source of truth. The
  constructor requires it, so a new code cannot be added without one.
- GlobalExceptionHandler reads status from the enum instead of hardcoding
  `@ResponseStatus` per handler.
- New ApiResponseStatusAdvice (ResponseBodyAdvice) fills in the status just
  before the body is written, covering all ~100 direct-return sites without
  touching them. Two constraints, both noted in code: only downgrade when the
  current status is still 2xx (the advice also sees exception-handler results,
  and must not override an already-correct 401/403/409), and never alter the
  body.
- SecurityConfig: entry point returns 401 with a uniform ApiResponse body;
  access denied handler returns 403 likewise.
- CorsConfig: default changed to empty (deny). Both clients are same-origin
  anyway — nginx proxies /api/ and Vite proxies /api — so nothing depends on it.
- miniapp api.js: 401/403/429/409 branches now prefer the server's
  `body.message`, otherwise "账号已被封禁" would be flattened to "无权限访问".

Implementation trap worth remembering: `ServerHttpResponse` has `setStatusCode`
but no getter, so reading the current status requires casting to
`ServletServerHttpResponse`.

Verification: 37 E2E passed (33 + 4 new contract cases), including a live-stack
check that a controller's direct `notFound()` now yields 404 — that path throws
no exception and never reaches the exception handler, so if the advice were
inactive it would silently return 200 while the enum unit tests stayed green.
Backend regression 662 / 0 failures / 0 errors / 3 skipped (+6 new guards).

The first regression run had 3 failures, all tests asserting the old wrong
behavior (anonymous access expected 403; outsiders reading a conversation
expected 200). Fixed the assertions, not the implementation. Where 404 is used
instead of 403 for "invisible", that is deliberate — it prevents probing whether
another user's conversation exists — and the substantive assertions (e.g. that an
unauthorized response must not leak message bodies) were kept.

Not done, needs a product decision: third-party credential issuance, whether
rate limiting is actually active, publishing OpenAPI externally, per-caller
audit and quotas, pagination/idempotency coverage, desensitization boundaries.
2026-09-18 14:34:58 +08:00

善缘丹阳公益婚恋服务平台 V1.1 增量恢复中

面向丹阳市成年单身人士,由公益组织参与运营的实名制公益婚恋服务平台。

真实 · 公益 · 本地 · 安全 · 高效

当前基线: V1.0.0-RC.2 + V1.1 客户需求增量 · 状态:INCREMENTAL RECOVERY / NO-GO

当前代码包含 V1.1 部分实现,但尚未通过 Admin、Miniapp、权限和 E2E 发布门禁。请勿依据历史 Completion Report 或 Jira 勾选项判断已经上线。唯一执行计划见 docs/善缘丹阳 V1.1 客户需求基线增量开发与修复计划.md。


项目简介

本平台帮助丹阳本地单身人士通过实名认证、人工审核、智能匹配、双向喜欢、在线沟通、公益红娘和线下相亲活动,安全、高效、真实地寻找合适伴侣。

用户永久免费。


技术栈

组件 技术
后端 Java 21 + Spring Boot 3.x
数据库 PostgreSQL
缓存/Session Redis
对象存储 S3 兼容(MinIO / 国内云存储)
实时通信 WebSocket
数据库迁移 Flyway
小程序 微信原生 + TypeScript
管理后台 Vue 3 + TypeScript + Vite + Pinia + Element Plus
容器化 Docker + Docker Compose + Nginx
CI/CD GitHub Actions

项目结构

├── backend/          # Spring Boot 后端服务
├── miniapp/          # 微信小程序用户端
├── admin-web/        # 运营管理后台(Web)
├── infrastructure/   # Docker Compose 编排
├── scripts/          # 运维脚本
├── tests/            # 测试代码
│   ├── unit/
│   ├── integration/
│   ├── api/
│   ├── permission/
│   ├── concurrency/
│   ├── e2e/
│   └── invariants/   # 核心不变量测试(每次CI必跑)
├── docs/             # 项目文档
│   ├── product/
│   ├── architecture/
│   ├── api/
│   ├── database/
│   ├── security/
│   ├── testing/
│   ├── ops/
│   └── decisions/
├── AGENTS.md         # 项目最高执行规则摘要
├── CHANGELOG.md
└── README.md

快速开始(开发环境)

前置要求

  • Docker & Docker Compose
  • JDK 21
  • Node.js 18+
  • npm / pnpm

一键启动基础设施

# 进入基础设施目录
cd infrastructure

# 启动 PostgreSQL / Redis / MinIO
docker compose up -d

# 等待服务就绪(约30秒)
# 可运行:docker compose logs -f

启动后端

cd backend

# 复制环境变量
cp src/main/resources/application-dev.yml.example src/main/resources/application-dev.yml
# 编辑 application-dev.yml,设置数据库连接等

# 构建并启动
./mvnw spring-boot:run -Dspring-boot.run.profiles=dev

启动管理后台

cd admin-web

# 安装依赖
pnpm install

# 启动开发服务器
pnpm dev

启动小程序

使用微信开发者工具打开 miniapp/ 目录,配置 AppID 后即可预览。


环境变量

所有环境变量参见各模块的 .env.example 文件。

关键变量:

# 数据库
DB_HOST=localhost
DB_PORT=5432
DB_NAME=danyang_match
DB_USER=app_rw
DB_PASSWORD=<secret>

# Redis
REDIS_HOST=localhost
REDIS_PORT=6379

# 对象存储
MINIO_ENDPOINT=localhost:9000
MINIO_ACCESS_KEY=<secret>
MINIO_SECRET_KEY=<secret>
MINIO_BUCKET_PUBLIC=public
MINIO_BUCKET_PRIVATE=private

# 微信
WECHAT_APP_ID=<secret>
WECHAT_APP_SECRET=<secret>

Secret 不进 Git。


数据库迁移

cd backend
./mvnw flyway:migrate -Dflyway.url=jdbc:postgresql://localhost:5432/danyang_match

运行测试

Phase 01 一键基线检查

PowerShell:

.\scripts\verify-phase01.ps1

Bash:

./scripts/verify-phase01.sh

脚本依次检查 Git、Backend tests、Admin type-check/build、Miniapp TypeScript 和 V1.1 E2E。任一门禁失败时脚本返回非零退出码,并在结尾列出失败项。Windows 未安装 JDK/Maven 时,Backend 检查使用 Docker 中的 JDK 21 与仓库内 Maven 包;不会永久修改系统环境。

首次执行 Admin/Miniapp 检查前,在 admin-web 目录运行 npm ci。E2E 使用 python -m pytest,不要依赖全局 pytest 命令。

分项命令

# 后端单元测试
cd backend
./mvnw test

# 后端集成测试
./mvnw verify

# 管理后台构建检查
cd admin-web
pnpm build

# 小程序编译检查
cd miniapp
# 在微信开发者工具中查看编译结果

构建部署

# 构建后端镜像
docker build -t danyang-match-backend:latest ./backend

# 构建管理后台
cd admin-web && pnpm build

# 完整部署
cd infrastructure && docker compose up -d

核心业务闭环

微信登录 → 绑定手机 → 实名认证 → 填写资料 → 设置择偶 → 提交审核
    ↓
审核通过 → 系统推荐 → 用户Like → 双向Match → 安全聊天
    ↓
公益红娘辅助 / 参加线下活动 → 进一步了解 → 双方确认成功牵手

开发阶段

项目按 Phase 01~Phase 26 顺序推进。详见 docs/STATUS.md。


许可证

本项目为公益项目,服务于丹阳市单身人士婚恋匹配。

S
Description
善缘丹阳公益婚恋平台
Readme Unlicense
29 MiB
Languages
Java 53.1%
Vue 14.9%
JavaScript 12.5%
HTML 9.6%
TypeScript 3.8%
Other 6.1%