docs: 批量更新历史文档中的 backend-single 引用为 server
This commit is contained in:
@@ -20,13 +20,13 @@ purpose: 微信小程序登录修复 spec 的实施计划(TDD + 频繁 commit
|
||||
|
||||
| 状态 | 文件 | 责任 | 行数 |
|
||||
|---|---|---|---|
|
||||
| 重写 | `backend-single/src/main/java/com/emotion/config/RestTemplateConfig.java` | 统一 RestTemplate Bean(User-Agent + 超时 + 拦截器 + 错误处理) | 13 → 40 |
|
||||
| 新增 | `backend-single/src/main/java/com/emotion/interceptor/WechatApiLoggingInterceptor.java` | 请求/响应日志(INFO)+ 脱敏 body(DEBUG) | 60 |
|
||||
| 新增 | `backend-single/src/main/java/com/emotion/config/WechatResponseErrorHandler.java` | 4xx/5xx 不抛异常 | 30 |
|
||||
| 新增 | `backend-single/src/main/java/com/emotion/exception/WechatApiException.java` | 业务异常类(HTTP 风格 code + rawBody) | 30 |
|
||||
| 重写 | `backend-single/src/main/java/com/emotion/service/impl/WechatMiniProgramServiceImpl.java` | `code2Session` 五步防御 | 49 → 90 |
|
||||
| 修改 | `backend-single/src/main/java/com/emotion/exception/GlobalExceptionHandler.java` | 新增 `handleWechatApiException` + 脱敏日志 | +25 |
|
||||
| 修改 | `backend-single/src/main/resources/application.yml` | 移除 `app-id` / `app-secret` 硬编码默认值 | 2 行 |
|
||||
| 重写 | `server/src/main/java/com/emotion/config/RestTemplateConfig.java` | 统一 RestTemplate Bean(User-Agent + 超时 + 拦截器 + 错误处理) | 13 → 40 |
|
||||
| 新增 | `server/src/main/java/com/emotion/interceptor/WechatApiLoggingInterceptor.java` | 请求/响应日志(INFO)+ 脱敏 body(DEBUG) | 60 |
|
||||
| 新增 | `server/src/main/java/com/emotion/config/WechatResponseErrorHandler.java` | 4xx/5xx 不抛异常 | 30 |
|
||||
| 新增 | `server/src/main/java/com/emotion/exception/WechatApiException.java` | 业务异常类(HTTP 风格 code + rawBody) | 30 |
|
||||
| 重写 | `server/src/main/java/com/emotion/service/impl/WechatMiniProgramServiceImpl.java` | `code2Session` 五步防御 | 49 → 90 |
|
||||
| 修改 | `server/src/main/java/com/emotion/exception/GlobalExceptionHandler.java` | 新增 `handleWechatApiException` + 脱敏日志 | +25 |
|
||||
| 修改 | `server/src/main/resources/application.yml` | 移除 `app-id` / `app-secret` 硬编码默认值 | 2 行 |
|
||||
|
||||
**总计**:2 重写 + 3 新增 + 2 修改,约 280 行 Java + 2 行 YAML
|
||||
|
||||
@@ -38,9 +38,9 @@ purpose: 微信小程序登录修复 spec 的实施计划(TDD + 频繁 commit
|
||||
cd "G:\IdeaProjects\emotion-museun"
|
||||
git status # 确认在 master 分支
|
||||
git log --oneline -1 # 确认最新 commit 是 82c308b
|
||||
ls backend-single/src/main/java/com/emotion/exception/ # 确认 GlobalExceptionHandler.java 存在
|
||||
ls backend-single/src/main/java/com/emotion/config/ # 确认 RestTemplateConfig.java 存在
|
||||
ls backend-single/src/main/java/com/emotion/service/impl/ # 确认 WechatMiniProgramServiceImpl.java 存在
|
||||
ls server/src/main/java/com/emotion/exception/ # 确认 GlobalExceptionHandler.java 存在
|
||||
ls server/src/main/java/com/emotion/config/ # 确认 RestTemplateConfig.java 存在
|
||||
ls server/src/main/java/com/emotion/service/impl/ # 确认 WechatMiniProgramServiceImpl.java 存在
|
||||
```
|
||||
|
||||
期望:全部存在,工作树只有 spec 文件修改(无业务代码污染)
|
||||
@@ -50,7 +50,7 @@ ls backend-single/src/main/java/com/emotion/service/impl/ # 确认 WechatMiniPr
|
||||
## Task 1: 创建 WechatApiException 异常类
|
||||
|
||||
**Files:**
|
||||
- Create: `backend-single/src/main/java/com/emotion/exception/WechatApiException.java`
|
||||
- Create: `server/src/main/java/com/emotion/exception/WechatApiException.java`
|
||||
|
||||
- [ ] **Step 1.1: 写入 WechatApiException.java**
|
||||
|
||||
@@ -95,7 +95,7 @@ public class WechatApiException extends RuntimeException {
|
||||
- [ ] **Step 1.2: mvn 编译验证**
|
||||
|
||||
```bash
|
||||
cd "G:\IdeaProjects\emotion-museun\backend-single"
|
||||
cd "G:\IdeaProjects\emotion-museun\server"
|
||||
mvn clean compile -DskipTests
|
||||
```
|
||||
|
||||
@@ -105,7 +105,7 @@ mvn clean compile -DskipTests
|
||||
|
||||
```bash
|
||||
cd "G:\IdeaProjects\emotion-museun"
|
||||
git add backend-single/src/main/java/com/emotion/exception/WechatApiException.java
|
||||
git add server/src/main/java/com/emotion/exception/WechatApiException.java
|
||||
git commit -m "feat(wechat): 新增 WechatApiException 业务异常类
|
||||
|
||||
- 继承 RuntimeException
|
||||
@@ -119,12 +119,12 @@ git commit -m "feat(wechat): 新增 WechatApiException 业务异常类
|
||||
## Task 2: 创建 WechatApiLoggingInterceptor(含脱敏单元测试)
|
||||
|
||||
**Files:**
|
||||
- Create: `backend-single/src/main/java/com/emotion/interceptor/WechatApiLoggingInterceptor.java`
|
||||
- Create: `backend-single/src/test/java/com/emotion/interceptor/WechatApiLoggingInterceptorTest.java`
|
||||
- Create: `server/src/main/java/com/emotion/interceptor/WechatApiLoggingInterceptor.java`
|
||||
- Create: `server/src/test/java/com/emotion/interceptor/WechatApiLoggingInterceptorTest.java`
|
||||
|
||||
- [ ] **Step 2.1: 写失败测试(验证脱敏逻辑)**
|
||||
|
||||
创建 `backend-single/src/test/java/com/emotion/interceptor/WechatApiLoggingInterceptorTest.java`:
|
||||
创建 `server/src/test/java/com/emotion/interceptor/WechatApiLoggingInterceptorTest.java`:
|
||||
|
||||
```java
|
||||
package com.emotion.interceptor;
|
||||
@@ -197,7 +197,7 @@ class WechatApiLoggingInterceptorTest {
|
||||
- [ ] **Step 2.2: 运行测试验证失败**
|
||||
|
||||
```bash
|
||||
cd "G:\IdeaProjects\emotion-museun\backend-single"
|
||||
cd "G:\IdeaProjects\emotion-museun\server"
|
||||
mvn test -Dtest=WechatApiLoggingInterceptorTest
|
||||
```
|
||||
|
||||
@@ -205,7 +205,7 @@ mvn test -Dtest=WechatApiLoggingInterceptorTest
|
||||
|
||||
- [ ] **Step 2.3: 写最小实现让测试通过**
|
||||
|
||||
创建 `backend-single/src/main/java/com/emotion/interceptor/WechatApiLoggingInterceptor.java`:
|
||||
创建 `server/src/main/java/com/emotion/interceptor/WechatApiLoggingInterceptor.java`:
|
||||
|
||||
```java
|
||||
package com.emotion.interceptor;
|
||||
@@ -282,7 +282,7 @@ public class WechatApiLoggingInterceptor implements ClientHttpRequestInterceptor
|
||||
- [ ] **Step 2.4: 运行测试验证通过**
|
||||
|
||||
```bash
|
||||
cd "G:\IdeaProjects\emotion-museun\backend-single"
|
||||
cd "G:\IdeaProjects\emotion-museun\server"
|
||||
mvn test -Dtest=WechatApiLoggingInterceptorTest
|
||||
```
|
||||
|
||||
@@ -292,8 +292,8 @@ mvn test -Dtest=WechatApiLoggingInterceptorTest
|
||||
|
||||
```bash
|
||||
cd "G:\IdeaProjects\emotion-museun"
|
||||
git add backend-single/src/main/java/com/emotion/interceptor/WechatApiLoggingInterceptor.java
|
||||
git add backend-single/src/test/java/com/emotion/interceptor/WechatApiLoggingInterceptorTest.java
|
||||
git add server/src/main/java/com/emotion/interceptor/WechatApiLoggingInterceptor.java
|
||||
git add server/src/test/java/com/emotion/interceptor/WechatApiLoggingInterceptorTest.java
|
||||
git commit -m "feat(wechat): 新增 WechatApiLoggingInterceptor 拦截器(含脱敏单元测试)
|
||||
|
||||
- ClientHttpRequestInterceptor 实现
|
||||
@@ -309,7 +309,7 @@ git commit -m "feat(wechat): 新增 WechatApiLoggingInterceptor 拦截器(含
|
||||
## Task 3: 创建 WechatResponseErrorHandler
|
||||
|
||||
**Files:**
|
||||
- Create: `backend-single/src/main/java/com/emotion/config/WechatResponseErrorHandler.java`
|
||||
- Create: `server/src/main/java/com/emotion/config/WechatResponseErrorHandler.java`
|
||||
|
||||
- [ ] **Step 3.1: 写入 WechatResponseErrorHandler.java**
|
||||
|
||||
@@ -354,7 +354,7 @@ public class WechatResponseErrorHandler extends DefaultResponseErrorHandler {
|
||||
- [ ] **Step 3.2: mvn 编译验证**
|
||||
|
||||
```bash
|
||||
cd "G:\IdeaProjects\emotion-museun\backend-single"
|
||||
cd "G:\IdeaProjects\emotion-museun\server"
|
||||
mvn clean compile -DskipTests
|
||||
```
|
||||
|
||||
@@ -364,7 +364,7 @@ mvn clean compile -DskipTests
|
||||
|
||||
```bash
|
||||
cd "G:\IdeaProjects\emotion-museun"
|
||||
git add backend-single/src/main/java/com/emotion/config/WechatResponseErrorHandler.java
|
||||
git add server/src/main/java/com/emotion/config/WechatResponseErrorHandler.java
|
||||
git commit -m "feat(wechat): 新增 WechatResponseErrorHandler
|
||||
|
||||
- 继承 DefaultResponseErrorHandler
|
||||
@@ -378,12 +378,12 @@ git commit -m "feat(wechat): 新增 WechatResponseErrorHandler
|
||||
## Task 4: 重写 RestTemplateConfig 集成新组件
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend-single/src/main/java/com/emotion/config/RestTemplateConfig.java`
|
||||
- Modify: `server/src/main/java/com/emotion/config/RestTemplateConfig.java`
|
||||
|
||||
- [ ] **Step 4.1: 备份并读取原文件**
|
||||
|
||||
```bash
|
||||
cd "G:\IdeaProjects\emotion-museun\backend-single\src\main\java\com\emotion\config"
|
||||
cd "G:\IdeaProjects\emotion-museun\server\src\main\java\com\emotion\config"
|
||||
copy RestTemplateConfig.java RestTemplateConfig.java.bak
|
||||
```
|
||||
|
||||
@@ -467,8 +467,8 @@ public class RestTemplateConfig {
|
||||
- [ ] **Step 4.3: mvn 编译验证(确保 7 个其他使用点不受影响)**
|
||||
|
||||
```bash
|
||||
cd "G:\IdeaProjects\emotion-museun\backend-single"
|
||||
mvn clean install -pl :backend-single -am -DskipTests
|
||||
cd "G:\IdeaProjects\emotion-museun\server"
|
||||
mvn clean install -pl :server -am -DskipTests
|
||||
```
|
||||
|
||||
期望:`BUILD SUCCESS`,无编译错误(如果 7 个其他使用点有编译错误,说明 RestTemplate API 不兼容,需要回滚)
|
||||
@@ -476,7 +476,7 @@ mvn clean install -pl :backend-single -am -DskipTests
|
||||
- [ ] **Step 4.4: 删除备份文件**
|
||||
|
||||
```bash
|
||||
cd "G:\IdeaProjects\emotion-museun\backend-single\src\main\java\com\emotion\config"
|
||||
cd "G:\IdeaProjects\emotion-museun\server\src\main\java\com\emotion\config"
|
||||
del RestTemplateConfig.java.bak
|
||||
```
|
||||
|
||||
@@ -484,7 +484,7 @@ del RestTemplateConfig.java.bak
|
||||
|
||||
```bash
|
||||
cd "G:\IdeaProjects\emotion-museun"
|
||||
git add backend-single/src/main/java/com/emotion/config/RestTemplateConfig.java
|
||||
git add server/src/main/java/com/emotion/config/RestTemplateConfig.java
|
||||
git commit -m "feat(wechat): 重写 RestTemplateConfig 统一 RestTemplate Bean
|
||||
|
||||
解决问题:
|
||||
@@ -514,8 +514,8 @@ git commit -m "feat(wechat): 重写 RestTemplateConfig 统一 RestTemplate Bean
|
||||
## Task 5: 重写 WechatMiniProgramServiceImpl.code2Session(TDD 10 个场景)
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend-single/src/main/java/com/emotion/service/impl/WechatMiniProgramServiceImpl.java`
|
||||
- Create: `backend-single/src/test/java/com/emotion/service/impl/WechatMiniProgramServiceImplTest.java`
|
||||
- Modify: `server/src/main/java/com/emotion/service/impl/WechatMiniProgramServiceImpl.java`
|
||||
- Create: `server/src/test/java/com/emotion/service/impl/WechatMiniProgramServiceImplTest.java`
|
||||
|
||||
- [ ] **Step 5.1: 读取当前 WechatMiniProgramServiceImpl.java**
|
||||
|
||||
@@ -523,7 +523,7 @@ git commit -m "feat(wechat): 重写 RestTemplateConfig 统一 RestTemplate Bean
|
||||
|
||||
- [ ] **Step 5.2: 写失败测试(覆盖 spec 10 个场景)**
|
||||
|
||||
创建 `backend-single/src/test/java/com/emotion/service/impl/WechatMiniProgramServiceImplTest.java`:
|
||||
创建 `server/src/test/java/com/emotion/service/impl/WechatMiniProgramServiceImplTest.java`:
|
||||
|
||||
```java
|
||||
package com.emotion.service.impl;
|
||||
@@ -659,7 +659,7 @@ class WechatMiniProgramServiceImplTest {
|
||||
- [ ] **Step 5.3: 运行测试验证失败(确认 service 现有方法未做防御)**
|
||||
|
||||
```bash
|
||||
cd "G:\IdeaProjects\emotion-museun\backend-single"
|
||||
cd "G:\IdeaProjects\emotion-museun\server"
|
||||
mvn test -Dtest=WechatMiniProgramServiceImplTest
|
||||
```
|
||||
|
||||
@@ -667,7 +667,7 @@ mvn test -Dtest=WechatMiniProgramServiceImplTest
|
||||
|
||||
- [ ] **Step 5.4: 重写 code2Session 方法(五步防御)**
|
||||
|
||||
修改 `backend-single/src/main/java/com/emotion/service/impl/WechatMiniProgramServiceImpl.java`:
|
||||
修改 `server/src/main/java/com/emotion/service/impl/WechatMiniProgramServiceImpl.java`:
|
||||
|
||||
在 class 顶部添加 imports:
|
||||
```java
|
||||
@@ -748,7 +748,7 @@ public WechatCodeSessionResponse code2Session(String code) {
|
||||
- [ ] **Step 5.5: 运行测试验证通过**
|
||||
|
||||
```bash
|
||||
cd "G:\IdeaProjects\emotion-museun\backend-single"
|
||||
cd "G:\IdeaProjects\emotion-museun\server"
|
||||
mvn test -Dtest=WechatMiniProgramServiceImplTest
|
||||
```
|
||||
|
||||
@@ -758,8 +758,8 @@ mvn test -Dtest=WechatMiniProgramServiceImplTest
|
||||
|
||||
```bash
|
||||
cd "G:\IdeaProjects\emotion-museun"
|
||||
git add backend-single/src/main/java/com/emotion/service/impl/WechatMiniProgramServiceImpl.java
|
||||
git add backend-single/src/test/java/com/emotion/service/impl/WechatMiniProgramServiceImplTest.java
|
||||
git add server/src/main/java/com/emotion/service/impl/WechatMiniProgramServiceImpl.java
|
||||
git add server/src/test/java/com/emotion/service/impl/WechatMiniProgramServiceImplTest.java
|
||||
git commit -m "feat(wechat): 重写 code2Session 五步防御
|
||||
|
||||
解决问题:
|
||||
@@ -783,7 +783,7 @@ git commit -m "feat(wechat): 重写 code2Session 五步防御
|
||||
## Task 6: 修改 application.yml 移除硬编码
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend-single/src/main/resources/application.yml`
|
||||
- Modify: `server/src/main/resources/application.yml`
|
||||
|
||||
- [ ] **Step 6.1: 定位并修改微信配置**
|
||||
|
||||
@@ -820,7 +820,7 @@ $env:WECHAT_MINI_PROGRAM_APP_SECRET = "4f087bd363a4147ef543d634f9f6950d"
|
||||
- [ ] **Step 6.3: mvn 编译验证(确保 YAML 可加载)**
|
||||
|
||||
```bash
|
||||
cd "G:\IdeaProjects\emotion-museun\backend-single"
|
||||
cd "G:\IdeaProjects\emotion-museun\server"
|
||||
mvn clean compile -DskipTests
|
||||
```
|
||||
|
||||
@@ -830,7 +830,7 @@ mvn clean compile -DskipTests
|
||||
|
||||
```bash
|
||||
cd "G:\IdeaProjects\emotion-museun"
|
||||
git add backend-single/src/main/resources/application.yml
|
||||
git add server/src/main/resources/application.yml
|
||||
git commit -m "fix(wechat): 移除 app-id/app-secret 硬编码默认值
|
||||
|
||||
安全问题:
|
||||
@@ -854,7 +854,7 @@ git commit -m "fix(wechat): 移除 app-id/app-secret 硬编码默认值
|
||||
## Task 7: 修改 GlobalExceptionHandler 添加 WechatApiException handler
|
||||
|
||||
**Files:**
|
||||
- Modify: `backend-single/src/main/java/com/emotion/exception/GlobalExceptionHandler.java`
|
||||
- Modify: `server/src/main/java/com/emotion/exception/GlobalExceptionHandler.java`
|
||||
|
||||
- [ ] **Step 7.1: 定位文件并添加新方法**
|
||||
|
||||
@@ -911,7 +911,7 @@ public Result<Void> handleWechatApiException(WechatApiException e, HttpServletRe
|
||||
- [ ] **Step 7.2: mvn 编译验证**
|
||||
|
||||
```bash
|
||||
cd "G:\IdeaProjects\emotion-museun\backend-single"
|
||||
cd "G:\IdeaProjects\emotion-museun\server"
|
||||
mvn clean compile -DskipTests
|
||||
```
|
||||
|
||||
@@ -919,7 +919,7 @@ mvn clean compile -DskipTests
|
||||
|
||||
- [ ] **Step 7.3: 写简单测试验证 handler 行为**
|
||||
|
||||
创建 `backend-single/src/test/java/com/emotion/exception/GlobalExceptionHandlerWechatTest.java`:
|
||||
创建 `server/src/test/java/com/emotion/exception/GlobalExceptionHandlerWechatTest.java`:
|
||||
|
||||
```java
|
||||
package com.emotion.exception;
|
||||
@@ -976,7 +976,7 @@ class GlobalExceptionHandlerWechatTest {
|
||||
- [ ] **Step 7.4: 运行测试**
|
||||
|
||||
```bash
|
||||
cd "G:\IdeaProjects\emotion-museun\backend-single"
|
||||
cd "G:\IdeaProjects\emotion-museun\server"
|
||||
mvn test -Dtest=GlobalExceptionHandlerWechatTest
|
||||
```
|
||||
|
||||
@@ -986,8 +986,8 @@ mvn test -Dtest=GlobalExceptionHandlerWechatTest
|
||||
|
||||
```bash
|
||||
cd "G:\IdeaProjects\emotion-museun"
|
||||
git add backend-single/src/main/java/com/emotion/exception/GlobalExceptionHandler.java
|
||||
git add backend-single/src/test/java/com/emotion/exception/GlobalExceptionHandlerWechatTest.java
|
||||
git add server/src/main/java/com/emotion/exception/GlobalExceptionHandler.java
|
||||
git add server/src/test/java/com/emotion/exception/GlobalExceptionHandlerWechatTest.java
|
||||
git commit -m "feat(wechat): GlobalExceptionHandler 新增 WechatApiException handler
|
||||
|
||||
解决问题:
|
||||
@@ -1014,7 +1014,7 @@ git commit -m "feat(wechat): GlobalExceptionHandler 新增 WechatApiException ha
|
||||
|
||||
```bash
|
||||
cd "G:\IdeaProjects\emotion-museun"
|
||||
mvn clean install -pl :backend-single -am -DskipTests
|
||||
mvn clean install -pl :server -am -DskipTests
|
||||
```
|
||||
|
||||
期望:`BUILD SUCCESS`
|
||||
@@ -1023,7 +1023,7 @@ mvn clean install -pl :backend-single -am -DskipTests
|
||||
|
||||
```bash
|
||||
cd "G:\IdeaProjects\emotion-museun"
|
||||
mvn test -pl :backend-single
|
||||
mvn test -pl :server
|
||||
```
|
||||
|
||||
期望:所有测试通过,无失败
|
||||
|
||||
Reference in New Issue
Block a user