feature: [种类] 种类管理
This commit is contained in:
parent
7dc80cd187
commit
00a247cfae
|
@ -1,14 +1,21 @@
|
||||||
package com.guwan.backend.controller;
|
package com.guwan.backend.controller;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.guwan.backend.common.Result;
|
import com.guwan.backend.common.Result;
|
||||||
|
|
||||||
|
|
||||||
|
import com.guwan.backend.common.SearchResult;
|
||||||
|
import com.guwan.backend.pojo.entity.BSCategory;
|
||||||
import com.guwan.backend.service.BSCategoryService;
|
import com.guwan.backend.service.BSCategoryService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/category")
|
@RequestMapping("/category")
|
||||||
|
@ -18,12 +25,22 @@ public class CategotyController {
|
||||||
private final BSCategoryService categoryService;
|
private final BSCategoryService categoryService;
|
||||||
|
|
||||||
@GetMapping("/getAll")
|
@GetMapping("/getAll")
|
||||||
public Result getAllCategory() {
|
public SearchResult getAllCategory(@RequestParam(name = "page", required = false) Long pageNum,
|
||||||
|
@RequestParam(required = false) Long size) {
|
||||||
try {
|
try {
|
||||||
return Result.success(categoryService.list());
|
|
||||||
|
if (pageNum != null && size != null) {
|
||||||
|
Page<BSCategory> bsCategoryPage = new Page<>(pageNum, size);
|
||||||
|
Page<BSCategory> page = categoryService.page(bsCategoryPage);
|
||||||
|
List<BSCategory> records = page.getRecords();
|
||||||
|
long total = page.getTotal();
|
||||||
|
return SearchResult.success(records, total);
|
||||||
|
}
|
||||||
|
|
||||||
|
return SearchResult.success(categoryService.list());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Failed to get categories", e);
|
log.error("Failed to get categories", e);
|
||||||
return Result.error("Failed to get categories");
|
return SearchResult.error("Failed to get categories");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue