Format main.rs
This commit is contained in:
parent
835bce5dcb
commit
1e4cf00730
@ -1,20 +1,19 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
|
|
||||||
use std::str::FromStr;
|
use chrono::NaiveDate;
|
||||||
|
use entity::transaction;
|
||||||
|
use migration::MigratorTrait;
|
||||||
|
use rocket::fairing::{self, AdHoc};
|
||||||
use rocket::form::Form;
|
use rocket::form::Form;
|
||||||
use rocket::response::{Flash, Redirect};
|
use rocket::response::{Flash, Redirect};
|
||||||
use migration::{MigratorTrait};
|
use rocket::{Build, Rocket};
|
||||||
|
use rust_decimal::Decimal;
|
||||||
use sea_orm::ActiveValue::Set;
|
use sea_orm::ActiveValue::Set;
|
||||||
use sea_orm::{ActiveModelTrait, ConnectOptions, DatabaseConnection};
|
use sea_orm::{ActiveModelTrait, ConnectOptions, DatabaseConnection};
|
||||||
use sea_orm_rocket::{rocket::figment::Figment, Config, Database, Connection};
|
use sea_orm_rocket::{rocket::figment::Figment, Config, Connection, Database};
|
||||||
|
use std::str::FromStr;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use chrono::{NaiveDate};
|
|
||||||
use entity::transaction;
|
|
||||||
use rust_decimal::Decimal;
|
|
||||||
use rocket::{Build, Rocket};
|
|
||||||
use rocket::fairing::{self, AdHoc};
|
|
||||||
|
|
||||||
|
|
||||||
#[derive(sea_orm_rocket::Database, Debug)]
|
#[derive(sea_orm_rocket::Database, Debug)]
|
||||||
#[database("bookkeeper")]
|
#[database("bookkeeper")]
|
||||||
@ -50,7 +49,6 @@ impl sea_orm_rocket::Pool for SeaOrmPool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
fn index() -> &'static str {
|
fn index() -> &'static str {
|
||||||
"Hello, world!"
|
"Hello, world!"
|
||||||
@ -69,12 +67,12 @@ struct TransBuy<'r> {
|
|||||||
#[post("/buy", data = "<trans_buy>")]
|
#[post("/buy", data = "<trans_buy>")]
|
||||||
async fn buy(trans_buy: Form<TransBuy<'_>>, conn: Connection<'_, Db>) -> Flash<Redirect> {
|
async fn buy(trans_buy: Form<TransBuy<'_>>, conn: Connection<'_, Db>) -> Flash<Redirect> {
|
||||||
let record = transaction::ActiveModel {
|
let record = transaction::ActiveModel {
|
||||||
code: Set(trans_buy.code as i32),
|
code: Set(trans_buy.code as i32),
|
||||||
name: Set(trans_buy.name.to_string()),
|
name: Set(trans_buy.name.to_string()),
|
||||||
buy: Set(Decimal::from_str(trans_buy.buy).unwrap()),
|
buy: Set(Decimal::from_str(trans_buy.buy).unwrap()),
|
||||||
volume: Set(trans_buy.volume as i32),
|
volume: Set(trans_buy.volume as i32),
|
||||||
net_buy: Set(Decimal::from_str(trans_buy.net_buy).unwrap()),
|
net_buy: Set(Decimal::from_str(trans_buy.net_buy).unwrap()),
|
||||||
date: Set(NaiveDate::parse_from_str(trans_buy.date, "%Y-%m-%d").unwrap()),
|
date: Set(NaiveDate::parse_from_str(trans_buy.date, "%Y-%m-%d").unwrap()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user