92 lines
3.0 KiB
Java
92 lines
3.0 KiB
Java
package com.emotion.controller;
|
|
|
|
import com.emotion.common.PageResult;
|
|
import com.emotion.common.Result;
|
|
import com.emotion.dto.request.AdminCreateRequest;
|
|
import com.emotion.dto.request.AdminPageRequest;
|
|
import com.emotion.dto.request.AdminUpdateRequest;
|
|
import com.emotion.dto.response.AdminResponse;
|
|
import com.emotion.service.AdminService;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
/**
|
|
* 管理员控制器
|
|
*
|
|
* @author huazhongmin
|
|
* @date 2025-10-27
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/admin")
|
|
@Tag(name = "管理员管理", description = "管理员的增删改查功能")
|
|
public class AdminController {
|
|
|
|
@Autowired
|
|
private AdminService adminService;
|
|
|
|
/**
|
|
* 分页查询管理员
|
|
*/
|
|
@Operation(summary = "分页查询管理员", description = "分页查询管理员列表")
|
|
@GetMapping("/page")
|
|
public Result<PageResult<AdminResponse>> getPage(@Validated AdminPageRequest request) {
|
|
PageResult<AdminResponse> pageResult = adminService.getPageWithResponse(request);
|
|
return Result.success(pageResult);
|
|
}
|
|
|
|
/**
|
|
* 根据ID获取管理员
|
|
*/
|
|
@Operation(summary = "根据ID获取管理员", description = "根据ID获取管理员详情")
|
|
@GetMapping("/detail")
|
|
public Result<AdminResponse> getById(@RequestParam String id) {
|
|
AdminResponse response = adminService.getAdminResponseById(id);
|
|
if (response == null) {
|
|
return Result.notFound("管理员不存在");
|
|
}
|
|
return Result.success(response);
|
|
}
|
|
|
|
/**
|
|
* 创建管理员
|
|
*/
|
|
@Operation(summary = "创建管理员", description = "创建新的管理员")
|
|
@PostMapping("/create")
|
|
public Result<AdminResponse> create(@RequestBody @Validated AdminCreateRequest request) {
|
|
AdminResponse response = adminService.createAdminWithResponse(request);
|
|
if (response == null) {
|
|
return Result.error("创建失败");
|
|
}
|
|
return Result.success("创建成功", response);
|
|
}
|
|
|
|
/**
|
|
* 更新管理员
|
|
*/
|
|
@Operation(summary = "更新管理员", description = "更新指定管理员")
|
|
@PutMapping("/update")
|
|
public Result<AdminResponse> update(@RequestBody @Validated AdminUpdateRequest request) {
|
|
AdminResponse response = adminService.updateAdminWithResponse(request);
|
|
if (response == null) {
|
|
return Result.error("更新失败");
|
|
}
|
|
return Result.success("更新成功", response);
|
|
}
|
|
|
|
/**
|
|
* 删除管理员
|
|
*/
|
|
@Operation(summary = "删除管理员", description = "删除指定管理员")
|
|
@DeleteMapping("/delete")
|
|
public Result<Void> delete(@RequestParam String id) {
|
|
boolean deleted = adminService.removeById(id);
|
|
if (!deleted) {
|
|
return Result.error("删除失败");
|
|
}
|
|
return Result.success("删除成功", null);
|
|
}
|
|
}
|