feat(api_key): implement API key management with creation, retrieval, and deletion endpoints
This commit is contained in:
32
thoughts-backend/models/src/domains/api_key.rs
Normal file
32
thoughts-backend/models/src/domains/api_key.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||
#[sea_orm(table_name = "api_key")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub id: Uuid,
|
||||
pub user_id: Uuid,
|
||||
pub key_prefix: String,
|
||||
#[sea_orm(unique)]
|
||||
pub key_hash: String,
|
||||
pub name: String,
|
||||
pub created_at: DateTimeWithTimeZone,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::user::Entity",
|
||||
from = "Column::UserId",
|
||||
to = "super::user::Column::Id"
|
||||
)]
|
||||
User,
|
||||
}
|
||||
|
||||
impl Related<super::user::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::User.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
@@ -2,6 +2,7 @@
|
||||
|
||||
pub mod prelude;
|
||||
|
||||
pub mod api_key;
|
||||
pub mod follow;
|
||||
pub mod tag;
|
||||
pub mod thought;
|
||||
|
@@ -1,5 +1,6 @@
|
||||
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0
|
||||
|
||||
pub use super::api_key::Entity as ApiKey;
|
||||
pub use super::follow::Entity as Follow;
|
||||
pub use super::tag::Entity as Tag;
|
||||
pub use super::thought::Entity as Thought;
|
||||
|
@@ -28,6 +28,9 @@ pub enum Relation {
|
||||
|
||||
#[sea_orm(has_many = "super::top_friends::Entity")]
|
||||
TopFriends,
|
||||
|
||||
#[sea_orm(has_many = "super::api_key::Entity")]
|
||||
ApiKey,
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
Reference in New Issue
Block a user