add entity and migration crates with SeaORM models for group, project, user, and user_group_project

This commit is contained in:
Mika 2025-03-28 17:27:50 +01:00
parent 801353eed1
commit f7612711b0
9 changed files with 200 additions and 5 deletions

View file

@ -7,3 +7,12 @@ name = "peer-group-grading"
version = "0.1.0"
edition = "2024"
[workspace.dependencies]
entity = { path = "crates/entity" }
migration = { path = "crates/migration" }
serde = { version = "*", features = ["derive"] }
sea-orm = { version = "1.1.0", features = [
"runtime-tokio-rustls",
"sqlx-postgres",
] }

View file

@ -1,16 +1,18 @@
[package]
name = "backend"
version = {workspace = true}
edition = {workspace = true}
version = { workspace = true }
edition = { workspace = true }
[dependencies]
entity = { workspace = true }
migration = { workspace = true }
actix-web = "4"
actix-session = { version = "0.10", features = ["redis-session"] }
actix-cors = "0.7"
actix-files = "0.6"
tracing-actix-web = "0.7.16"
env_logger = "0.11"
serde = {version = "1", features = ["derive"]}
env_logger = "0.11"
serde = { version = "1", features = ["derive"] }

8
crates/entity/Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "entity"
version = { workspace = true }
edition = { workspace = true }
[dependencies]
serde = { workspace = true }
sea-orm = { workspace = true }

View file

@ -0,0 +1,42 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.4
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "group")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
#[sea_orm(primary_key, auto_increment = false)]
pub project_id: Uuid,
pub name: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::project::Entity",
from = "Column::ProjectId",
to = "super::project::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
Project,
#[sea_orm(has_many = "super::user_group_project::Entity")]
UserGroupProject,
}
impl Related<super::project::Entity> for Entity {
fn to() -> RelationDef {
Relation::Project.def()
}
}
impl Related<super::user_group_project::Entity> for Entity {
fn to() -> RelationDef {
Relation::UserGroupProject.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

8
crates/entity/src/lib.rs Normal file
View file

@ -0,0 +1,8 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.4
pub mod prelude;
pub mod group;
pub mod project;
pub mod user;
pub mod user_group_project;

View file

@ -0,0 +1,6 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.4
pub use super::group::Entity as Group;
pub use super::project::Entity as Project;
pub use super::user::Entity as User;
pub use super::user_group_project::Entity as UserGroupProject;

View file

@ -0,0 +1,35 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.4
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "project")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub name: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::group::Entity")]
Group,
}
impl Related<super::group::Entity> for Entity {
fn to() -> RelationDef {
Relation::Group.def()
}
}
impl Related<super::user_group_project::Entity> for Entity {
fn to() -> RelationDef {
super::group::Relation::UserGroupProject.def()
}
fn via() -> Option<RelationDef> {
Some(super::group::Relation::Project.def().rev())
}
}
impl ActiveModelBehavior for ActiveModel {}

27
crates/entity/src/user.rs Normal file
View file

@ -0,0 +1,27 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.4
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "user")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub name: String,
pub role: String,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::user_group_project::Entity")]
UserGroupProject,
}
impl Related<super::user_group_project::Entity> for Entity {
fn to() -> RelationDef {
Relation::UserGroupProject.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View file

@ -0,0 +1,58 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.4
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "user_group_project")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub user_id: Uuid,
#[sea_orm(primary_key, auto_increment = false)]
pub group_id: Uuid,
#[sea_orm(primary_key, auto_increment = false)]
pub project_id: Uuid,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::group::Entity",
from = "(Column::GroupId, Column::ProjectId)",
to = "(super::group::Column::Id, super::group::Column::ProjectId)",
on_update = "Cascade",
on_delete = "Cascade"
)]
Group,
#[sea_orm(
belongs_to = "super::user::Entity",
from = "Column::UserId",
to = "super::user::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
User,
}
impl Related<super::group::Entity> for Entity {
fn to() -> RelationDef {
Relation::Group.def()
}
}
impl Related<super::user::Entity> for Entity {
fn to() -> RelationDef {
Relation::User.def()
}
}
impl Related<super::project::Entity> for Entity {
fn to() -> RelationDef {
super::group::Relation::Project.def()
}
fn via() -> Option<RelationDef> {
Some(super::group::Relation::UserGroupProject.def().rev())
}
}
impl ActiveModelBehavior for ActiveModel {}