feat(分类属性): 实现分类属性管理功能
新增分类属性相关实体、DTO、仓库、服务及控制器 扩展文章服务以支持按属性查询文章 重构文章实体将typeid改为attributeid 添加按标题查询文章功能
This commit is contained in:
@@ -42,6 +42,15 @@ public class ArticleController {
|
||||
public ResponseMessage<List<Article>> getAllArticles() {
|
||||
return articleService.getAllArticles();
|
||||
}
|
||||
/**
|
||||
* 根据标题查询文章列表
|
||||
* @param title 文章标题
|
||||
* @return 返回包含文章列表的ResponseMessage对象
|
||||
*/
|
||||
@GetMapping("/title/{title}")
|
||||
public ResponseMessage<List<Article>> getArticlesByTitle(@PathVariable String title) {
|
||||
return articleService.getArticlesByTitle(title);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新文章
|
||||
@@ -84,13 +93,33 @@ public class ArticleController {
|
||||
|
||||
|
||||
/**
|
||||
* 根据分类ID获取该分类下的所有文章
|
||||
* @param typeid 分类ID
|
||||
* 根据分类ID获取该分类下的所有文章(兼容旧接口)
|
||||
* @param categoryId 分类ID
|
||||
* @return 返回包含文章列表的ResponseMessage对象
|
||||
*/
|
||||
@GetMapping("/category/{categoryId}")
|
||||
public ResponseMessage<List<Article>> getArticlesByCategory(@PathVariable Integer typeid) {
|
||||
return articleService.getArticlesByCategory(typeid);
|
||||
public ResponseMessage<List<Article>> getArticlesByCategory(@PathVariable Integer categoryId) {
|
||||
return articleService.getArticlesByCategory(categoryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据属性ID获取该属性下的所有文章
|
||||
* @param attributeId 属性ID
|
||||
* @return 返回包含文章列表的ResponseMessage对象
|
||||
*/
|
||||
@GetMapping("/attribute/{attributeId}")
|
||||
public ResponseMessage<List<Article>> getArticlesByAttribute(@PathVariable Integer attributeId) {
|
||||
return articleService.getArticlesByAttribute(attributeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据属性ID获取最新文章(按创建时间降序)
|
||||
* @param attributeId 属性ID
|
||||
* @return 返回包含最新文章列表的ResponseMessage对象
|
||||
*/
|
||||
@GetMapping("/attribute/{attributeId}/latest")
|
||||
public ResponseMessage<List<Article>> getLatestArticlesByAttribute(@PathVariable Integer attributeId) {
|
||||
return articleService.getLatestArticlesByAttribute(attributeId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.qf.myafterprojecy.controller;
|
||||
|
||||
import com.qf.myafterprojecy.pojo.Category_attribute;
|
||||
import com.qf.myafterprojecy.pojo.ResponseMessage;
|
||||
import com.qf.myafterprojecy.pojo.dto.CategoryAttributeDto;
|
||||
import com.qf.myafterprojecy.service.ICategoryAttributeService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import javax.validation.Valid;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/category-attributes")
|
||||
@Validated
|
||||
public class CategoryAttributeController {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(CategoryAttributeController.class);
|
||||
|
||||
@Autowired
|
||||
private ICategoryAttributeService categoryAttributeService;
|
||||
|
||||
/**
|
||||
* 根据ID获取分类属性
|
||||
* @param id 属性ID
|
||||
* @return 属性信息
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public ResponseMessage<Category_attribute> getAttributeById(@PathVariable Integer id) {
|
||||
log.info("接收根据ID获取分类属性的请求: ID={}", id);
|
||||
return categoryAttributeService.getCategoryAttributeById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类ID获取属性列表
|
||||
* @param categoryId 分类ID
|
||||
* @return 属性列表
|
||||
*/
|
||||
@GetMapping("/category/{categoryId}")
|
||||
public ResponseMessage<List<Category_attribute>> getAttributesByCategory(@PathVariable Integer categoryId) {
|
||||
log.info("接收根据分类ID获取属性列表的请求: 分类ID={}", categoryId);
|
||||
return categoryAttributeService.getAttributesByCategoryId(categoryId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新的分类属性
|
||||
* @param dto 分类属性数据
|
||||
* @return 创建结果
|
||||
*/
|
||||
@PostMapping
|
||||
public ResponseMessage<Category_attribute> createAttribute(@Valid @RequestBody CategoryAttributeDto dto) {
|
||||
log.info("接收创建分类属性的请求: 分类ID={}, 属性名称={}",
|
||||
dto.getCategoryid(), dto.getAttributename());
|
||||
return categoryAttributeService.saveCategoryAttribute(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新分类属性
|
||||
* @param id 属性ID
|
||||
* @param dto 分类属性数据
|
||||
* @return 更新结果
|
||||
*/
|
||||
@PutMapping("/{id}")
|
||||
public ResponseMessage<Category_attribute> updateAttribute(
|
||||
@PathVariable Integer id,
|
||||
@Valid @RequestBody CategoryAttributeDto dto) {
|
||||
log.info("接收更新分类属性的请求: ID={}, 分类ID={}, 属性名称={}",
|
||||
id, dto.getCategoryid(), dto.getAttributename());
|
||||
return categoryAttributeService.updateCategoryAttribute(id, dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分类属性
|
||||
* @param id 属性ID
|
||||
* @return 删除结果
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
public ResponseMessage<Boolean> deleteAttribute(@PathVariable Integer id) {
|
||||
log.info("接收删除分类属性的请求: ID={}", id);
|
||||
return categoryAttributeService.deleteCategoryAttribute(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查分类下是否存在指定名称的属性
|
||||
* @param categoryId 分类ID
|
||||
* @param attributeName 属性名称
|
||||
* @return 是否存在
|
||||
*/
|
||||
@GetMapping("/check-exists")
|
||||
public ResponseMessage<Boolean> checkAttributeExists(
|
||||
@RequestParam Integer categoryId,
|
||||
@RequestParam String attributeName) {
|
||||
log.info("接收检查分类属性是否存在的请求: 分类ID={}, 属性名称={}", categoryId, attributeName);
|
||||
return categoryAttributeService.existsByCategoryAndName(categoryId, attributeName);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user