Initial work re-implementing model for TimeEntries

This commit is contained in:
2023-11-01 17:32:26 +00:00
parent 31b322d643
commit 8f39bf7d23
12 changed files with 194 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
pub mod prelude;
pub mod time_entry;
+3
View File
@@ -0,0 +1,3 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
pub use super::time_entry::Entity as TimeEntry;
+22
View File
@@ -0,0 +1,22 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "time_entry")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i64,
pub description: String,
pub project_id: Option<i64>,
pub start: DateTime,
pub stop: DateTime,
#[sea_orm(column_type = "JsonBinary")]
pub raw_json: Json,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}
+13
View File
@@ -13,6 +13,7 @@ use serde_json::Value;
use std::collections::HashMap;
use std::net::SocketAddr;
use tower_http::trace::TraceLayer;
use migration::{Migrator, MigratorTrait};
mod client;
mod types;
@@ -27,6 +28,9 @@ struct Config {
#[arg(long = "addr", short, env, default_value = "0.0.0.0:3000")]
address: SocketAddr,
#[arg(long = "db", short, env)]
database_url: String,
}
pub async fn report(
@@ -70,6 +74,14 @@ async fn main() -> Result<()> {
&STANDARD.encode(&format!("{}:api_token", config.toggl_api_token)),
);
let db = sea_orm::Database::connect(config.database_url)
.await
.unwrap();
Migrator::up(&db, None)
.await
.expect("Failed to migrate");
// build our application with a route
let app = Router::new()
.route("/health", get(health))
@@ -77,6 +89,7 @@ async fn main() -> Result<()> {
.route("/report", post(report))
.route("/start_time_entry", post(start_time_entry))
.layer(Extension(toggl_client))
.layer(Extension(db))
.layer(TraceLayer::new_for_http());
tracing::info!("Listening on {}", config.address);