diff options
| author | Santo Cariotti <santo@dcariotti.me> | 2022-09-24 16:10:08 +0000 |
|---|---|---|
| committer | Santo Cariotti <santo@dcariotti.me> | 2022-09-24 16:10:08 +0000 |
| commit | 357b9e646df220575df37fe1d6705a9667210997 (patch) | |
| tree | 76f415c19f636a2899dd469745baf21fbff8b808 /src/models/user.rs | |
| parent | f1b9eb9e54bc264c235a4d77a18ad2f3c943a6d1 (diff) | |
Get user's models
Diffstat (limited to 'src/models/user.rs')
| -rw-r--r-- | src/models/user.rs | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/models/user.rs b/src/models/user.rs index c4debf5..7c08075 100644 --- a/src/models/user.rs +++ b/src/models/user.rs @@ -1,4 +1,9 @@ -use crate::{config::CONFIG, db::get_client, errors::AppError}; +use crate::{ + config::CONFIG, + db::get_client, + errors::AppError, + models::model::{Model, ModelUser}, +}; use serde::{Deserialize, Serialize}; use serde_with::{serde_as, NoneAsEmptyString}; @@ -170,7 +175,7 @@ impl User { } impl UserList { - // Edit an user + /// Edit an user pub async fn edit_avatar(&mut self, avatar: Option<String>) -> Result<(), AppError> { let pool = unsafe { get_client() }; sqlx::query( @@ -187,4 +192,14 @@ impl UserList { Ok(()) } + + /// Get all models created by an user + pub async fn get_models(&self, page: i64) -> Result<Vec<ModelUser>, AppError> { + Model::list_from_author(page, self.id).await + } + + /// Returns the number of models for an user + pub async fn count_models(&self) -> Result<i64, AppError> { + Model::count_filter_by_author(self.id).await + } } |
