cargo fmt

This commit is contained in:
guochao 2022-08-06 11:56:43 +08:00
parent 9b8999e0f3
commit 92979a7391
Signed by: guochao
GPG Key ID: 79F7306D2AA32FC3
5 changed files with 31 additions and 28 deletions

View File

@ -1,6 +1,6 @@
use clap::{CommandFactory, Parser, Subcommand};
use clap_complete::Shell;
use sea_orm::{Database};
use sea_orm::Database;
use sea_orm_migration::prelude::*;
#[derive(Parser, Clone)]
@ -37,9 +37,7 @@ enum Commands {
#[derive(Subcommand, Clone)]
enum MigrationDirection {
/// Migrate database up
Up {
steps: Option<u32>,
},
Up { steps: Option<u32> },
/// Do a fresh install
Fresh,
/// Remove previous tables and do a fresh install
@ -72,7 +70,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
if let Some(command) = args.commands.clone() {
match command {
Commands::Migrate { direction } => match direction {
MigrationDirection::Up{steps} => migrations::Migrator::up(&database, steps).await?,
MigrationDirection::Up { steps } => {
migrations::Migrator::up(&database, steps).await?
}
MigrationDirection::Fresh => migrations::Migrator::fresh(&database).await?,
MigrationDirection::Refresh => migrations::Migrator::refresh(&database).await?,
},

View File

@ -1,5 +1,3 @@
pub(crate) struct UserController;
impl UserController {
}
impl UserController {}

View File

@ -1,29 +1,28 @@
use actix_web::{HttpServer, App};
use actix_web::{App, HttpServer};
use sea_orm::DatabaseConnection;
use crate::Opts;
mod urls;
mod controller;
mod model;
mod view;
mod controller;
#[derive(Debug, Clone)]
struct AppState {
database: DatabaseConnection,
}
pub(crate) async fn run(database: DatabaseConnection, opts: Opts) -> Result<(), Box<dyn std::error::Error>> {
let data = actix_web::web::Data::new(AppState {
database: database,
});
pub(crate) async fn run(
database: DatabaseConnection,
opts: Opts,
) -> Result<(), Box<dyn std::error::Error>> {
let data = actix_web::web::Data::new(AppState { database: database });
let server = HttpServer::new(move|| {
App::new()
.configure(urls::configure)
.app_data(data.clone())
}).bind((opts.address, opts.port))?;
let server =
HttpServer::new(move || App::new().configure(urls::configure).app_data(data.clone()))
.bind((opts.address, opts.port))?;
let result = server.run().await?;

View File

@ -1,4 +1,4 @@
use actix_web::{Responder, HttpRequest};
use actix_web::{HttpRequest, Responder};
use sea_orm::*;
use serde::{Deserialize, Serialize};
@ -13,10 +13,16 @@ pub struct Params {
}
#[actix_web::get("/")]
async fn index_page(req: HttpRequest, data: actix_web::web::Data<AppState>) -> Result<impl Responder, Box<dyn std::error::Error>> {
async fn index_page(
req: HttpRequest,
data: actix_web::web::Data<AppState>,
) -> Result<impl Responder, Box<dyn std::error::Error>> {
let params = actix_web::web::Query::<Params>::from_query(req.query_string()).unwrap();
let users = User::find().paginate(&data.database, params.posts_per_page.unwrap_or(10)).fetch_page(params.page.unwrap_or(0)).await?;
let users = User::find()
.paginate(&data.database, params.posts_per_page.unwrap_or(10))
.fetch_page(params.page.unwrap_or(0))
.await?;
Ok(actix_web::web::Json(users))
}