Skip to content

Commit

Permalink
每次新增路由后,自动分配给管理员角色
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuYuYang01 committed Jan 25, 2025
1 parent d23a018 commit e61edb2
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions blog/src/main/java/liuyuyang/net/controller/RouteController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import liuyuyang.net.annotation.CheckRole;
import liuyuyang.net.annotation.PremName;
import liuyuyang.net.execption.CustomException;
import liuyuyang.net.model.Route;
import liuyuyang.net.model.RouteRole;
import liuyuyang.net.service.RouteRoleService;
import liuyuyang.net.utils.Result;
import liuyuyang.net.service.RouteService;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -22,19 +22,24 @@
public class RouteController {
@Resource
private RouteService routeService;
@Resource
private RouteRoleService routeRoleService;

@PremName("route:add")
@PostMapping
@ApiOperation("新增路由")
@ApiOperationSupport(author = "刘宇阳 | liuyuyang1024@yeah.net", order = 1)
public Result<String> add(@RequestBody Route route) {
try {
boolean res = routeService.save(route);
routeService.save(route);

// 每次新增路由后,自动分配给管理员角色
RouteRole routeRole = new RouteRole();
routeRole.setRouteId(route.getId());
routeRole.setRoleId(1);

return res ? Result.success() : Result.error();
} catch (Exception e) {
throw new CustomException(400, e.getMessage());
}
routeRoleService.save(routeRole);

return Result.success();
}

@PremName("route:del")
Expand All @@ -44,34 +49,26 @@ public Result<String> add(@RequestBody Route route) {
public Result<String> del(@PathVariable Integer id) {
Route data = routeService.getById(id);
if (data == null) return Result.error("该数据不存在");

Boolean res = routeService.removeById(id);

return res ? Result.success() : Result.error();
routeService.removeById(id);
return Result.success();
}

@PremName("route:del")
@DeleteMapping("/batch")
@ApiOperation("批量删除路由")
@ApiOperationSupport(author = "刘宇阳 | liuyuyang1024@yeah.net", order = 3)
public Result batchDel(@RequestBody List<Integer> ids) {
Boolean res = routeService.removeByIds(ids);

return res ? Result.success() : Result.error();
routeService.removeByIds(ids);
return Result.success();
}

@PremName("route:edit")
@PatchMapping
@ApiOperation("编辑路由")
@ApiOperationSupport(author = "刘宇阳 | liuyuyang1024@yeah.net", order = 4)
public Result<String> edit(@RequestBody Route route) {
try {
boolean res = routeService.updateById(route);

return res ? Result.success() : Result.error();
} catch (Exception e) {
throw new CustomException(400, e.getMessage());
}
routeService.updateById(route);
return Result.success();
}

@PremName("route:info")
Expand Down

0 comments on commit e61edb2

Please sign in to comment.