feat(device): refactor device management API and implement CRUD operations
- Rename CreateDriveRequest to CreateDeviceRequest - Add DeviceQueryRequest for pagination and filtering - Add UpdateDeviceRequest for device updates - Refactor DeviceController with RESTful endpoints - Implement getAllDevices with pagination and search - Implement createDevice endpoint - Implement updateDevice endpoint - Implement deleteDevice endpoint - Remove real delete endpoint - Add DeviceResponse and OptionResponse DTOs - Update DeviceService interface and implementation - Add device type options endpoint - Update device type controller mappings
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package cn.nopj.chaos_api.controller;
|
||||
|
||||
|
||||
import cn.nopj.chaos_api.dto.request.CreateDriveRequest;
|
||||
import cn.nopj.chaos_api.dto.request.CreateDeviceRequest;
|
||||
import cn.nopj.chaos_api.dto.request.DeviceQueryRequest;
|
||||
import cn.nopj.chaos_api.dto.request.UpdateDeviceRequest;
|
||||
import cn.nopj.chaos_api.dto.response.DeviceResponse;
|
||||
import cn.nopj.chaos_api.model.ApiResult;
|
||||
import cn.nopj.chaos_api.service.DeviceService;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -14,7 +17,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
* 设备管理
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/device")
|
||||
@RequestMapping("/api/devices")
|
||||
public class DeviceController {
|
||||
|
||||
private final DeviceService deviceService;
|
||||
@@ -23,14 +26,24 @@ public class DeviceController {
|
||||
this.deviceService = deviceService;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查询所有设备信息
|
||||
* @return 所有设备信息
|
||||
*/
|
||||
@GetMapping
|
||||
public ApiResult<IPage<DeviceResponse>> getAllDevices(DeviceQueryRequest request){
|
||||
return ApiResult.success(deviceService.getAllDevices(request));
|
||||
}
|
||||
/**
|
||||
* 新建设备信息
|
||||
* @param createDriveRequest 设备信息
|
||||
* @param createDeviceRequest 设备信息
|
||||
* @return 新建设备信息结果
|
||||
*/
|
||||
@PostMapping("/create")
|
||||
public ApiResult<DeviceResponse> createDevice(@RequestBody @Validated CreateDriveRequest createDriveRequest){
|
||||
return ApiResult.success(deviceService.createDevice(createDriveRequest));
|
||||
@PostMapping
|
||||
public ApiResult<DeviceResponse> createDevice(@RequestBody @Validated CreateDeviceRequest createDeviceRequest){
|
||||
return ApiResult.success(deviceService.createDevice(createDeviceRequest));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,7 +56,7 @@ public class DeviceController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 逻辑删除指定设备信息
|
||||
* 删除指定设备信息
|
||||
* @return 逻辑删除指定设备信息结果
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
@@ -51,16 +64,13 @@ public class DeviceController {
|
||||
deviceService.deleteDevice(id);
|
||||
return ApiResult.success("删除成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 真实删除指定设备信息
|
||||
* @return 真实删除指定设备信息结果
|
||||
* 修改指定设备信息
|
||||
* @return 修改指定设备信息结果
|
||||
*/
|
||||
@PreAuthorize("hasAuthority('admin')")
|
||||
@DeleteMapping("/deleteReal")
|
||||
public ApiResult<String> deleteDeviceReal(@RequestParam(value = "id") Long id){
|
||||
deviceService.deleteDeviceReal(id);
|
||||
return ApiResult.success("删除成功");
|
||||
@PutMapping({"/{id}"})
|
||||
public ApiResult<DeviceResponse> updateDevice(@RequestBody @Validated UpdateDeviceRequest updateDeviceRequest){
|
||||
return ApiResult.success(deviceService.updateDevice(updateDeviceRequest));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package cn.nopj.chaos_api.controller;
|
||||
|
||||
import cn.nopj.chaos_api.dto.response.DeviceTypeResponse;
|
||||
import cn.nopj.chaos_api.dto.response.OptionResponse;
|
||||
import cn.nopj.chaos_api.model.ApiResult;
|
||||
import cn.nopj.chaos_api.service.DeviceTypeService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -14,7 +16,7 @@ import java.util.List;
|
||||
* @author nopj
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/deviceType")
|
||||
@RequestMapping("/api/device-types")
|
||||
public class DeviceTypeController {
|
||||
private final DeviceTypeService deviceTypeService;
|
||||
|
||||
@@ -22,14 +24,18 @@ public class DeviceTypeController {
|
||||
this.deviceTypeService = deviceTypeService;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取所有设备类型
|
||||
*
|
||||
* @return 所有设备类型
|
||||
*/
|
||||
@RequestMapping("/all")
|
||||
@GetMapping
|
||||
public ApiResult<List<DeviceTypeResponse>> getAllDeviceTypes() {
|
||||
return ApiResult.success(deviceTypeService.getAllDeviceTypes());
|
||||
}
|
||||
|
||||
@GetMapping("/options")
|
||||
public ApiResult<List<OptionResponse>> getDeviceTypeOptions() {
|
||||
return ApiResult.success(deviceTypeService.getDeviceTypeOptions());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,4 +92,5 @@ public class UserController {
|
||||
ApiResult<UserProfileResponse> setNickname(@PathVariable Long userId, @RequestBody @Validated SetUserNicknameRequest request){
|
||||
return ApiResult.success(userProfileService.setUserNickname(userId,request.getNickname()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user