-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
243 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use askama::Template; | ||
use axum::{extract::State, response::IntoResponse, Form}; | ||
use sea_orm::Set; | ||
use std::sync::Arc; | ||
use uuid::Uuid; | ||
|
||
use crate::AppState; | ||
use entity::house::ActiveModel as HouseActiveModel; | ||
use entity::house::Entity as HouseEntity; | ||
use entity::house::Model as HouseModel; | ||
use sea_orm::{ActiveModelTrait, EntityTrait}; | ||
|
||
pub async fn root_path() -> impl IntoResponse { | ||
HelloTemplate | ||
} | ||
|
||
pub async fn get_houses_web(State(database): State<Arc<AppState>>) -> impl IntoResponse { | ||
let list_houses = HouseEntity::find().all(&database.db).await.unwrap(); | ||
|
||
Records { houses: list_houses } | ||
} | ||
|
||
pub async fn create_house_web( | ||
State(database): State<Arc<AppState>>, | ||
Form(form): Form<HouseModel>, | ||
) -> impl IntoResponse { | ||
let new_house = HouseActiveModel { | ||
id: Set(Uuid::new_v4().to_string()), | ||
title: Set(form.title), | ||
body: Set(form.body), | ||
..Default::default() | ||
}; | ||
let insert_response = new_house.insert(&database.db).await.unwrap(); | ||
HouseNewTemplate { house: insert_response }; | ||
} | ||
|
||
#[derive(Template)] | ||
#[template(path = "index.html")] | ||
struct HelloTemplate; | ||
|
||
#[derive(Template)] | ||
#[template(path = "houses.html")] | ||
struct Records { | ||
houses: Vec<HouseModel>, | ||
} | ||
|
||
#[derive(Template)] | ||
#[template(path = "house.html")] | ||
struct HouseNewTemplate { | ||
house: HouseModel, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod base; | ||
pub mod house; | ||
pub mod room; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<script src="https://unpkg.com/[email protected]" integrity="sha384-FhXw7b6AlE/jyjlZH5iHa/tTe9EpJ1Y55RjcgPbjeWMskSxZt1v9qkxLJWNJaGni" crossorigin="anonymous"></script> | ||
<link rel="stylesheet" href="/styles.css"/> | ||
<title>{% block title %}{{ title }} - My Site{% endblock %}</title> | ||
{% block head %}{% endblock %} | ||
</head> | ||
<body> | ||
<div id="content"> | ||
{% block content %}<p>Placeholder content</p>{% endblock %} | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<tr id="shuttle-house-{{ house.id }}"> | ||
<td> {{ house.id }} </td> | ||
<td id="shuttle-house-desc-{{house.id}}"> {{ house.title }} </td> | ||
<td id="shuttel-house-body={{house.id}}"> {{ house.body }}</td> | ||
<td> | ||
<button hx-delete="/houses/{{house.id}}" hx-trigger="click" hx-target="#shuttle-todo-{{house.id}}" hx-swap="delete">Delete</button> | ||
</td> | ||
</tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<div id="houses"> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>ID</th> | ||
<th>Title</th> | ||
<th>Body</th> | ||
<th>Delete</th> | ||
</tr> | ||
</thead> | ||
<tbody id="houses-content"> | ||
{% for house in houses %} | ||
{% include "house.html" %} | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block title %}Index{% endblock %} | ||
|
||
{% block content %} | ||
<h1>Inventory App</h1> | ||
<form id="add-form"> | ||
<input placeholder="Your House name" required type=text name="title"> | ||
<input placeholder="Description" required type=text name="body"> | ||
<button hx-post="/houses" hx-trigger="click" hx-target="#houses-content" hx-swap="beforeend">Add</button> | ||
</form> | ||
<div id="list" hx-get="/houses" hx-target="this" hx-trigger="load" hx-swap="outerHTML"> | ||
Loading... | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#content { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
gap: 1rem; | ||
} | ||
|
||
table, th, td { | ||
border: 1px solid black; | ||
padding: 0.25rem; | ||
} |