Update Datetime handling in API and DB layers
Changed the handling of start, stop, and update timestamp fields in ReportRowInnerTimeEntry data structure from strings to DateTime objects in the API layer. Also updated the data persisting in DB layer to use these new datetime objects and introduced additional columns for server_updated_at, server_deleted_at and tags.
This commit is contained in:
parent
ce60eaf310
commit
73b3e2cb96
31
src/db.rs
31
src/db.rs
@ -12,9 +12,13 @@ impl ReportRow {
|
||||
toggl_id: Set(inner.id as i64),
|
||||
description: Set(self.description.clone()),
|
||||
project_id: Set(self.project_id.map(|id| id as i64)),
|
||||
start: Set(chrono::DateTime::parse_from_rfc3339(&inner.start).unwrap()),
|
||||
stop: Set(chrono::DateTime::parse_from_rfc3339(&inner.stop).unwrap()),
|
||||
start: Set(inner.start.fixed_offset()),
|
||||
stop: Set(inner.stop.fixed_offset()),
|
||||
raw_json: Set(serde_json::to_value(inner).unwrap()),
|
||||
server_deleted_at: NotSet,
|
||||
server_updated_at: Set(inner.at.fixed_offset()),
|
||||
// TODO: tags on report row import, need to track in separate table
|
||||
tags: NotSet
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
@ -27,6 +31,9 @@ impl ReportRow {
|
||||
time_entry::Column::Start,
|
||||
time_entry::Column::Stop,
|
||||
time_entry::Column::RawJson,
|
||||
time_entry::Column::ServerUpdatedAt,
|
||||
time_entry::Column::ServerDeletedAt,
|
||||
// time_entry::Column::Tags, TODO add tags to conflict resolution when implemented
|
||||
])
|
||||
.to_owned()
|
||||
}
|
||||
@ -39,11 +46,29 @@ impl TimeEntry {
|
||||
toggl_id: Set(self.id),
|
||||
description: Set(self.description.clone()),
|
||||
project_id: Set(self.project_id),
|
||||
start: Set(self.start.clone().fixed_offset()),
|
||||
start: Set(self.start.fixed_offset()),
|
||||
stop: Set(self.stop.unwrap().fixed_offset()),
|
||||
raw_json: Set(serde_json::to_value(self).unwrap()),
|
||||
server_updated_at: Set(self.at.fixed_offset()),
|
||||
server_deleted_at: Set(self.server_deleted_at.map(|dt| dt.fixed_offset())),
|
||||
tags: Set(serde_json::to_value(&self.tags).unwrap()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn grafting_conflict_statement() -> OnConflict {
|
||||
OnConflict::column(time_entry::Column::TogglId)
|
||||
.update_columns(vec![
|
||||
time_entry::Column::Description,
|
||||
time_entry::Column::ProjectId,
|
||||
time_entry::Column::Start,
|
||||
time_entry::Column::Stop,
|
||||
time_entry::Column::RawJson,
|
||||
time_entry::Column::ServerUpdatedAt,
|
||||
time_entry::Column::ServerDeletedAt,
|
||||
time_entry::Column::Tags,
|
||||
])
|
||||
.to_owned()
|
||||
}
|
||||
}
|
||||
|
||||
impl Client {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use reqwest::{Client, RequestBuilder, Response, Url};
|
||||
use reqwest::{Client, RequestBuilder, Response};
|
||||
use serde_json::Value;
|
||||
use std::collections::HashMap;
|
||||
use std::time::Duration;
|
||||
|
||||
@ -25,9 +25,9 @@ pub struct ReportRow {
|
||||
pub struct ReportRowInnerTimeEntry {
|
||||
pub id: u64,
|
||||
pub seconds: u32,
|
||||
pub start: String,
|
||||
pub stop: String,
|
||||
pub at: String,
|
||||
pub start: DateTime<Utc>,
|
||||
pub stop: DateTime<Utc>,
|
||||
pub at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user