Collections users route (#711)

* users route

* Added user route

* collections
This commit is contained in:
Wyatt Verchere
2023-09-18 11:43:58 -07:00
committed by GitHub
parent f65f949a36
commit 4bf030993a
7 changed files with 103 additions and 9 deletions

View File

@@ -1,4 +1,5 @@
use super::ids::{ProjectId, UserId};
use super::CollectionId;
use crate::database::models::DatabaseError;
use crate::models::ids::base62_impl::{parse_base62, to_base62};
use crate::models::users::{Badges, RecipientType, RecipientWallet};
@@ -320,6 +321,30 @@ impl User {
Ok(projects)
}
pub async fn get_collections<'a, E>(
user_id: UserId,
exec: E,
) -> Result<Vec<CollectionId>, sqlx::Error>
where
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
{
use futures::stream::TryStreamExt;
let projects = sqlx::query!(
"
SELECT c.id FROM collections c
WHERE c.user_id = $1
",
user_id as UserId,
)
.fetch_many(exec)
.try_filter_map(|e| async { Ok(e.right().map(|m| CollectionId(m.id))) })
.try_collect::<Vec<CollectionId>>()
.await?;
Ok(projects)
}
pub async fn get_backup_codes<'a, E>(
user_id: UserId,
exec: E,