64 lines
2.0 KiB
Java
64 lines
2.0 KiB
Java
package com.test.bijihoudaun.controller;
|
||
|
||
import com.test.bijihoudaun.common.response.R;
|
||
import com.test.bijihoudaun.entity.Grouping;
|
||
import com.test.bijihoudaun.service.GroupingService;
|
||
import io.swagger.v3.oas.annotations.Operation;
|
||
import io.swagger.v3.oas.annotations.Parameter;
|
||
import io.swagger.v3.oas.annotations.Parameters;
|
||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.web.bind.annotation.*;
|
||
|
||
import java.util.List;
|
||
|
||
@Tag(name = "分组接口")
|
||
@RestController
|
||
@RequestMapping("/api/groupings")
|
||
public class GroupingController {
|
||
|
||
@Autowired
|
||
private GroupingService groupingService;
|
||
|
||
@Operation(summary = "创建分组")
|
||
@PostMapping
|
||
public R<Grouping> createGrouping(@RequestBody Grouping grouping) {
|
||
Grouping created = groupingService.createGrouping(grouping);
|
||
return R.success(created);
|
||
}
|
||
|
||
@Operation(summary = "获取全部分组")
|
||
@Parameters({
|
||
@Parameter(name = "parentId", description = "0是一级,其他的是看它的父级id", required = true)
|
||
})
|
||
@GetMapping
|
||
public R<List<Grouping>> getAllGroupings(String parentId) {
|
||
if (parentId == null) {
|
||
return R.fail("参数不能为空");
|
||
}
|
||
long l = Long.parseLong(parentId);
|
||
List<Grouping> groupings = groupingService.getAllGroupings(l);
|
||
return R.success(groupings);
|
||
}
|
||
|
||
@Operation(summary = "更新分组名称")
|
||
@PutMapping("/{id}")
|
||
public R<Grouping> updateGrouping(
|
||
@PathVariable String id,
|
||
@RequestBody Grouping grouping) {
|
||
|
||
long l = Long.parseLong(id);
|
||
grouping.setId(l);
|
||
Grouping updated = groupingService.updateGrouping(grouping);
|
||
return R.success(updated);
|
||
}
|
||
|
||
@Operation(summary = "删除分组")
|
||
@DeleteMapping("/{id}")
|
||
public R<Void> deleteGrouping(@PathVariable String id) {
|
||
Long idLong = Long.parseLong(id);
|
||
groupingService.deleteGrouping(idLong);
|
||
return R.success();
|
||
}
|
||
}
|