mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-29 05:09:46 +01:00
绑定解绑完善请求参数
This commit is contained in:
parent
f7ab083e05
commit
cee55b9c86
3 changed files with 51 additions and 7 deletions
|
|
@ -15,7 +15,8 @@ import xiaozhi.modules.security.user.SecurityUser;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import xiaozhi.common.validator.AssertUtils;
|
import xiaozhi.common.validator.AssertUtils;
|
||||||
|
import xiaozhi.modules.device.dto.DeviceBindDTO;
|
||||||
|
import xiaozhi.modules.device.dto.DeviceUnBindDTO;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/device")
|
@RequestMapping("/device")
|
||||||
|
|
@ -24,14 +25,15 @@ import xiaozhi.common.validator.AssertUtils;
|
||||||
public class DeviceController {
|
public class DeviceController {
|
||||||
private final DeviceService deviceService;
|
private final DeviceService deviceService;
|
||||||
|
|
||||||
@PostMapping("/bind/{deviceCode}")
|
|
||||||
|
@PostMapping("/bind")
|
||||||
@Operation(summary = "绑定设备")
|
@Operation(summary = "绑定设备")
|
||||||
@RequiresPermissions("sys:device:bind")
|
@RequiresPermissions("sys:device:bind")
|
||||||
public Result<DeviceDTO> register(@RequestBody String deviceCode) {
|
public Result<DeviceDTO> register(@RequestBody DeviceBindDTO deviveBind) {
|
||||||
UserDetail user = SecurityUser.getUser();
|
UserDetail user = SecurityUser.getUser();
|
||||||
|
|
||||||
AssertUtils.isBlank(deviceCode, 400, "设备编码不能为空");
|
AssertUtils.isBlank(deviveBind.getDeviceCode(),400, "设备编码不能为空");
|
||||||
DeviceDTO device = deviceService.bindDevice(user.getId(), deviceCode);
|
DeviceDTO device = deviceService.bindDevice(user.getId(), deviveBind.getDeviceCode());
|
||||||
return new Result<DeviceDTO>().ok(device);
|
return new Result<DeviceDTO>().ok(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,9 +49,9 @@ public class DeviceController {
|
||||||
@PostMapping("/unbind")
|
@PostMapping("/unbind")
|
||||||
@Operation(summary = "解绑设备")
|
@Operation(summary = "解绑设备")
|
||||||
@RequiresPermissions("sys:device:unbind")
|
@RequiresPermissions("sys:device:unbind")
|
||||||
public Result unbindDevice(@RequestBody Long deviceId) {
|
public Result unbindDevice(@RequestBody DeviceUnBindDTO unDeviveBind) {
|
||||||
UserDetail user = SecurityUser.getUser();
|
UserDetail user = SecurityUser.getUser();
|
||||||
deviceService.unbindDevice(user.getId(), deviceId);
|
deviceService.unbindDevice(user.getId(), unDeviveBind.getDeviceId());
|
||||||
return new Result();
|
return new Result();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
package xiaozhi.modules.device.dto;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备绑定表单
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Schema(description = "设备绑定表单")
|
||||||
|
public class DeviceBindDTO implements Serializable {
|
||||||
|
|
||||||
|
@Schema(description = "设备验证码")
|
||||||
|
@NotBlank(message = "设备验证码不能为空")
|
||||||
|
private String deviceCode;
|
||||||
|
|
||||||
|
@Schema(description = "设备ID")
|
||||||
|
@NotBlank(message = "设备ID不能为空")
|
||||||
|
private Long deviceId;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package xiaozhi.modules.device.dto;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备绑定表单
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Schema(description = "设备解绑表单")
|
||||||
|
public class DeviceUnBindDTO implements Serializable {
|
||||||
|
|
||||||
|
@Schema(description = "设备ID")
|
||||||
|
@NotBlank(message = "设备ID不能为空")
|
||||||
|
private Long deviceId;
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue