53 lines
1.3 KiB
Rust
53 lines
1.3 KiB
Rust
use crate::models::group;
|
|
use sea_orm::Set;
|
|
use serde::{Deserialize, Serialize};
|
|
use utoipa::ToSchema;
|
|
use uuid::Uuid;
|
|
|
|
#[derive(Debug, Serialize, ToSchema)]
|
|
pub struct GroupResponse {
|
|
pub id: Uuid,
|
|
pub server_id: Uuid,
|
|
pub name: String,
|
|
pub permissions: i64,
|
|
pub is_default: bool,
|
|
pub created_at: String,
|
|
}
|
|
|
|
impl From<group::Model> for GroupResponse {
|
|
fn from(model: group::Model) -> Self {
|
|
Self {
|
|
id: model.id,
|
|
server_id: model.server_id,
|
|
name: model.name,
|
|
permissions: model.permissions,
|
|
is_default: model.is_default,
|
|
created_at: model.created_at.to_rfc3339(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, ToSchema)]
|
|
pub struct CreateGroupRequest {
|
|
pub server_id: Uuid,
|
|
pub name: String,
|
|
pub permissions: i64,
|
|
}
|
|
|
|
impl CreateGroupRequest {
|
|
pub fn into_active_model(self) -> group::ActiveModel {
|
|
group::ActiveModel {
|
|
server_id: Set(self.server_id),
|
|
name: Set(self.name),
|
|
permissions: Set(self.permissions),
|
|
..Default::default()
|
|
}
|
|
}
|
|
|
|
pub fn apply_to(self, mut am: group::ActiveModel) -> group::ActiveModel {
|
|
am.name = Set(self.name);
|
|
am.permissions = Set(self.permissions);
|
|
am
|
|
}
|
|
}
|