mirror of
https://github.com/house-of-vanity/OutFleet.git
synced 2025-10-28 02:39:09 +00:00
Added usermanagement in TG admin
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
use crate::{
|
||||
database::{entities::inbound_template, repository::InboundTemplateRepository},
|
||||
web::AppState,
|
||||
};
|
||||
use axum::{
|
||||
extract::{Path, State},
|
||||
http::StatusCode,
|
||||
@@ -5,26 +9,17 @@ use axum::{
|
||||
Json as JsonExtractor,
|
||||
};
|
||||
use uuid::Uuid;
|
||||
use crate::{
|
||||
database::{
|
||||
entities::inbound_template,
|
||||
repository::InboundTemplateRepository,
|
||||
},
|
||||
web::AppState,
|
||||
};
|
||||
|
||||
/// List all inbound templates
|
||||
pub async fn list_templates(
|
||||
State(app_state): State<AppState>,
|
||||
) -> Result<Json<Vec<inbound_template::InboundTemplateResponse>>, StatusCode> {
|
||||
let repo = InboundTemplateRepository::new(app_state.db.connection().clone());
|
||||
|
||||
|
||||
match repo.find_all().await {
|
||||
Ok(templates) => {
|
||||
let responses: Vec<inbound_template::InboundTemplateResponse> = templates
|
||||
.into_iter()
|
||||
.map(|t| t.into())
|
||||
.collect();
|
||||
let responses: Vec<inbound_template::InboundTemplateResponse> =
|
||||
templates.into_iter().map(|t| t.into()).collect();
|
||||
Ok(Json(responses))
|
||||
}
|
||||
Err(_) => Err(StatusCode::INTERNAL_SERVER_ERROR),
|
||||
@@ -37,7 +32,7 @@ pub async fn get_template(
|
||||
Path(id): Path<Uuid>,
|
||||
) -> Result<Json<inbound_template::InboundTemplateResponse>, StatusCode> {
|
||||
let repo = InboundTemplateRepository::new(app_state.db.connection().clone());
|
||||
|
||||
|
||||
match repo.find_by_id(id).await {
|
||||
Ok(Some(template)) => Ok(Json(template.into())),
|
||||
Ok(None) => Err(StatusCode::NOT_FOUND),
|
||||
@@ -52,7 +47,7 @@ pub async fn create_template(
|
||||
) -> Result<Json<inbound_template::InboundTemplateResponse>, StatusCode> {
|
||||
tracing::info!("Creating template: {:?}", template_data);
|
||||
let repo = InboundTemplateRepository::new(app_state.db.connection().clone());
|
||||
|
||||
|
||||
match repo.create(template_data).await {
|
||||
Ok(template) => Ok(Json(template.into())),
|
||||
Err(_) => Err(StatusCode::INTERNAL_SERVER_ERROR),
|
||||
@@ -66,7 +61,7 @@ pub async fn update_template(
|
||||
JsonExtractor(template_data): JsonExtractor<inbound_template::UpdateInboundTemplateDto>,
|
||||
) -> Result<Json<inbound_template::InboundTemplateResponse>, StatusCode> {
|
||||
let repo = InboundTemplateRepository::new(app_state.db.connection().clone());
|
||||
|
||||
|
||||
match repo.update(id, template_data).await {
|
||||
Ok(template) => Ok(Json(template.into())),
|
||||
Err(_) => Err(StatusCode::INTERNAL_SERVER_ERROR),
|
||||
@@ -79,10 +74,10 @@ pub async fn delete_template(
|
||||
Path(id): Path<Uuid>,
|
||||
) -> Result<StatusCode, StatusCode> {
|
||||
let repo = InboundTemplateRepository::new(app_state.db.connection().clone());
|
||||
|
||||
|
||||
match repo.delete(id).await {
|
||||
Ok(true) => Ok(StatusCode::NO_CONTENT),
|
||||
Ok(false) => Err(StatusCode::NOT_FOUND),
|
||||
Err(_) => Err(StatusCode::INTERNAL_SERVER_ERROR),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user