89 lines
3.1 KiB
Rust
89 lines
3.1 KiB
Rust
use crate::entity::{client, project, time_entry};
|
|
use crate::toggl_api::types::{Project, Client, ReportRow};
|
|
use sea_orm::sea_query::OnConflict;
|
|
use sea_orm::{NotSet, Set};
|
|
|
|
impl ReportRow {
|
|
pub(crate) fn as_models(&self) -> Vec<time_entry::ActiveModel> {
|
|
self.time_entries
|
|
.iter()
|
|
.map(|inner| time_entry::ActiveModel {
|
|
id: NotSet,
|
|
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()),
|
|
raw_json: Set(serde_json::to_value(inner).unwrap()),
|
|
})
|
|
.collect()
|
|
}
|
|
|
|
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,
|
|
])
|
|
.to_owned()
|
|
}
|
|
}
|
|
|
|
impl Client {
|
|
pub fn as_model(&self) -> client::ActiveModel {
|
|
client::ActiveModel {
|
|
id: Set(self.id),
|
|
name: Set(self.name.clone()),
|
|
archived: Set(self.archived.clone()),
|
|
workspace_id: Set(self.wid),
|
|
at: Set(self.at.clone().fixed_offset()),
|
|
server_deleted_at: Set(self.server_deleted_at.clone().map(|dt| dt.fixed_offset())),
|
|
}
|
|
}
|
|
|
|
pub fn grafting_conflict_statement() -> OnConflict {
|
|
OnConflict::column(client::Column::Id)
|
|
.update_columns(vec![
|
|
client::Column::Name,
|
|
client::Column::Archived,
|
|
client::Column::WorkspaceId,
|
|
client::Column::At,
|
|
client::Column::ServerDeletedAt,
|
|
])
|
|
.to_owned()
|
|
}
|
|
}
|
|
|
|
impl Project {
|
|
pub fn as_model(&self) -> project::ActiveModel {
|
|
project::ActiveModel {
|
|
id: NotSet,
|
|
toggl_id: Set(self.id as i64),
|
|
name: Set(self.name.clone()),
|
|
active: Set(self.active),
|
|
client_id: Set(self.client_id.map(|id| id as i32)),
|
|
workspace_id: Set(self.workspace_id as i64),
|
|
raw_json: Set(serde_json::to_value(self).unwrap()),
|
|
color: Set(self.color.clone()),
|
|
server_created_at: Set(self.created_at.clone().fixed_offset()),
|
|
server_updated_at: Set(self.at.clone().fixed_offset()),
|
|
server_deleted_at: Set(self.server_deleted_at.clone().fixed_offset()),
|
|
}
|
|
}
|
|
|
|
pub fn grafting_conflict_statement() -> OnConflict {
|
|
OnConflict::column(project::Column::TogglId)
|
|
.update_columns(vec![
|
|
project::Column::Name,
|
|
project::Column::Active,
|
|
project::Column::ClientId,
|
|
project::Column::WorkspaceId,
|
|
project::Column::RawJson,
|
|
])
|
|
.to_owned()
|
|
}
|
|
}
|