添加分类的controller

This commit is contained in:
2025-09-14 22:21:03 +08:00
parent d14b46d007
commit 7f24d65d76
94 changed files with 146 additions and 137 deletions

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

0
src/main/java/com/qingqiu/interview/common/res/R.java Normal file → Executable file
View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

@@ -1,15 +1,159 @@
package com.qingqiu.interview.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qingqiu.interview.common.res.R;
import com.qingqiu.interview.dto.QuestionCategoryDTO;
import com.qingqiu.interview.dto.QuestionCategoryPageParams;
import com.qingqiu.interview.entity.QuestionCategory;
import com.qingqiu.interview.service.IQuestionCategoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/api/v1/question-category")
@RequiredArgsConstructor
public class QuestionCategoryController {
private final IQuestionCategoryService questionCategoryService;
/**
* 获取分类树列表
*/
@GetMapping("/tree-list")
public R<List<QuestionCategory>> getTreeList() {
try {
List<QuestionCategory> list = questionCategoryService.getTreeList();
return R.success(list);
} catch (Exception e) {
log.error("获取分类树列表失败", e);
return R.error("获取分类树列表失败");
}
}
/**
* 获取分类选项
*/
@GetMapping("/options")
public R<List<QuestionCategory>> getOptions() {
try {
List<QuestionCategory> options = questionCategoryService.getOptions();
return R.success(options);
} catch (Exception e) {
log.error("获取分类选项失败", e);
return R.error("获取分类选项失败");
}
}
/**
* 获取分类详情
*/
@GetMapping("/{id}")
public R<QuestionCategory> getDetail(@PathVariable Long id) {
try {
QuestionCategory category = questionCategoryService.getCategoryDetail(id);
return R.success(category);
} catch (Exception e) {
log.error("获取分类详情失败", e);
return R.error("获取分类详情失败");
}
}
/**
* 分页查询分类
*/
@GetMapping("/page")
public R<Page<QuestionCategory>> getPage(QuestionCategoryPageParams query) {
try {
Page<QuestionCategory> pageR = questionCategoryService.getCategoryPage(query);
return R.success(pageR);
} catch (Exception e) {
log.error("分页查询分类失败", e);
return R.error("分页查询分类失败");
}
}
/**
* 创建分类
*/
@PostMapping
public R<Long> create(@Validated @RequestBody QuestionCategoryDTO dto) {
try {
Long id = questionCategoryService.createCategory(dto);
return R.success(id);
} catch (RuntimeException e) {
log.error("创建分类失败", e);
return R.error(e.getMessage());
} catch (Exception e) {
log.error("创建分类失败", e);
return R.error("创建分类失败");
}
}
/**
* 更新分类
*/
@PutMapping("/{id}")
public R<Void> update(@PathVariable Long id, @Validated @RequestBody QuestionCategoryDTO dto) {
try {
questionCategoryService.updateCategory(id, dto);
return R.success();
} catch (RuntimeException e) {
log.error("更新分类失败", e);
return R.error(e.getMessage());
} catch (Exception e) {
log.error("更新分类失败", e);
return R.error("更新分类失败");
}
}
/**
* 删除分类
*/
@DeleteMapping("/{id}")
public R<Void> delete(@PathVariable Long id) {
try {
questionCategoryService.deleteCategory(id);
return R.success();
} catch (RuntimeException e) {
log.error("删除分类失败", e);
return R.error(e.getMessage());
} catch (Exception e) {
log.error("删除分类失败", e);
return R.error("删除分类失败");
}
}
/**
* 更新分类状态
*/
@PatchMapping("/{id}/state")
public R<Void> updateState(@PathVariable Long id, @RequestParam Integer state) {
try {
questionCategoryService.updateState(id, state);
return R.success();
} catch (Exception e) {
log.error("更新分类状态失败", e);
return R.error("更新分类状态失败");
}
}
/**
* 搜索分类
*/
@GetMapping("/search")
public R<List<QuestionCategory>> search(@RequestParam String name) {
try {
List<QuestionCategory> res = questionCategoryService.searchByName(name);
return R.success(res);
} catch (Exception e) {
log.error("搜索分类失败", e);
return R.error("搜索分类失败");
}
}
}

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

0
src/main/resources/application.yml Normal file → Executable file
View File

0
src/main/resources/mapper/AIClientService.xml Normal file → Executable file
View File

0
src/main/resources/mapper/AiSessionLogMapper.xml Normal file → Executable file
View File

View File

0
src/main/resources/mapper/InterviewMessageMapper.xml Normal file → Executable file
View File

View File

0
src/main/resources/mapper/QuestionCategoryMapper.xml Normal file → Executable file
View File

0
src/main/resources/mapper/QuestionMapper.xml Normal file → Executable file
View File

0
src/main/resources/sql/schema.sql Normal file → Executable file
View File

View File