-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: api user crud and request validation with api cred implemented
- Loading branch information
1 parent
cee5569
commit 0b15f0c
Showing
13 changed files
with
343 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use crate::{models::api_user, utils::check_locked_at_constraint}; | ||
use async_trait::async_trait; | ||
use sea_orm::{entity::prelude::*, sqlx::types::chrono::Utc, ActiveValue}; | ||
|
||
#[async_trait] | ||
impl ActiveModelBehavior for api_user::ActiveModel { | ||
/// Will be triggered before insert / update | ||
async fn before_save<C>(mut self, _db: &C, _insert: bool) -> Result<Self, DbErr> | ||
where | ||
C: ConnectionTrait, | ||
{ | ||
if let ActiveValue::Set(ref locked_at) = self.locked_at { | ||
check_locked_at_constraint(locked_at)? | ||
} | ||
|
||
if let ActiveValue::Set(ref expires) = self.expires { | ||
if expires < &Utc::now().fixed_offset() { | ||
return Err(DbErr::Custom("Expires must be greater than created_at".to_owned())); | ||
} | ||
} | ||
|
||
Ok(self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod api_user; | ||
pub mod client; | ||
pub mod realm; | ||
pub mod resource; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.