backend: working license controller

This commit is contained in:
Sphereso 2024-07-09 18:50:42 +02:00
parent e3a3c5bc78
commit cb9d3464e3
13 changed files with 252 additions and 2 deletions

View file

@ -4,6 +4,8 @@ pub struct Migrator;
mod m20240705_100914_create_user;
mod m20240708_085852_create_admin_user;
mod m20240709_095319_create_license_group;
mod m20240709_095325_create_license;
#[async_trait::async_trait]
impl MigratorTrait for Migrator {
@ -11,6 +13,8 @@ impl MigratorTrait for Migrator {
vec![
Box::new(m20240705_100914_create_user::Migration),
Box::new(m20240708_085852_create_admin_user::Migration),
Box::new(m20240709_095319_create_license_group::Migration),
Box::new(m20240709_095325_create_license::Migration),
]
}
}

View file

@ -0,0 +1,39 @@
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(LicenseGroup::Table)
.if_not_exists()
.col(
ColumnDef::new(LicenseGroup::Id)
.uuid()
.not_null()
.primary_key()
.extra("DEFAULT gen_random_uuid()"),
)
.col(ColumnDef::new(LicenseGroup::Name).string().not_null())
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(LicenseGroup::Table).to_owned())
.await
}
}
#[derive(DeriveIden)]
enum LicenseGroup {
Table,
Id,
Name,
}

View file

@ -0,0 +1,63 @@
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.create_table(
Table::create()
.table(License::Table)
.if_not_exists()
.col(
ColumnDef::new(License::Id)
.uuid()
.not_null()
.primary_key()
.extra("DEFAULT gen_random_uuid()"),
)
.col(ColumnDef::new(License::Name).string().not_null())
.col(ColumnDef::new(License::Start).date_time())
.col(ColumnDef::new(License::End).date_time())
.col(ColumnDef::new(License::Amount).date_time())
.col(ColumnDef::new(License::Key).string().not_null())
.col(ColumnDef::new(License::GroupId).uuid().not_null())
.foreign_key(
ForeignKey::create()
.name("fk-license-group_id")
.from(License::Table, License::GroupId)
.to(LicenseGroup::Table, LicenseGroup::Id)
.on_update(ForeignKeyAction::Cascade)
.on_delete(ForeignKeyAction::Cascade),
)
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(License::Table).to_owned())
.await
}
}
#[derive(DeriveIden)]
enum License {
Table,
Id,
Name,
Start,
End,
Amount,
Key,
GroupId,
}
#[derive(DeriveIden)]
enum LicenseGroup {
Table,
Id,
}