mirror of
https://github.com/actix/examples
synced 2025-06-26 17:17:42 +02:00
fmt
This commit is contained in:
@ -49,10 +49,7 @@ pub async fn create(
|
||||
session: Session,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
if params.description.is_empty() {
|
||||
session::set_flash(
|
||||
&session,
|
||||
FlashMessage::error("Description cannot be empty"),
|
||||
)?;
|
||||
session::set_flash(&session, FlashMessage::error("Description cannot be empty"))?;
|
||||
Ok(redirect_to("/"))
|
||||
} else {
|
||||
db::create_task(params.into_inner().description, &pool)
|
||||
@ -133,9 +130,7 @@ pub fn not_found<B>(res: dev::ServiceResponse<B>) -> Result<ErrorHandlerResponse
|
||||
Ok(ErrorHandlerResponse::Response(res.into_response(new_resp)))
|
||||
}
|
||||
|
||||
pub fn internal_server_error<B>(
|
||||
res: dev::ServiceResponse<B>,
|
||||
) -> Result<ErrorHandlerResponse<B>> {
|
||||
pub fn internal_server_error<B>(res: dev::ServiceResponse<B>) -> Result<ErrorHandlerResponse<B>> {
|
||||
let new_resp = NamedFile::open("static/errors/500.html")?
|
||||
.set_status_code(res.status())
|
||||
.into_response(res.request())
|
||||
|
@ -32,8 +32,7 @@ async fn main() -> io::Result<()> {
|
||||
HttpServer::new(move || {
|
||||
log::debug!("Constructing the App");
|
||||
|
||||
let mut templates =
|
||||
Tera::new("templates/**/*").expect("errors in tera templates");
|
||||
let mut templates = Tera::new("templates/**/*").expect("errors in tera templates");
|
||||
templates.autoescape_on(vec!["tera"]);
|
||||
|
||||
let session_store = CookieSession::signed(SESSION_SIGNING_KEY).secure(false);
|
||||
|
@ -28,10 +28,7 @@ impl Task {
|
||||
Ok(tasks)
|
||||
}
|
||||
|
||||
pub async fn insert(
|
||||
todo: NewTask,
|
||||
connection: &SqlitePool,
|
||||
) -> Result<(), sqlx::Error> {
|
||||
pub async fn insert(todo: NewTask, connection: &SqlitePool) -> Result<(), sqlx::Error> {
|
||||
sqlx::query!(
|
||||
r#"
|
||||
INSERT INTO tasks (description)
|
||||
@ -45,10 +42,7 @@ impl Task {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn toggle_with_id(
|
||||
id: i32,
|
||||
connection: &SqlitePool,
|
||||
) -> Result<(), sqlx::Error> {
|
||||
pub async fn toggle_with_id(id: i32, connection: &SqlitePool) -> Result<(), sqlx::Error> {
|
||||
sqlx::query!(
|
||||
r#"
|
||||
UPDATE tasks
|
||||
@ -63,10 +57,7 @@ impl Task {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn delete_with_id(
|
||||
id: i32,
|
||||
connection: &SqlitePool,
|
||||
) -> Result<(), sqlx::Error> {
|
||||
pub async fn delete_with_id(id: i32, connection: &SqlitePool) -> Result<(), sqlx::Error> {
|
||||
sqlx::query!(
|
||||
r#"
|
||||
DELETE FROM tasks
|
||||
|
Reference in New Issue
Block a user