Display donation addresses
This commit is contained in:
parent
8a8162d6b0
commit
1d30e8a97c
5 changed files with 68 additions and 3 deletions
|
@ -1,5 +1,7 @@
|
|||
mod donation_crypto_address;
|
||||
mod employee;
|
||||
mod user;
|
||||
|
||||
pub use self::donation_crypto_address::*;
|
||||
pub use self::employee::*;
|
||||
pub use self::user::*;
|
||||
|
|
21
src/models/donation_crypto_address.rs
Normal file
21
src/models/donation_crypto_address.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
use crate::database::DbConn;
|
||||
|
||||
use crate::schema::donation_crypto_addresses;
|
||||
|
||||
use diesel::prelude::*;
|
||||
|
||||
#[derive(Debug, Identifiable, Serialize, Queryable)]
|
||||
#[table_name = "donation_crypto_addresses"]
|
||||
pub struct DonationCryptoAddress {
|
||||
pub id: i32,
|
||||
pub name: String,
|
||||
pub code: String,
|
||||
pub address: String,
|
||||
pub history: String,
|
||||
}
|
||||
|
||||
impl DonationCryptoAddress {
|
||||
pub fn all(db_conn: DbConn) -> Result<Vec<Self>, diesel::result::Error> {
|
||||
donation_crypto_addresses::table.load::<Self>(&*db_conn)
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
use crate::database;
|
||||
// use crate::models;
|
||||
use crate::models;
|
||||
use crate::states;
|
||||
use crate::views;
|
||||
|
||||
|
@ -13,13 +13,19 @@ use rocket_csrf::CsrfToken;
|
|||
#[get("/donate")]
|
||||
pub fn index(
|
||||
_i18n: State<I18n>,
|
||||
_db_conn: database::DbConn,
|
||||
db_conn: database::DbConn,
|
||||
csrf_token: CsrfToken,
|
||||
current_user: states::MaybeCurrentUser,
|
||||
) -> Result<Template, CommonResponse> {
|
||||
let donation_crypto_addresses = models::DonationCryptoAddress::all(db_conn)?;
|
||||
|
||||
let page_context = views::donate::Index {
|
||||
donation_crypto_addresses,
|
||||
};
|
||||
|
||||
let context = views::Site {
|
||||
page: "donate/index".to_string(),
|
||||
page_context: (),
|
||||
page_context,
|
||||
authenticity_token: csrf_token.authenticity_token().to_string(),
|
||||
current_user: current_user.0,
|
||||
};
|
||||
|
|
|
@ -15,6 +15,15 @@ pub struct Error {
|
|||
pub error_code: u16,
|
||||
}
|
||||
|
||||
pub mod donate {
|
||||
use crate::models;
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct Index {
|
||||
pub donation_crypto_addresses: Vec<models::DonationCryptoAddress>,
|
||||
}
|
||||
}
|
||||
|
||||
pub mod home {
|
||||
#[derive(Serialize)]
|
||||
pub struct Index {
|
||||
|
|
27
templates/donate/index.html.hbs
Normal file
27
templates/donate/index.html.hbs
Normal file
|
@ -0,0 +1,27 @@
|
|||
<div class="container">
|
||||
<div class="row">
|
||||
{{#each donation_crypto_addresses}}
|
||||
<div class="col-lg-6">
|
||||
<div class="card mt-4">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">
|
||||
{{ this.name }}
|
||||
</h5>
|
||||
|
||||
<h6 class="card-subtitle text-muted mb-2">
|
||||
{{ this.code }}
|
||||
</h6>
|
||||
|
||||
<p class="card-text">
|
||||
<code>{{ this.address }}</code>
|
||||
</p>
|
||||
|
||||
<a href="{{ this.history }}" target="_blank" class="card-link">
|
||||
History
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{/each}}
|
||||
</div>
|
||||
</div>
|
Reference in a new issue