summaryrefslogtreecommitdiffstats
path: root/src/models/user.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/models/user.rs')
-rw-r--r--src/models/user.rs19
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
+ }
}