use chrono::offset::Utc;
use chrono::DateTime;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use crate::framework::endpoint::{EndpointSpec, Method};
use crate::framework::response::{ApiResult, ApiSuccess};
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
pub struct Bucket {
pub name: String,
pub creation_date: DateTime<Utc>,
}
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
pub struct ListBucketsResult {
pub buckets: Vec<Bucket>,
}
type EmptyMap = HashMap<(), ()>;
impl ApiResult for EmptyMap {}
impl ApiResult for ListBucketsResult {}
#[derive(Debug)]
pub struct ListBuckets<'a> {
pub account_identifier: &'a str,
}
impl EndpointSpec for ListBuckets<'_> {
type JsonResponse = ListBucketsResult;
type ResponseType = ApiSuccess<Self::JsonResponse>;
fn method(&self) -> Method {
Method::GET
}
fn path(&self) -> String {
format!("accounts/{}/r2/buckets", self.account_identifier)
}
}
#[derive(Debug)]
pub struct CreateBucket<'a> {
pub account_identifier: &'a str,
pub bucket_name: &'a str,
}
impl EndpointSpec for CreateBucket<'_> {
type JsonResponse = EmptyMap;
type ResponseType = ApiSuccess<Self::JsonResponse>;
fn method(&self) -> Method {
Method::PUT
}
fn path(&self) -> String {
format!(
"accounts/{}/r2/buckets/{}",
self.account_identifier, self.bucket_name
)
}
}
#[derive(Debug)]
pub struct DeleteBucket<'a> {
pub account_identifier: &'a str,
pub bucket_name: &'a str,
}
impl EndpointSpec for DeleteBucket<'_> {
type JsonResponse = EmptyMap;
type ResponseType = ApiSuccess<Self::JsonResponse>;
fn method(&self) -> Method {
Method::DELETE
}
fn path(&self) -> String {
format!(
"accounts/{}/r2/buckets/{}",
self.account_identifier, self.bucket_name
)
}
}