remove OIDC/Postgres, replace ApiError w/ AppError, move params to api-types
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
use axum::Json;
|
||||
use axum::extract::{Query, State};
|
||||
use serde::Deserialize;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use api_types::{ActivityEventResponse, SettingsResponse};
|
||||
use api_types::{ActivityEventResponse, ActivityLogParams, SettingsResponse};
|
||||
use application::admin::{GetActivityLogQuery, GetSettingsQuery, UpdateSettingsCommand};
|
||||
|
||||
use crate::errors::ApiError;
|
||||
use crate::errors::AppError;
|
||||
use crate::extractors::AdminUser;
|
||||
use crate::state::AppState;
|
||||
|
||||
@@ -15,7 +14,7 @@ const DEFAULT_ACTIVITY_LIMIT: u32 = 50;
|
||||
pub async fn get_settings(
|
||||
State(state): State<AppState>,
|
||||
AdminUser(_user): AdminUser,
|
||||
) -> Result<Json<SettingsResponse>, ApiError> {
|
||||
) -> Result<Json<SettingsResponse>, AppError> {
|
||||
let pairs =
|
||||
application::admin::get_settings::execute(&state.admin_deps, GetSettingsQuery).await?;
|
||||
let settings: HashMap<String, String> = pairs.into_iter().collect();
|
||||
@@ -26,7 +25,7 @@ pub async fn update_settings(
|
||||
State(state): State<AppState>,
|
||||
AdminUser(_user): AdminUser,
|
||||
Json(body): Json<HashMap<String, String>>,
|
||||
) -> Result<Json<SettingsResponse>, ApiError> {
|
||||
) -> Result<Json<SettingsResponse>, AppError> {
|
||||
let settings_vec: Vec<(String, String)> = body.into_iter().collect();
|
||||
let cmd = UpdateSettingsCommand {
|
||||
settings: settings_vec,
|
||||
@@ -39,16 +38,11 @@ pub async fn update_settings(
|
||||
Ok(Json(SettingsResponse { settings }))
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ActivityLogParams {
|
||||
pub limit: Option<u32>,
|
||||
}
|
||||
|
||||
pub async fn get_activity_log(
|
||||
State(state): State<AppState>,
|
||||
AdminUser(_user): AdminUser,
|
||||
Query(params): Query<ActivityLogParams>,
|
||||
) -> Result<Json<Vec<ActivityEventResponse>>, ApiError> {
|
||||
) -> Result<Json<Vec<ActivityEventResponse>>, AppError> {
|
||||
let query = GetActivityLogQuery {
|
||||
limit: params.limit.unwrap_or(DEFAULT_ACTIVITY_LIMIT),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user