Repo layer refactor.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct UserAppSecret {
|
||||
pub id: Uuid,
|
||||
pub app_id: Uuid,
|
||||
|
||||
@@ -21,24 +21,23 @@ pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<Account>, Repo
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
let accounts = db::list(
|
||||
executor,
|
||||
db::Query {
|
||||
name: query.name,
|
||||
limit: query
|
||||
.limit
|
||||
.map(|l| i64::try_from(l).map_err(|_| QueryConversionError::Limit(l)))
|
||||
.transpose()?,
|
||||
offset: query
|
||||
.offset
|
||||
.map(|o| i64::try_from(o).map_err(|_| QueryConversionError::Offset(o)))
|
||||
.transpose()?,
|
||||
},
|
||||
)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(decode)
|
||||
.collect::<Result<_, DecodeError>>()?;
|
||||
let query = db::Query {
|
||||
name: query.name,
|
||||
limit: query
|
||||
.limit
|
||||
.map(|l| i64::try_from(l).map_err(|_| QueryConversionError::Limit(l)))
|
||||
.transpose()?,
|
||||
offset: query
|
||||
.offset
|
||||
.map(|o| i64::try_from(o).map_err(|_| QueryConversionError::Offset(o)))
|
||||
.transpose()?,
|
||||
};
|
||||
|
||||
let accounts = db::list(executor, query)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(decode)
|
||||
.collect::<Result<_, _>>()?;
|
||||
|
||||
Ok(accounts)
|
||||
}
|
||||
@@ -67,12 +66,14 @@ where
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(decode)
|
||||
.collect::<Result<Vec<_>, DecodeError>>()?;
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok(accounts
|
||||
let account_map = accounts
|
||||
.into_iter()
|
||||
.map(|account| (account.id, account))
|
||||
.collect())
|
||||
.collect();
|
||||
|
||||
Ok(account_map)
|
||||
}
|
||||
|
||||
pub async fn upsert<'e, E>(
|
||||
@@ -84,20 +85,22 @@ where
|
||||
{
|
||||
let account = db::upsert(executor, encode(account))
|
||||
.await?
|
||||
.try_map(decode)?;
|
||||
.try_map(decode)?
|
||||
.into();
|
||||
|
||||
Ok(account.into())
|
||||
Ok(account)
|
||||
}
|
||||
|
||||
pub async fn delete_by_id<'e, E>(executor: E, id: Uuid) -> Result<Delete, RepositoryError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
let deleted = db::delete_by_id(executor, id)
|
||||
let result = db::delete_by_id(executor, id)
|
||||
.await
|
||||
.map_err(classify_delete_error)?;
|
||||
.map_err(classify_delete_error)?
|
||||
.into();
|
||||
|
||||
Ok(deleted.into())
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn classify_delete_error(error: DatabaseError) -> RepositoryError {
|
||||
@@ -202,6 +205,7 @@ mod tests {
|
||||
#[test]
|
||||
fn round_trips_through_rows() {
|
||||
let account = decode(row()).unwrap();
|
||||
assert_eq!(decode(encode(account.clone())).unwrap(), account);
|
||||
let round_trip = decode(encode(account.clone())).unwrap();
|
||||
assert_eq!(round_trip, account);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,23 +27,22 @@ pub async fn list<'e, E>(
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
let transactions = db::list(
|
||||
executor,
|
||||
db::Query {
|
||||
limit: query
|
||||
.limit
|
||||
.map(|l| i64::try_from(l).map_err(|_| QueryConversionError::Limit(l)))
|
||||
.transpose()?,
|
||||
offset: query
|
||||
.offset
|
||||
.map(|o| i64::try_from(o).map_err(|_| QueryConversionError::Offset(o)))
|
||||
.transpose()?,
|
||||
},
|
||||
)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(decode)
|
||||
.collect::<Result<_, DecodeError>>()?;
|
||||
let query = db::Query {
|
||||
limit: query
|
||||
.limit
|
||||
.map(|l| i64::try_from(l).map_err(|_| QueryConversionError::Limit(l)))
|
||||
.transpose()?,
|
||||
offset: query
|
||||
.offset
|
||||
.map(|o| i64::try_from(o).map_err(|_| QueryConversionError::Offset(o)))
|
||||
.transpose()?,
|
||||
};
|
||||
|
||||
let transactions = db::list(executor, query)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(decode)
|
||||
.collect::<Result<_, DecodeError>>()?;
|
||||
|
||||
Ok(transactions)
|
||||
}
|
||||
@@ -70,9 +69,10 @@ where
|
||||
let transaction = db::upsert(executor, encode(transaction))
|
||||
.await
|
||||
.map_err(classify_upsert_error)?
|
||||
.try_map(decode)?;
|
||||
.try_map(decode)?
|
||||
.into();
|
||||
|
||||
Ok(transaction.into())
|
||||
Ok(transaction)
|
||||
}
|
||||
|
||||
fn classify_upsert_error(error: DatabaseError) -> RepositoryError {
|
||||
@@ -98,7 +98,9 @@ pub async fn delete_by_id<'e, E>(executor: E, id: Uuid) -> Result<Delete, Reposi
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
Ok(db::delete_by_id(executor, id).await?.into())
|
||||
let result = db::delete_by_id(executor, id).await?.into();
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn decode(row: RecurringTransactionRow) -> Result<RecurringTransaction, DecodeError> {
|
||||
@@ -238,6 +240,7 @@ mod tests {
|
||||
#[test]
|
||||
fn round_trips_through_rows() {
|
||||
let transaction = decode(row()).unwrap();
|
||||
assert_eq!(decode(encode(transaction.clone())).unwrap(), transaction);
|
||||
let round_trip = decode(encode(transaction.clone())).unwrap();
|
||||
assert_eq!(round_trip, transaction);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,9 +59,10 @@ where
|
||||
let transaction = db::upsert(executor, encode(transaction))
|
||||
.await
|
||||
.map_err(classify_upsert_error)?
|
||||
.try_map(decode)?;
|
||||
.try_map(decode)?
|
||||
.into();
|
||||
|
||||
Ok(transaction.into())
|
||||
Ok(transaction)
|
||||
}
|
||||
|
||||
fn classify_upsert_error(error: DatabaseError) -> RepositoryError {
|
||||
@@ -82,7 +83,9 @@ pub async fn delete_by_id<'e, E>(executor: E, id: Uuid) -> Result<Delete, Reposi
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
Ok(db::delete_by_id(executor, id).await?.into())
|
||||
let result = db::delete_by_id(executor, id).await?.into();
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn decode(row: TransactionRow) -> Result<Transaction, DecodeError> {
|
||||
@@ -180,6 +183,7 @@ mod tests {
|
||||
#[test]
|
||||
fn round_trips_through_rows() {
|
||||
let transaction = decode(row()).unwrap();
|
||||
assert_eq!(decode(encode(transaction.clone())).unwrap(), transaction);
|
||||
let round_trip = decode(encode(transaction.clone())).unwrap();
|
||||
assert_eq!(round_trip, transaction);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use super::{
|
||||
use crate::{
|
||||
database::{Constraint, DatabaseError, dtos::UserAppSecretRow, user_app_secrets as db},
|
||||
domain::UserAppSecret,
|
||||
repository::DecodeError,
|
||||
};
|
||||
|
||||
pub struct Query {
|
||||
@@ -18,26 +19,25 @@ pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<UserAppSecret>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
Ok(db::list(
|
||||
executor,
|
||||
db::Query {
|
||||
app_id: query.app_id,
|
||||
limit: query
|
||||
.limit
|
||||
.map(|limit| i64::try_from(limit).map_err(|_| QueryConversionError::Limit(limit)))
|
||||
.transpose()?,
|
||||
offset: query
|
||||
.offset
|
||||
.map(|offset| {
|
||||
i64::try_from(offset).map_err(|_| QueryConversionError::Offset(offset))
|
||||
})
|
||||
.transpose()?,
|
||||
},
|
||||
)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(decode)
|
||||
.collect())
|
||||
let query = db::Query {
|
||||
app_id: query.app_id,
|
||||
limit: query
|
||||
.limit
|
||||
.map(|limit| i64::try_from(limit).map_err(|_| QueryConversionError::Limit(limit)))
|
||||
.transpose()?,
|
||||
offset: query
|
||||
.offset
|
||||
.map(|offset| i64::try_from(offset).map_err(|_| QueryConversionError::Offset(offset)))
|
||||
.transpose()?,
|
||||
};
|
||||
|
||||
let secrets = db::list(executor, query)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(decode)
|
||||
.collect::<Result<Vec<_>, DecodeError>>()?;
|
||||
|
||||
Ok(secrets)
|
||||
}
|
||||
|
||||
pub async fn get_by_id<'e, E>(
|
||||
@@ -48,7 +48,12 @@ pub async fn get_by_id<'e, E>(
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
Ok(db::get_by_id(executor, app_id, id).await?.map(decode))
|
||||
let secret = db::get_by_id(executor, app_id, id)
|
||||
.await?
|
||||
.map(decode)
|
||||
.transpose()?;
|
||||
|
||||
Ok(secret)
|
||||
}
|
||||
|
||||
pub async fn upsert<'e, E>(
|
||||
@@ -58,14 +63,13 @@ pub async fn upsert<'e, E>(
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
let upsert = db::upsert(executor, encode(secret))
|
||||
let secret = db::upsert(executor, encode(secret))
|
||||
.await
|
||||
.map_err(classify_upsert_error)?;
|
||||
.map_err(classify_upsert_error)?
|
||||
.try_map(decode)?
|
||||
.into();
|
||||
|
||||
Ok(match upsert {
|
||||
crate::database::dtos::Upsert::Created(row) => Upsert::Created(decode(row)),
|
||||
crate::database::dtos::Upsert::Updated(row) => Upsert::Updated(decode(row)),
|
||||
})
|
||||
Ok(secret)
|
||||
}
|
||||
|
||||
fn classify_upsert_error(error: DatabaseError) -> RepositoryError {
|
||||
@@ -90,7 +94,9 @@ pub async fn verify<'e, E>(
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
Ok(db::verify(executor, app_id, secret_hash).await?)
|
||||
let result = db::verify(executor, app_id, secret_hash).await?;
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
pub async fn delete_by_id<'e, E>(
|
||||
@@ -101,17 +107,19 @@ pub async fn delete_by_id<'e, E>(
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
Ok(db::delete_by_id(executor, app_id, id).await?.into())
|
||||
let result = db::delete_by_id(executor, app_id, id).await?.into();
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn decode(row: UserAppSecretRow) -> UserAppSecret {
|
||||
UserAppSecret {
|
||||
fn decode(row: UserAppSecretRow) -> Result<UserAppSecret, DecodeError> {
|
||||
Ok(UserAppSecret {
|
||||
id: row.id,
|
||||
app_id: row.app_id,
|
||||
secret_hash: row.secret_hash,
|
||||
expires_at: row.expires_at,
|
||||
created_at: row.created_at,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn encode(secret: UserAppSecret) -> UserAppSecretRow {
|
||||
@@ -168,12 +176,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn round_trips_through_rows() {
|
||||
let secret = decode(row());
|
||||
let round_trip = decode(encode(secret.clone()));
|
||||
|
||||
assert_eq!(round_trip.id, secret.id);
|
||||
assert_eq!(round_trip.app_id, secret.app_id);
|
||||
assert_eq!(round_trip.secret_hash, secret.secret_hash);
|
||||
assert_eq!(round_trip.expires_at, secret.expires_at);
|
||||
let secret = decode(row()).unwrap();
|
||||
let round_trip = decode(encode(secret.clone())).unwrap();
|
||||
assert_eq!(round_trip, secret);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ use super::{QueryConversionError, RepositoryError, dtos::Upsert};
|
||||
use crate::{
|
||||
database::{Constraint, DatabaseError, dtos::UserAppRow, user_apps as db},
|
||||
domain::UserApp,
|
||||
repository::DecodeError,
|
||||
};
|
||||
|
||||
pub struct Query {
|
||||
@@ -16,26 +17,25 @@ pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<UserApp>, Repo
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
Ok(db::list(
|
||||
executor,
|
||||
db::Query {
|
||||
user_id: query.user_id,
|
||||
limit: query
|
||||
.limit
|
||||
.map(|limit| i64::try_from(limit).map_err(|_| QueryConversionError::Limit(limit)))
|
||||
.transpose()?,
|
||||
offset: query
|
||||
.offset
|
||||
.map(|offset| {
|
||||
i64::try_from(offset).map_err(|_| QueryConversionError::Offset(offset))
|
||||
})
|
||||
.transpose()?,
|
||||
},
|
||||
)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(decode)
|
||||
.collect())
|
||||
let query = db::Query {
|
||||
user_id: query.user_id,
|
||||
limit: query
|
||||
.limit
|
||||
.map(|limit| i64::try_from(limit).map_err(|_| QueryConversionError::Limit(limit)))
|
||||
.transpose()?,
|
||||
offset: query
|
||||
.offset
|
||||
.map(|offset| i64::try_from(offset).map_err(|_| QueryConversionError::Offset(offset)))
|
||||
.transpose()?,
|
||||
};
|
||||
|
||||
let apps = db::list(executor, query)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(decode)
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
Ok(apps)
|
||||
}
|
||||
|
||||
pub async fn get_by_id<'e, E>(
|
||||
@@ -46,21 +46,25 @@ pub async fn get_by_id<'e, E>(
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
Ok(db::get_by_id(executor, user_id, id).await?.map(decode))
|
||||
let app = db::get_by_id(executor, user_id, id)
|
||||
.await?
|
||||
.map(decode)
|
||||
.transpose()?;
|
||||
|
||||
Ok(app)
|
||||
}
|
||||
|
||||
pub async fn upsert<'e, E>(executor: E, app: UserApp) -> Result<Upsert<UserApp>, RepositoryError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
let upsert = db::upsert(executor, encode(app))
|
||||
let app = db::upsert(executor, encode(app))
|
||||
.await
|
||||
.map_err(classify_upsert_error)?;
|
||||
.map_err(classify_upsert_error)?
|
||||
.try_map(decode)?
|
||||
.into();
|
||||
|
||||
Ok(match upsert {
|
||||
crate::database::dtos::Upsert::Created(row) => Upsert::Created(decode(row)),
|
||||
crate::database::dtos::Upsert::Updated(row) => Upsert::Updated(decode(row)),
|
||||
})
|
||||
Ok(app)
|
||||
}
|
||||
|
||||
fn classify_upsert_error(error: DatabaseError) -> RepositoryError {
|
||||
@@ -85,14 +89,16 @@ pub async fn delete_by_id<'e, E>(
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
Ok(db::delete_by_id(executor, user_id, id).await?.into())
|
||||
let result = db::delete_by_id(executor, user_id, id).await?.into();
|
||||
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn decode(row: UserAppRow) -> UserApp {
|
||||
UserApp {
|
||||
fn decode(row: UserAppRow) -> Result<UserApp, DecodeError> {
|
||||
Ok(UserApp {
|
||||
id: row.id,
|
||||
user_id: row.user_id,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn encode(app: UserApp) -> UserAppRow {
|
||||
@@ -143,7 +149,7 @@ mod tests {
|
||||
fn decodes_valid_rows() {
|
||||
let row = row();
|
||||
let (id, user_id) = (row.id, row.user_id);
|
||||
let app = decode(row);
|
||||
let app = decode(row).unwrap();
|
||||
|
||||
assert_eq!(app.id, id);
|
||||
assert_eq!(app.user_id, user_id);
|
||||
@@ -151,7 +157,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn round_trips_through_rows() {
|
||||
let app = decode(row());
|
||||
assert_eq!(decode(encode(app.clone())), app);
|
||||
let app = decode(row()).unwrap();
|
||||
let round_trip = decode(encode(app.clone())).unwrap();
|
||||
assert_eq!(round_trip, app);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,23 +18,22 @@ pub async fn list<'e, E>(executor: E, query: Query) -> Result<Vec<User>, Reposit
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
let users = db::list(
|
||||
executor,
|
||||
db::Query {
|
||||
limit: query
|
||||
.limit
|
||||
.map(|l| i64::try_from(l).map_err(|_| QueryConversionError::Limit(l)))
|
||||
.transpose()?,
|
||||
offset: query
|
||||
.offset
|
||||
.map(|o| i64::try_from(o).map_err(|_| QueryConversionError::Offset(o)))
|
||||
.transpose()?,
|
||||
},
|
||||
)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(decode)
|
||||
.collect::<Result<_, DecodeError>>()?;
|
||||
let query = db::Query {
|
||||
limit: query
|
||||
.limit
|
||||
.map(|l| i64::try_from(l).map_err(|_| QueryConversionError::Limit(l)))
|
||||
.transpose()?,
|
||||
offset: query
|
||||
.offset
|
||||
.map(|o| i64::try_from(o).map_err(|_| QueryConversionError::Offset(o)))
|
||||
.transpose()?,
|
||||
};
|
||||
|
||||
let users = db::list(executor, query)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(decode)
|
||||
.collect::<Result<_, DecodeError>>()?;
|
||||
|
||||
Ok(users)
|
||||
}
|
||||
@@ -52,20 +51,24 @@ pub async fn upsert<'e, E>(executor: E, user: User) -> Result<Upsert<User>, Repo
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
let user = db::upsert(executor, encode(user)).await?.try_map(decode)?;
|
||||
let user = db::upsert(executor, encode(user))
|
||||
.await?
|
||||
.try_map(decode)?
|
||||
.into();
|
||||
|
||||
Ok(user.into())
|
||||
Ok(user)
|
||||
}
|
||||
|
||||
pub async fn delete_by_id<'e, E>(executor: E, id: Uuid) -> Result<Delete, RepositoryError>
|
||||
where
|
||||
E: sqlx::Executor<'e, Database = sqlx::Postgres>,
|
||||
{
|
||||
let deleted = db::delete_by_id(executor, id)
|
||||
let result = db::delete_by_id(executor, id)
|
||||
.await
|
||||
.map_err(classify_delete_error)?;
|
||||
.map_err(classify_delete_error)?
|
||||
.into();
|
||||
|
||||
Ok(deleted.into())
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn classify_delete_error(error: DatabaseError) -> RepositoryError {
|
||||
|
||||
@@ -39,18 +39,17 @@ async fn list_accounts(
|
||||
State(pool): State<PgPool>,
|
||||
Query(query): Query<QueryParams>,
|
||||
) -> Result<Json<Vec<AccountResponse>>, AppError> {
|
||||
let accounts = repository::accounts::list(
|
||||
&pool,
|
||||
repository::accounts::Query {
|
||||
name: query.name,
|
||||
limit: Some(query.limit.unwrap_or(20)),
|
||||
offset: query.offset,
|
||||
},
|
||||
)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(AccountResponse::from)
|
||||
.collect();
|
||||
let query = repository::accounts::Query {
|
||||
name: query.name,
|
||||
limit: Some(query.limit.unwrap_or(20)),
|
||||
offset: query.offset,
|
||||
};
|
||||
|
||||
let accounts = repository::accounts::list(&pool, query)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(AccountResponse::from)
|
||||
.collect();
|
||||
|
||||
Ok(Json(accounts))
|
||||
}
|
||||
|
||||
@@ -43,18 +43,17 @@ async fn list_user_app_secrets(
|
||||
Path((user_id, app_id)): Path<(Uuid, Uuid)>,
|
||||
Query(query): Query<QueryParams>,
|
||||
) -> Result<Json<Vec<UserAppSecretResponse>>, AppError> {
|
||||
let secrets = repository::user_app_secrets::list(
|
||||
&pool,
|
||||
repository::user_app_secrets::Query {
|
||||
app_id,
|
||||
limit: Some(query.limit.unwrap_or(20)),
|
||||
offset: query.offset,
|
||||
},
|
||||
)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(UserAppSecretResponse::from)
|
||||
.collect();
|
||||
let query = repository::user_app_secrets::Query {
|
||||
app_id,
|
||||
limit: Some(query.limit.unwrap_or(20)),
|
||||
offset: query.offset,
|
||||
};
|
||||
|
||||
let secrets = repository::user_app_secrets::list(&pool, query)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(UserAppSecretResponse::from)
|
||||
.collect();
|
||||
|
||||
Ok(Json(secrets))
|
||||
}
|
||||
|
||||
@@ -39,18 +39,17 @@ async fn list_user_apps(
|
||||
Path(user_id): Path<Uuid>,
|
||||
Query(query): Query<QueryParams>,
|
||||
) -> Result<Json<Vec<UserAppResponse>>, AppError> {
|
||||
let apps = repository::user_apps::list(
|
||||
&pool,
|
||||
repository::user_apps::Query {
|
||||
user_id,
|
||||
limit: Some(query.limit.unwrap_or(20)),
|
||||
offset: query.offset,
|
||||
},
|
||||
)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(UserAppResponse::from)
|
||||
.collect();
|
||||
let query = repository::user_apps::Query {
|
||||
user_id,
|
||||
limit: Some(query.limit.unwrap_or(20)),
|
||||
offset: query.offset,
|
||||
};
|
||||
|
||||
let apps = repository::user_apps::list(&pool, query)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(UserAppResponse::from)
|
||||
.collect();
|
||||
|
||||
Ok(Json(apps))
|
||||
}
|
||||
|
||||
+10
-11
@@ -38,17 +38,16 @@ async fn list_users(
|
||||
State(pool): State<PgPool>,
|
||||
Query(query): Query<QueryParams>,
|
||||
) -> Result<Json<Vec<UserResponse>>, AppError> {
|
||||
let users = repository::users::list(
|
||||
&pool,
|
||||
repository::users::Query {
|
||||
limit: Some(query.limit.unwrap_or(20)),
|
||||
offset: query.offset,
|
||||
},
|
||||
)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(UserResponse::from)
|
||||
.collect();
|
||||
let query = repository::users::Query {
|
||||
limit: Some(query.limit.unwrap_or(20)),
|
||||
offset: query.offset,
|
||||
};
|
||||
|
||||
let users = repository::users::list(&pool, query)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(UserResponse::from)
|
||||
.collect();
|
||||
|
||||
Ok(Json(users))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user