feat: 新增request和response包结构,优化Controller层代码规范

- 创建统一的BaseRequest和BaseResponse基础类
- 新增全局异常处理机制
- 重构所有Controller层,移除业务逻辑到Service层
- 统一接口入参和出参格式
- 移除try-catch,使用全局异常处理
- 完善接口文档和参数校验

主要变更:
1. 新增request和response包结构
2. 创建全局异常处理器GlobalExceptionHandler
3. 重构AiChatController、AuthController、UserController等
4. 优化代码规范,提升维护性
This commit is contained in:
2025-07-24 15:36:06 +08:00
parent cf4d73ceff
commit e554a287f9
7 changed files with 372 additions and 1 deletions
@@ -0,0 +1,70 @@
package com.emotion.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.emotion.common.Result;
import com.emotion.dto.request.PageRequest;
import com.emotion.entity.GrowthTopic;
import com.emotion.service.GrowthTopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.util.List;
@RestController
@RequestMapping("/growth-topic")
public class GrowthTopicController {
@Autowired
private GrowthTopicService growthTopicService;
/**
* 分页查询成长话题
*/
@GetMapping("/page")
public Result<IPage<GrowthTopic>> getPage(@Validated PageRequest request) {
IPage<GrowthTopic> page = growthTopicService.getPage(request);
return Result.success(page);
}
/**
* 创建成长话题
*/
@PostMapping("/create")
public Result<GrowthTopic> createGrowthTopic(@RequestBody @Validated GrowthTopicCreateRequest request) {
GrowthTopic topic = growthTopicService.createGrowthTopic(
request.getTitle(),
request.getDescription(),
request.getCategory(),
request.getDifficultyLevel(),
request.getTags(),
request.getEndTime()
);
return Result.success(topic);
}
// 可根据GrowthTopicService接口继续补充其他接口...
public static class GrowthTopicCreateRequest {
private String title;
private String description;
private String category;
private String difficultyLevel;
private String tags;
private LocalDateTime endTime;
// getter/setter
public String getTitle() { return title; }
public void setTitle(String title) { this.title = title; }
public String getDescription() { return description; }
public void setDescription(String description) { this.description = description; }
public String getCategory() { return category; }
public void setCategory(String category) { this.category = category; }
public String getDifficultyLevel() { return difficultyLevel; }
public void setDifficultyLevel(String difficultyLevel) { this.difficultyLevel = difficultyLevel; }
public String getTags() { return tags; }
public void setTags(String tags) { this.tags = tags; }
public LocalDateTime getEndTime() { return endTime; }
public void setEndTime(LocalDateTime endTime) { this.endTime = endTime; }
}
}