-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
206 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,60 @@ | ||
use super::{create, delete, read, update, HookExt, PublicExt, RequestExt}; | ||
use crate::server::{AppState, AppStores}; | ||
use axum::{ | ||
routing::{patch, post}, | ||
Router, | ||
}; | ||
use chrono::Utc; | ||
use entities::{ | ||
event_access::EventAccess, prefix::IdPrefix, record_metadata::RecordMetadata, task::Task, Id, | ||
}; | ||
use fake::Dummy; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::Value; | ||
use std::sync::Arc; | ||
|
||
pub fn get_router() -> Router<Arc<AppState>> { | ||
Router::new() | ||
.route( | ||
"/", | ||
post(create::<CreateRequest, Task>).get(read::<CreateRequest, Task>), | ||
) | ||
.route( | ||
"/:id", | ||
patch(update::<CreateRequest, Task>).delete(delete::<CreateRequest, Task>), | ||
) | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Dummy)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct CreateRequest { | ||
pub start_time: i64, | ||
pub endpoint: String, | ||
pub payload: Value, | ||
} | ||
|
||
impl RequestExt for CreateRequest { | ||
type Output = Task; | ||
|
||
fn from(&self) -> Option<Task> { | ||
Some(Task { | ||
id: Id::now(IdPrefix::Task), | ||
start_time: Utc::now().timestamp_millis(), | ||
end_time: None, | ||
payload: self.payload.clone(), | ||
endpoint: self.endpoint.clone(), | ||
status: None, | ||
metadata: RecordMetadata::default(), | ||
}) | ||
} | ||
|
||
fn get_store(stores: AppStores) -> entities::MongoStore<Self::Output> { | ||
stores.tasks | ||
} | ||
|
||
fn access(&self, _: Arc<EventAccess>) -> Option<Self::Output> { | ||
self.from() | ||
} | ||
} | ||
impl HookExt<Task> for CreateRequest {} | ||
impl PublicExt<Task> for CreateRequest {} |
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
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,19 @@ | ||
use crate::{record_metadata::RecordMetadata, Id}; | ||
use http::StatusCode; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_json::Value; | ||
|
||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Task { | ||
#[serde(rename = "_id")] | ||
pub id: Id, | ||
pub start_time: i64, | ||
pub end_time: Option<i64>, | ||
pub payload: Value, | ||
pub endpoint: String, | ||
#[serde(with = "http_serde_ext_ios::status_code::option")] | ||
pub status: Option<StatusCode>, | ||
#[serde(flatten)] | ||
pub metadata: RecordMetadata, | ||
} |
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
Oops, something went wrong.