feat: load task to database
This commit is contained in:
parent
1e3c235b78
commit
7be435332c
5 changed files with 89 additions and 38 deletions
|
|
@ -1,8 +1,9 @@
|
|||
use chrono::{DateTime, Local};
|
||||
use serde::{Deserialize, Deserializer, de};
|
||||
use serde::{Deserialize, Deserializer, de, Serialize};
|
||||
use serde_json::Value;
|
||||
use crate::sql::TaskPayload;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
pub struct DocumentPayload {
|
||||
title: String,
|
||||
summary: Option<String>,
|
||||
|
|
@ -13,20 +14,10 @@ pub struct DocumentPayload {
|
|||
location: String,
|
||||
}
|
||||
|
||||
fn str_to_int<'de, D: Deserializer<'de>>(deserializer: D) -> Result<u64, D::Error> {
|
||||
Ok(match Value::deserialize(deserializer)? {
|
||||
Value::String(s) => s.parse().map_err(de::Error::custom)?,
|
||||
Value::Number(num) => num.as_u64().ok_or(de::Error::custom("Invalid number"))?,
|
||||
_ => return Err(de::Error::custom("wrong type")),
|
||||
})
|
||||
}
|
||||
|
||||
fn str_to_bool<'de, D: Deserializer<'de>>(deserializer: D) -> Result<bool, D::Error> {
|
||||
Ok(match Value::deserialize(deserializer)? {
|
||||
Value::String(s) => s.parse().map_err(de::Error::custom)?,
|
||||
Value::Bool(b) => b,
|
||||
_ => return Err(de::Error::custom("wrong type")),
|
||||
})
|
||||
impl TaskPayload for DocumentPayload {
|
||||
fn get_key(&self) -> String {
|
||||
self.url.clone()
|
||||
}
|
||||
}
|
||||
|
||||
fn single_or_vec<'de, D: Deserializer<'de>>(deserializer: D) -> Result<Vec<String>, D::Error> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue