This commit is contained in:
@@ -31,26 +31,38 @@ public class ProductController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增分类
|
* 新增分类(仅管理员)
|
||||||
*/
|
*/
|
||||||
@PostMapping("/categories")
|
@PostMapping("/categories")
|
||||||
public Result<Category> createCategory(@RequestBody Category category) {
|
public Result<Category> createCategory(@RequestBody Category category,
|
||||||
|
@RequestHeader(value = "X-User-Role", required = false) String role) {
|
||||||
|
if (!"admin".equals(role)) {
|
||||||
|
return Result.error("只有管理员可以操作");
|
||||||
|
}
|
||||||
return Result.success(productService.createCategory(category));
|
return Result.success(productService.createCategory(category));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改分类
|
* 修改分类(仅管理员)
|
||||||
*/
|
*/
|
||||||
@PutMapping("/categories/{id}")
|
@PutMapping("/categories/{id}")
|
||||||
public Result<Category> updateCategory(@PathVariable String id, @RequestBody Category category) {
|
public Result<Category> updateCategory(@PathVariable String id, @RequestBody Category category,
|
||||||
|
@RequestHeader(value = "X-User-Role", required = false) String role) {
|
||||||
|
if (!"admin".equals(role)) {
|
||||||
|
return Result.error("只有管理员可以操作");
|
||||||
|
}
|
||||||
return Result.success(productService.updateCategory(id, category));
|
return Result.success(productService.updateCategory(id, category));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除分类
|
* 删除分类(仅管理员)
|
||||||
*/
|
*/
|
||||||
@DeleteMapping("/categories/{id}")
|
@DeleteMapping("/categories/{id}")
|
||||||
public Result<Void> deleteCategory(@PathVariable String id) {
|
public Result<Void> deleteCategory(@PathVariable String id,
|
||||||
|
@RequestHeader(value = "X-User-Role", required = false) String role) {
|
||||||
|
if (!"admin".equals(role)) {
|
||||||
|
return Result.error("只有管理员可以操作");
|
||||||
|
}
|
||||||
productService.deleteCategory(id);
|
productService.deleteCategory(id);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
@@ -76,26 +88,38 @@ public class ProductController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增商品
|
* 新增商品(仅管理员)
|
||||||
*/
|
*/
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public Result<Product> createProduct(@RequestBody Product product) {
|
public Result<Product> createProduct(@RequestBody Product product,
|
||||||
|
@RequestHeader(value = "X-User-Role", required = false) String role) {
|
||||||
|
if (!"admin".equals(role)) {
|
||||||
|
return Result.error("只有管理员可以操作");
|
||||||
|
}
|
||||||
return Result.success(productService.createProduct(product));
|
return Result.success(productService.createProduct(product));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改商品
|
* 修改商品(仅管理员)
|
||||||
*/
|
*/
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
public Result<Product> updateProduct(@PathVariable String id, @RequestBody Product product) {
|
public Result<Product> updateProduct(@PathVariable String id, @RequestBody Product product,
|
||||||
|
@RequestHeader(value = "X-User-Role", required = false) String role) {
|
||||||
|
if (!"admin".equals(role)) {
|
||||||
|
return Result.error("只有管理员可以操作");
|
||||||
|
}
|
||||||
return Result.success(productService.updateProduct(id, product));
|
return Result.success(productService.updateProduct(id, product));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除商品
|
* 删除商品(仅管理员)
|
||||||
*/
|
*/
|
||||||
@DeleteMapping("/{id}")
|
@DeleteMapping("/{id}")
|
||||||
public Result<Void> deleteProduct(@PathVariable String id) {
|
public Result<Void> deleteProduct(@PathVariable String id,
|
||||||
|
@RequestHeader(value = "X-User-Role", required = false) String role) {
|
||||||
|
if (!"admin".equals(role)) {
|
||||||
|
return Result.error("只有管理员可以操作");
|
||||||
|
}
|
||||||
productService.deleteProduct(id);
|
productService.deleteProduct(id);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user