cargo fmt
This commit is contained in:
parent
9b8999e0f3
commit
92979a7391
14
src/main.rs
14
src/main.rs
@ -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)]
|
||||
@ -10,10 +10,10 @@ struct Opts {
|
||||
#[clap(short, long = "database", value_parser, env)]
|
||||
database_url: String,
|
||||
|
||||
#[clap(short, long, value_parser, env, default_value="0.0.0.0")]
|
||||
#[clap(short, long, value_parser, env, default_value = "0.0.0.0")]
|
||||
address: String,
|
||||
|
||||
#[clap(short, long, value_parser, env, default_value="8888")]
|
||||
#[clap(short, long, value_parser, env, default_value = "8888")]
|
||||
port: u16,
|
||||
|
||||
#[clap(subcommand)]
|
||||
@ -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?,
|
||||
},
|
||||
|
@ -1,5 +1,3 @@
|
||||
pub(crate) struct UserController;
|
||||
|
||||
impl UserController {
|
||||
|
||||
}
|
||||
impl UserController {}
|
||||
|
@ -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?;
|
||||
|
||||
|
@ -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))
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user