Skip to content
Clone
08cefb1
30 lines 944 B Rust
use axum::extract::{Path, State};
use export::data::{AppRequest, AppRequestData, AppResponseData};
use jwt::extractor::AuthUser;
use uuid::Uuid;
use crate::error::UserResult;
use crate::features::UserService;
use crate::features::devices::{DeviceView, UpdateDeviceCmd};
#[utoipa::path(
patch,
path = "/user/me/devices/{id}",
tag = "user",
params(("id" = Uuid, Path, description = "Device identifier.")),
request_body = AppRequestData<UpdateDeviceCmd>,
responses(
(status = 200, description = "Device updated.", body = AppResponseData<DeviceView>),
),
security(("bearer_auth" = [])),
)]
pub(crate) async fn handler(
State(svc): State<UserService>,
AuthUser { claims }: AuthUser,
Path(id): Path<Uuid>,
cmd: AppRequest<UpdateDeviceCmd>,
) -> UserResult<AppResponseData<DeviceView>> {
Ok(AppResponseData::ok(
svc.update_device(claims.sub, id, cmd.into_inner()).await?,
))
}