Files
komodo/client/core/rs/src/api/user.rs
T
2024-05-25 20:36:52 -07:00

98 lines
2.3 KiB
Rust

use derive_empty_traits::EmptyTraits;
use resolver_api::{derive::Request, HasResponse};
use serde::{Deserialize, Serialize};
use typeshare::typeshare;
use crate::entities::{update::ResourceTarget, NoData, I64};
pub trait MonitorUserRequest: HasResponse {}
//
/// Push a resource to the front of the users 10 most recently viewed resources.
/// Response: [NoData].
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
)]
#[empty_traits(MonitorUserRequest)]
#[response(PushRecentlyViewedResponse)]
pub struct PushRecentlyViewed {
/// The target to push.
pub resource: ResourceTarget,
}
#[typeshare]
pub type PushRecentlyViewedResponse = NoData;
//
/// Set the time the user last opened the UI updates.
/// Used for unseen notification dot.
/// Response: [NoData]
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
)]
#[empty_traits(MonitorUserRequest)]
#[response(SetLastSeenUpdateResponse)]
pub struct SetLastSeenUpdate {}
#[typeshare]
pub type SetLastSeenUpdateResponse = NoData;
//
/// Create an api key for the calling user.
/// Response: [CreateApiKeyResponse].
///
/// Note. After the response is served, there will be no way
/// to get the secret later.
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
)]
#[empty_traits(MonitorUserRequest)]
#[response(CreateApiKeyResponse)]
pub struct CreateApiKey {
/// The name for the api key.
pub name: String,
/// A unix timestamp in millseconds specifying api key expire time.
/// Default is 0, which means no expiry.
#[serde(default)]
pub expires: I64,
}
/// Response for [CreateApiKey].
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct CreateApiKeyResponse {
/// X-API-KEY
pub key: String,
/// X-API-SECRET
///
/// Note.
/// There is no way to get the secret again after it is distributed in this message
pub secret: String,
}
//
/// Delete an api key for the calling user.
/// Response: [NoData]
#[typeshare]
#[derive(
Serialize, Deserialize, Debug, Clone, Request, EmptyTraits,
)]
#[empty_traits(MonitorUserRequest)]
#[response(DeleteApiKeyResponse)]
pub struct DeleteApiKey {
/// The key which the user intends to delete.
pub key: String,
}
#[typeshare]
pub type DeleteApiKeyResponse = NoData;