-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This reverts commit 8303dee.
- Loading branch information
Showing
41 changed files
with
1,172 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use axum::extract::{Path, Query}; | ||
use axum::http::header::CONTENT_RANGE; | ||
use axum::http::{HeaderMap, StatusCode}; | ||
use axum::{Extension, Json}; | ||
use notifico_core::http::admin::{ListQueryParams, PaginatedResult}; | ||
use notifico_core::pipeline::storage::PipelineStorage; | ||
use notifico_core::pipeline::Event; | ||
use serde::Deserialize; | ||
use serde_json::{json, Value}; | ||
use std::sync::Arc; | ||
use uuid::Uuid; | ||
|
||
pub async fn list_events( | ||
Query(params): Query<ListQueryParams>, | ||
Extension(pipeline_storage): Extension<Arc<dyn PipelineStorage>>, | ||
) -> (HeaderMap, Json<Vec<Event>>) { | ||
let PaginatedResult { items, total_count } = | ||
pipeline_storage.list_events(params).await.unwrap(); | ||
|
||
let mut headers = HeaderMap::new(); | ||
headers.insert(CONTENT_RANGE, total_count.into()); | ||
|
||
(headers, Json(items)) | ||
} | ||
|
||
pub async fn get_event( | ||
Path((id,)): Path<(Uuid,)>, | ||
Extension(pipeline_storage): Extension<Arc<dyn PipelineStorage>>, | ||
) -> (StatusCode, Json<Option<Event>>) { | ||
let result = pipeline_storage.get_event_by_id(id).await.unwrap(); | ||
|
||
let Some(result) = result else { | ||
return (StatusCode::NOT_FOUND, Json(None)); | ||
}; | ||
(StatusCode::OK, Json(Some(result))) | ||
} | ||
|
||
#[derive(Deserialize)] | ||
pub struct EventCreate { | ||
project_id: Uuid, | ||
name: String, | ||
} | ||
|
||
pub async fn create_event( | ||
Extension(pipeline_storage): Extension<Arc<dyn PipelineStorage>>, | ||
Json(create): Json<EventCreate>, | ||
) -> (StatusCode, Json<Value>) { | ||
let result = pipeline_storage | ||
.create_event(create.project_id, &create.name) | ||
.await | ||
.unwrap(); | ||
|
||
( | ||
StatusCode::CREATED, | ||
Json(serde_json::to_value(result).unwrap()), | ||
) | ||
} | ||
|
||
#[derive(Deserialize)] | ||
pub struct EventUpdate { | ||
name: String, | ||
} | ||
|
||
pub async fn update_event( | ||
Extension(pipeline_storage): Extension<Arc<dyn PipelineStorage>>, | ||
Path((id,)): Path<(Uuid,)>, | ||
Json(update): Json<EventUpdate>, | ||
) -> (StatusCode, Json<Value>) { | ||
let result = pipeline_storage | ||
.update_event(id, &update.name) | ||
.await | ||
.unwrap(); | ||
|
||
( | ||
StatusCode::CREATED, | ||
Json(serde_json::to_value(result).unwrap()), | ||
) | ||
} | ||
|
||
pub async fn delete_event( | ||
Extension(pipeline_storage): Extension<Arc<dyn PipelineStorage>>, | ||
Path((id,)): Path<(Uuid,)>, | ||
) -> (StatusCode, Json<Value>) { | ||
pipeline_storage.delete_event(id).await.unwrap(); | ||
|
||
(StatusCode::NO_CONTENT, Json(json!({}))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use crate::http::admin::project::ProjectUpdate; | ||
use axum::extract::{Path, Query}; | ||
use axum::http::header::CONTENT_RANGE; | ||
use axum::http::{HeaderMap, StatusCode}; | ||
use axum::{Extension, Json}; | ||
use notifico_core::http::admin::{ListQueryParams, PaginatedResult}; | ||
use notifico_core::pipeline::storage::{PipelineResult, PipelineStorage}; | ||
use notifico_core::step::SerializedStep; | ||
use serde::Serialize; | ||
use serde_json::Value; | ||
use std::sync::Arc; | ||
use uuid::Uuid; | ||
|
||
#[derive(Clone, Serialize)] | ||
pub struct PipelineItem { | ||
pub id: Uuid, | ||
pub project_id: Uuid, | ||
pub event_ids: Vec<Uuid>, | ||
pub steps: Vec<SerializedStep>, | ||
pub channel: String, | ||
} | ||
|
||
impl From<PipelineResult> for PipelineItem { | ||
fn from(value: PipelineResult) -> Self { | ||
Self { | ||
id: value.pipeline.id, | ||
project_id: value.pipeline.project_id, | ||
steps: value.pipeline.steps.clone(), | ||
channel: value.pipeline.channel, | ||
|
||
event_ids: value.event_ids, | ||
} | ||
} | ||
} | ||
|
||
pub async fn list_pipelines( | ||
Query(params): Query<ListQueryParams>, | ||
Extension(pipeline_storage): Extension<Arc<dyn PipelineStorage>>, | ||
) -> (HeaderMap, Json<Vec<PipelineItem>>) { | ||
let PaginatedResult { items, total_count } = | ||
pipeline_storage.list_pipelines(params).await.unwrap(); | ||
|
||
let pipelines = items.into_iter().map(PipelineItem::from).collect(); | ||
|
||
let mut headers = HeaderMap::new(); | ||
headers.insert(CONTENT_RANGE, total_count.into()); | ||
|
||
(headers, Json(pipelines)) | ||
} | ||
|
||
pub async fn get_pipeline( | ||
Path((id,)): Path<(Uuid,)>, | ||
Extension(pipeline_storage): Extension<Arc<dyn PipelineStorage>>, | ||
) -> (StatusCode, Json<Option<PipelineItem>>) { | ||
let result = pipeline_storage | ||
.get_pipeline_by_id(id) | ||
.await | ||
.unwrap() | ||
.map(PipelineItem::from); | ||
|
||
let Some(result) = result else { | ||
return (StatusCode::NOT_FOUND, Json(None)); | ||
}; | ||
(StatusCode::OK, Json(Some(result))) | ||
} | ||
|
||
pub async fn update_pipeline( | ||
Extension(pipeline_storage): Extension<Arc<dyn PipelineStorage>>, | ||
Path((id,)): Path<(Uuid,)>, | ||
Json(update): Json<ProjectUpdate>, | ||
) -> (StatusCode, Json<Value>) { | ||
let result = pipeline_storage.update(id, &update.name).await.unwrap(); | ||
|
||
( | ||
StatusCode::ACCEPTED, | ||
Json(serde_json::to_value(result).unwrap()), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use axum::extract::{Path, Query}; | ||
use axum::http::header::CONTENT_RANGE; | ||
use axum::http::{HeaderMap, StatusCode}; | ||
use axum::{Extension, Json}; | ||
use notifico_core::http::admin::{ListQueryParams, PaginatedResult}; | ||
use notifico_project::{Project, ProjectController}; | ||
use serde::Deserialize; | ||
use serde_json::{json, Value}; | ||
use std::sync::Arc; | ||
use uuid::Uuid; | ||
|
||
pub async fn list_projects( | ||
Query(params): Query<ListQueryParams>, | ||
Extension(controller): Extension<Arc<ProjectController>>, | ||
) -> (HeaderMap, Json<Vec<Project>>) { | ||
let PaginatedResult { items, total_count } = controller.list(params).await.unwrap(); | ||
|
||
let mut headers = HeaderMap::new(); | ||
headers.insert(CONTENT_RANGE, total_count.into()); | ||
|
||
(headers, Json(items)) | ||
} | ||
|
||
pub async fn get_project( | ||
Path((id,)): Path<(Uuid,)>, | ||
Extension(controller): Extension<Arc<ProjectController>>, | ||
) -> (StatusCode, Json<Option<Project>>) { | ||
let result = controller.get_by_id(id).await.unwrap(); | ||
|
||
let Some(result) = result else { | ||
return (StatusCode::NOT_FOUND, Json(None)); | ||
}; | ||
(StatusCode::OK, Json(Some(result))) | ||
} | ||
|
||
#[derive(Deserialize)] | ||
pub struct ProjectUpdate { | ||
name: String, | ||
} | ||
|
||
pub async fn create_project( | ||
Extension(controller): Extension<Arc<ProjectController>>, | ||
Json(update): Json<ProjectUpdate>, | ||
) -> (StatusCode, Json<Value>) { | ||
let result = controller.create(&update.name).await.unwrap(); | ||
|
||
( | ||
StatusCode::CREATED, | ||
Json(serde_json::to_value(result).unwrap()), | ||
) | ||
} | ||
|
||
pub async fn update_project( | ||
Extension(controller): Extension<Arc<ProjectController>>, | ||
Path((id,)): Path<(Uuid,)>, | ||
Json(update): Json<ProjectUpdate>, | ||
) -> (StatusCode, Json<Value>) { | ||
let result = controller.update(id, &update.name).await.unwrap(); | ||
|
||
( | ||
StatusCode::ACCEPTED, | ||
Json(serde_json::to_value(result).unwrap()), | ||
) | ||
} | ||
|
||
pub async fn delete_project( | ||
Extension(controller): Extension<Arc<ProjectController>>, | ||
Path((id,)): Path<(Uuid,)>, | ||
) -> (StatusCode, Json<Value>) { | ||
controller.delete(id).await.unwrap(); | ||
|
||
(StatusCode::NO_CONTENT, Json(json!({}))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
pub mod credentials; | ||
pub mod pipelines; |
Oops, something went wrong.