132 lines
3.4 KiB
Rust
132 lines
3.4 KiB
Rust
use async_trait::async_trait;
|
|
use chrono::NaiveDateTime;
|
|
use serde::{Deserialize, Serialize};
|
|
use sqlx::FromRow;
|
|
use utoipa::ToSchema;
|
|
use uuid::Uuid;
|
|
|
|
use super::{collection::CollectionData, Error};
|
|
|
|
#[derive(Deserialize, Serialize, FromRow)]
|
|
pub struct Site {
|
|
/// Site internal ID
|
|
pub id: Uuid,
|
|
|
|
/// Site owner (user)
|
|
pub owner: Uuid,
|
|
|
|
/// Site name (unique per instance, shows up in URLs)
|
|
pub name: String,
|
|
|
|
/// Site's displayed name
|
|
pub title: String,
|
|
|
|
/// Site description (like a user's bio)
|
|
pub description: Option<String>,
|
|
|
|
/// Default collection (for homepage)
|
|
pub default_collection: Option<Uuid>,
|
|
|
|
/// Times
|
|
pub created_at: NaiveDateTime,
|
|
pub modified_at: Option<NaiveDateTime>,
|
|
pub deleted_at: Option<NaiveDateTime>,
|
|
}
|
|
|
|
/// More useful version of Site for showing to users
|
|
#[derive(Serialize, ToSchema)]
|
|
pub struct SiteData {
|
|
/// Site name (unique per instance, shows up in URLs)
|
|
pub name: String,
|
|
|
|
/// Site owner (user)
|
|
pub owner: String,
|
|
pub owner_display_name: Option<String>,
|
|
|
|
/// Site's displayed name
|
|
pub title: String,
|
|
|
|
/// Site description (like a user's bio)
|
|
pub description: Option<String>,
|
|
|
|
// Creation time
|
|
pub created_at: NaiveDateTime,
|
|
|
|
// Collections in the site
|
|
pub collections: Vec<CollectionData>,
|
|
|
|
// Default collection (for homepage)
|
|
pub default_collection: Option<Uuid>,
|
|
}
|
|
|
|
/// Data required to create a new site
|
|
#[derive(Deserialize, ToSchema)]
|
|
pub struct CreateSiteData {
|
|
/// Site name (unique per instance, shows up in URLs)
|
|
pub name: String,
|
|
|
|
/// Site's displayed name
|
|
pub title: String,
|
|
|
|
/// Site description (like a user's bio)
|
|
pub description: Option<String>,
|
|
}
|
|
|
|
/// Data required to update a site's info
|
|
#[derive(Deserialize, ToSchema)]
|
|
pub struct UpdateSiteData {
|
|
/// Site name (unique per instance, shows up in URLs)
|
|
pub name: Option<String>,
|
|
|
|
/// Site's displayed name
|
|
pub title: Option<String>,
|
|
|
|
/// Site description (like a user's bio)
|
|
pub description: Option<String>,
|
|
|
|
// Default collection (for homepage)
|
|
pub default_collection: Option<Uuid>,
|
|
}
|
|
|
|
/// Data required to show a summary of the website for lists
|
|
#[derive(Deserialize, Serialize, ToSchema)]
|
|
pub struct SiteShortInfo {
|
|
/// Site name (unique per instance, shows up in URLs)
|
|
pub name: String,
|
|
|
|
/// Site's displayed name
|
|
pub title: String,
|
|
|
|
/// Site description (like a user's bio)
|
|
pub description: Option<String>,
|
|
|
|
// Creation time
|
|
pub created_at: NaiveDateTime,
|
|
}
|
|
|
|
#[async_trait]
|
|
pub trait SiteRepository {
|
|
/// Retrieve site info from site name/slug
|
|
async fn get_site_by_name(&self, name: &str) -> Result<SiteData, Error>;
|
|
|
|
/// Create a new instance of a site and store it
|
|
async fn create_site(&self, owner: &Uuid, options: CreateSiteData) -> Result<Uuid, Error>;
|
|
|
|
/// Update an existing site's info
|
|
async fn update_site(
|
|
&self,
|
|
owner: &Uuid,
|
|
name: &str,
|
|
options: UpdateSiteData,
|
|
) -> Result<(), Error>;
|
|
|
|
/// Delete a site
|
|
async fn delete_site(&self, owner: &Uuid, name: &str, soft_delete: bool) -> Result<(), Error>;
|
|
|
|
/// Resolve a site's name to its ID
|
|
async fn get_site_id_and_owner(&self, name: &str) -> Result<(Uuid, Uuid), Error>;
|
|
|
|
/// Get a list of all sites owned by a user
|
|
async fn get_sites_by_owner(&self, owner: &Uuid) -> Result<Vec<SiteShortInfo>, Error>;
|
|
}
|