This commit is contained in:
2025-09-09 11:13:36 +08:00
parent cf50a9f1fa
commit fcd35c78e5
60 changed files with 2753 additions and 2196 deletions
@@ -1,19 +1,26 @@
package com.emotion.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.emotion.common.PageResult;
import com.emotion.common.Result;
import com.emotion.dto.request.PageRequest;
import com.emotion.entity.GrowthTopic;
import com.emotion.dto.request.growth.GrowthTopicCreateRequest;
import com.emotion.dto.request.growth.GrowthTopicPageRequest;
import com.emotion.dto.request.growth.GrowthTopicUpdateRequest;
import com.emotion.dto.response.growth.GrowthTopicResponse;
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;
import javax.validation.Valid;
/**
* 成长话题控制器
*
* @author emotion-museum
* @date 2025-09-08
*/
@RestController
@RequestMapping("/growth-topic")
@RequestMapping("/growthTopic")
public class GrowthTopicController {
@Autowired
@@ -22,49 +29,54 @@ public class GrowthTopicController {
/**
* 分页查询成长话题
*/
@GetMapping("/page")
public Result<IPage<GrowthTopic>> getPage(@Validated PageRequest request) {
IPage<GrowthTopic> page = growthTopicService.getPage(request);
return Result.success(page);
@GetMapping(value = "/page")
public Result<PageResult<GrowthTopicResponse>> getPage(@Validated GrowthTopicPageRequest request) {
PageResult<GrowthTopicResponse> pageResult = growthTopicService.getPageWithResponse(request);
return Result.success(pageResult);
}
/**
* 根据ID获取成长话题
*/
@GetMapping(value = "/detail")
public Result<GrowthTopicResponse> getById(@RequestParam String id) {
GrowthTopicResponse response = growthTopicService.getGrowthTopicResponseById(id);
if (response == null) {
return Result.notFound("成长话题不存在");
}
return Result.success(response);
}
/**
* 创建成长话题
*/
@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);
@PostMapping(value = "/create")
public Result<GrowthTopicResponse> create(@Valid @RequestBody GrowthTopicCreateRequest request) {
GrowthTopicResponse response = growthTopicService.createGrowthTopicWithResponse(request);
return Result.success(response);
}
// 可根据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; }
/**
* 更新成长话题
*/
@PutMapping(value = "/update")
public Result<GrowthTopicResponse> update(@Valid @RequestBody GrowthTopicUpdateRequest request) {
GrowthTopicResponse response = growthTopicService.updateGrowthTopicWithResponse(request);
if (response == null) {
return Result.notFound("成长话题不存在");
}
return Result.success(response);
}
}
/**
* 删除成长话题
*/
@DeleteMapping(value = "/delete")
public Result<Void> delete(@RequestParam String id) {
boolean deleted = growthTopicService.deleteGrowthTopic(id);
if (!deleted) {
return Result.error("删除失败");
}
return Result.success();
}
}