This commit is contained in:
despiegk 2025-04-29 06:27:28 +04:00
parent 19f8700b78
commit 457f3c8268
6 changed files with 112 additions and 75 deletions

View File

@ -103,7 +103,10 @@ impl MarketplaceController {
AssetType::NFT.as_str(),
AssetType::RealEstate.as_str(),
AssetType::IntellectualProperty.as_str(),
AssetType::PhysicalAsset.as_str(),
AssetType::Commodity.as_str(),
AssetType::Share.as_str(),
AssetType::Bond.as_str(),
AssetType::Other.as_str(),
]);
render_template(&tmpl, "marketplace/listings.html", &context)
@ -146,9 +149,22 @@ impl MarketplaceController {
.take(4)
.collect();
// Get highest bid amount and minimum bid for auction listings
let (highest_bid_amount, minimum_bid) = if listing.listing_type == ListingType::Auction {
if let Some(bid) = listing.highest_bid() {
(Some(bid.amount), bid.amount + 1.0)
} else {
(None, listing.price + 1.0)
}
} else {
(None, 0.0)
};
context.insert("active_page", &"marketplace");
context.insert("listing", listing);
context.insert("similar_listings", &similar_listings);
context.insert("highest_bid_amount", &highest_bid_amount);
context.insert("minimum_bid", &minimum_bid);
// Add current user info for bid/purchase forms
let user_id = "user-123";
@ -311,7 +327,7 @@ impl MarketplaceController {
tmpl: web::Data<Tera>,
path: web::Path<String>,
) -> Result<HttpResponse> {
let listing_id = path.into_inner();
let _listing_id = path.into_inner();
// In a real application, we would:
// 1. Find the listing in the database
@ -344,7 +360,10 @@ impl MarketplaceController {
AssetType::NFT => 500.0 + (i as f64 * 100.0),
AssetType::RealEstate => 50000.0 + (i as f64 * 10000.0),
AssetType::IntellectualProperty => 2000.0 + (i as f64 * 500.0),
AssetType::PhysicalAsset => 1000.0 + (i as f64 * 200.0),
AssetType::Commodity => 1000.0 + (i as f64 * 200.0),
AssetType::Share => 300.0 + (i as f64 * 50.0),
AssetType::Bond => 1500.0 + (i as f64 * 300.0),
AssetType::Other => 800.0 + (i as f64 * 150.0),
};
let mut listing = Listing::new(
@ -382,7 +401,10 @@ impl MarketplaceController {
AssetType::NFT => 400.0 + (i as f64 * 50.0),
AssetType::RealEstate => 40000.0 + (i as f64 * 5000.0),
AssetType::IntellectualProperty => 1500.0 + (i as f64 * 300.0),
AssetType::PhysicalAsset => 800.0 + (i as f64 * 100.0),
AssetType::Commodity => 800.0 + (i as f64 * 100.0),
AssetType::Share => 250.0 + (i as f64 * 40.0),
AssetType::Bond => 1200.0 + (i as f64 * 250.0),
AssetType::Other => 600.0 + (i as f64 * 120.0),
};
let mut listing = Listing::new(
@ -435,7 +457,10 @@ impl MarketplaceController {
AssetType::NFT => 600.0 + (i as f64 * 150.0),
AssetType::RealEstate => 60000.0 + (i as f64 * 15000.0),
AssetType::IntellectualProperty => 2500.0 + (i as f64 * 600.0),
AssetType::PhysicalAsset => 1200.0 + (i as f64 * 300.0),
AssetType::Commodity => 1200.0 + (i as f64 * 300.0),
AssetType::Share => 350.0 + (i as f64 * 70.0),
AssetType::Bond => 1800.0 + (i as f64 * 350.0),
AssetType::Other => 1000.0 + (i as f64 * 200.0),
};
let listing = Listing::new(
@ -469,7 +494,10 @@ impl MarketplaceController {
AssetType::NFT => 550.0 + (i as f64 * 120.0),
AssetType::RealEstate => 55000.0 + (i as f64 * 12000.0),
AssetType::IntellectualProperty => 2200.0 + (i as f64 * 550.0),
AssetType::PhysicalAsset => 1100.0 + (i as f64 * 220.0),
AssetType::Commodity => 1100.0 + (i as f64 * 220.0),
AssetType::Share => 320.0 + (i as f64 * 60.0),
AssetType::Bond => 1650.0 + (i as f64 * 330.0),
AssetType::Other => 900.0 + (i as f64 * 180.0),
};
let sale_price = price * 0.95; // Slight discount on sale
@ -515,7 +543,10 @@ impl MarketplaceController {
AssetType::NFT => 450.0 + (i as f64 * 80.0),
AssetType::RealEstate => 45000.0 + (i as f64 * 8000.0),
AssetType::IntellectualProperty => 1800.0 + (i as f64 * 400.0),
AssetType::PhysicalAsset => 900.0 + (i as f64 * 180.0),
AssetType::Commodity => 900.0 + (i as f64 * 180.0),
AssetType::Share => 280.0 + (i as f64 * 45.0),
AssetType::Bond => 1350.0 + (i as f64 * 270.0),
AssetType::Other => 750.0 + (i as f64 * 150.0),
};
let mut listing = Listing::new(

View File

@ -35,8 +35,8 @@
<select class="form-select" id="asset_id" name="asset_id" required>
<option value="" selected disabled>Choose an asset to list</option>
{% for asset in assets %}
<option value="{{ asset.id }}" data-type="{{ asset.asset_type.as_str() }}" data-image="{{ asset.image_url }}">
{{ asset.name }} ({{ asset.asset_type.as_str() }})
<option value="{{ asset.id }}" data-type="{{ asset.asset_type }}" data-image="{{ asset.image_url }}">
{{ asset.name }} ({{ asset.asset_type }})
</option>
{% endfor %}
</select>

View File

@ -116,8 +116,8 @@
<h5 class="card-title">{{ listing.title }}</h5>
<p class="card-text text-truncate">{{ listing.description }}</p>
<div class="d-flex justify-content-between align-items-center">
<span class="badge bg-primary">{{ listing.listing_type.as_str() }}</span>
<span class="badge bg-secondary">{{ listing.asset_type.as_str() }}</span>
<span class="badge bg-primary">{{ listing.listing_type }}</span>
<span class="badge bg-secondary">{{ listing.asset_type }}</span>
</div>
</div>
<div class="card-footer">
@ -178,20 +178,20 @@
</div>
</td>
<td>
{% if listing.asset_type.as_str() == "Token" %}
<span class="badge bg-primary">{{ listing.asset_type.as_str() }}</span>
{% elif listing.asset_type.as_str() == "NFT" %}
<span class="badge bg-info">{{ listing.asset_type.as_str() }}</span>
{% elif listing.asset_type.as_str() == "RealEstate" %}
{% if listing.asset_type == "Token" %}
<span class="badge bg-primary">{{ listing.asset_type }}</span>
{% elif listing.asset_type == "NFT" %}
<span class="badge bg-info">{{ listing.asset_type }}</span>
{% elif listing.asset_type == "RealEstate" %}
<span class="badge bg-success">Real Estate</span>
{% elif listing.asset_type.as_str() == "IntellectualProperty" %}
{% elif listing.asset_type == "IntellectualProperty" %}
<span class="badge bg-warning text-dark">IP</span>
{% else %}
<span class="badge bg-secondary">{{ listing.asset_type.as_str() }}</span>
<span class="badge bg-secondary">{{ listing.asset_type }}</span>
{% endif %}
</td>
<td>${{ listing.price }}</td>
<td>{{ listing.listing_type.as_str() }}</td>
<td>{{ listing.listing_type }}</td>
<td>{{ listing.seller_name }}</td>
<td>{{ listing.created_at|date }}</td>
<td>

View File

@ -27,15 +27,15 @@
{% endif %}
<div class="d-grid gap-2">
{% if listing.listing_type.as_str() == "Fixed Price" %}
{% if listing.listing_type == "Fixed Price" %}
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#purchaseModal">
<i class="bi bi-cart"></i> Purchase Now
</button>
{% elif listing.listing_type.as_str() == "Auction" %}
{% elif listing.listing_type == "Auction" %}
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#bidModal">
<i class="bi bi-hammer"></i> Place Bid
</button>
{% elif listing.listing_type.as_str() == "Exchange" %}
{% elif listing.listing_type == "Exchange" %}
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#offerModal">
<i class="bi bi-arrow-left-right"></i> Make Exchange Offer
</button>
@ -59,16 +59,16 @@
<div class="card-body">
<p><strong>Asset Name:</strong> {{ listing.asset_name }}</p>
<p><strong>Asset Type:</strong>
{% if listing.asset_type.as_str() == "Token" %}
<span class="badge bg-primary">{{ listing.asset_type.as_str() }}</span>
{% elif listing.asset_type.as_str() == "NFT" %}
<span class="badge bg-info">{{ listing.asset_type.as_str() }}</span>
{% elif listing.asset_type.as_str() == "RealEstate" %}
{% if listing.asset_type == "Token" %}
<span class="badge bg-primary">{{ listing.asset_type }}</span>
{% elif listing.asset_type == "NFT" %}
<span class="badge bg-info">{{ listing.asset_type }}</span>
{% elif listing.asset_type == "RealEstate" %}
<span class="badge bg-success">Real Estate</span>
{% elif listing.asset_type.as_str() == "IntellectualProperty" %}
{% elif listing.asset_type == "IntellectualProperty" %}
<span class="badge bg-warning text-dark">Intellectual Property</span>
{% else %}
<span class="badge bg-secondary">{{ listing.asset_type.as_str() }}</span>
<span class="badge bg-secondary">{{ listing.asset_type }}</span>
{% endif %}
</p>
<p><strong>Asset ID:</strong> <code>{{ listing.asset_id }}</code></p>
@ -89,8 +89,11 @@
Listing Details
</div>
<div>
<span class="badge bg-{{ listing.status.as_str() == 'Active' ? 'success' : 'secondary' }}">
{{ listing.status.as_str() }}
{% if listing.status == 'Active' %}
<span class="badge bg-success">{{ listing.status }}</span>
{% else %}
<span class="badge bg-secondary">{{ listing.status }}</span>
{% endif %}
</span>
</div>
</div>
@ -100,7 +103,7 @@
<div class="d-flex justify-content-between align-items-center mb-3">
<div>
<span class="badge bg-primary">{{ listing.listing_type.as_str() }}</span>
<span class="badge bg-primary">{{ listing.listing_type }}</span>
{% if listing.featured %}
<span class="badge bg-warning text-dark">Featured</span>
{% endif %}
@ -143,7 +146,7 @@
</div>
<!-- Bids Section (for Auctions) -->
{% if listing.listing_type.as_str() == "Auction" %}
{% if listing.listing_type == "Auction" %}
<div class="card mb-4">
<div class="card-header">
<i class="bi bi-list-ol"></i>
@ -168,8 +171,11 @@
<td>${{ bid.amount }}</td>
<td>{{ bid.created_at|date }}</td>
<td>
<span class="badge bg-{{ bid.status.as_str() == 'Active' ? 'success' : 'secondary' }}">
{{ bid.status.as_str() }}
{% if bid.status == 'Active' %}
<span class="badge bg-success">{{ bid.status }}</span>
{% else %}
<span class="badge bg-secondary">{{ bid.status }}</span>
{% endif %}
</span>
</td>
</tr>
@ -177,7 +183,7 @@
</tbody>
</table>
</div>
<p class="mt-2"><strong>Current Highest Bid:</strong> ${{ listing.highest_bid().amount }}</p>
<p class="mt-2"><strong>Current Highest Bid:</strong> ${{ listing.highest_bid_amount }}</p>
{% else %}
<p>No bids yet. Be the first to bid!</p>
<p><strong>Starting Price:</strong> ${{ listing.price }}</p>
@ -212,8 +218,8 @@
<div class="card-body">
<h5 class="card-title">{{ similar.title }}</h5>
<div class="d-flex justify-content-between align-items-center">
<span class="badge bg-primary">{{ similar.listing_type.as_str() }}</span>
<span class="badge bg-secondary">{{ similar.asset_type.as_str() }}</span>
<span class="badge bg-primary">{{ similar.listing_type }}</span>
<span class="badge bg-secondary">{{ similar.asset_type }}</span>
</div>
</div>
<div class="card-footer">
@ -293,9 +299,9 @@
<ul>
<li>Asset: {{ listing.asset_name }}</li>
<li>Starting Price: ${{ listing.price }} {{ listing.currency }}</li>
{% if listing.highest_bid() %}
<li>Current Highest Bid: ${{ listing.highest_bid().amount }} {{ listing.currency }}</li>
<li>Minimum Bid: ${{ listing.highest_bid().amount + 1 }} {{ listing.currency }}</li>
{% if listing.highest_bid_amount %}
<li>Current Highest Bid: ${{ listing.highest_bid_amount }} {{ listing.currency }}</li>
<li>Minimum Bid: ${{ listing.highest_bid_amount + 1 }} {{ listing.currency }}</li>
{% else %}
<li>Minimum Bid: ${{ listing.price + 1 }} {{ listing.currency }}</li>
{% endif %}
@ -306,7 +312,7 @@
<label for="bid-amount" class="form-label">Your Bid Amount ({{ listing.currency }})</label>
<div class="input-group">
<span class="input-group-text">$</span>
<input type="number" class="form-control" id="bid-amount" name="amount" step="0.01" min="{{ listing.highest_bid() ? listing.highest_bid().amount + 1 : listing.price + 1 }}" required>
<input type="number" class="form-control" id="bid-amount" name="amount" step="0.01" min="{{ minimum_bid }}" required>
</div>
</div>

View File

@ -78,8 +78,8 @@
{% if listings|length > 0 %}
{% for listing in listings %}
<div class="col-xl-3 col-lg-4 col-md-6 mb-4 listing-item"
data-asset-type="{{ listing.asset_type.as_str() }}"
data-listing-type="{{ listing.listing_type.as_str() }}"
data-asset-type="{{ listing.asset_type }}"
data-listing-type="{{ listing.listing_type }}"
data-price="{{ listing.price }}">
<div class="card h-100">
{% if listing.featured %}
@ -96,17 +96,17 @@
<h5 class="card-title">{{ listing.title }}</h5>
<p class="card-text text-truncate">{{ listing.description }}</p>
<div class="d-flex justify-content-between align-items-center mb-2">
<span class="badge bg-primary">{{ listing.listing_type.as_str() }}</span>
{% if listing.asset_type.as_str() == "Token" %}
<span class="badge bg-primary">{{ listing.asset_type.as_str() }}</span>
{% elif listing.asset_type.as_str() == "NFT" %}
<span class="badge bg-info">{{ listing.asset_type.as_str() }}</span>
{% elif listing.asset_type.as_str() == "RealEstate" %}
<span class="badge bg-primary">{{ listing.listing_type }}</span>
{% if listing.asset_type == "Token" %}
<span class="badge bg-primary">{{ listing.asset_type }}</span>
{% elif listing.asset_type == "NFT" %}
<span class="badge bg-info">{{ listing.asset_type }}</span>
{% elif listing.asset_type == "RealEstate" %}
<span class="badge bg-success">Real Estate</span>
{% elif listing.asset_type.as_str() == "IntellectualProperty" %}
{% elif listing.asset_type == "IntellectualProperty" %}
<span class="badge bg-warning text-dark">IP</span>
{% else %}
<span class="badge bg-secondary">{{ listing.asset_type.as_str() }}</span>
<span class="badge bg-secondary">{{ listing.asset_type }}</span>
{% endif %}
</div>
<div class="d-flex justify-content-between align-items-center">
@ -159,8 +159,8 @@
{% if listings|length > 0 %}
{% for listing in listings %}
<tr class="listing-item"
data-asset-type="{{ listing.asset_type.as_str() }}"
data-listing-type="{{ listing.listing_type.as_str() }}"
data-asset-type="{{ listing.asset_type }}"
data-listing-type="{{ listing.listing_type }}"
data-price="{{ listing.price }}">
<td>
<div class="d-flex align-items-center">
@ -173,20 +173,20 @@
</td>
<td>{{ listing.title }}</td>
<td>
{% if listing.asset_type.as_str() == "Token" %}
<span class="badge bg-primary">{{ listing.asset_type.as_str() }}</span>
{% elif listing.asset_type.as_str() == "NFT" %}
<span class="badge bg-info">{{ listing.asset_type.as_str() }}</span>
{% elif listing.asset_type.as_str() == "RealEstate" %}
{% if listing.asset_type == "Token" %}
<span class="badge bg-primary">{{ listing.asset_type }}</span>
{% elif listing.asset_type == "NFT" %}
<span class="badge bg-info">{{ listing.asset_type }}</span>
{% elif listing.asset_type == "RealEstate" %}
<span class="badge bg-success">Real Estate</span>
{% elif listing.asset_type.as_str() == "IntellectualProperty" %}
{% elif listing.asset_type == "IntellectualProperty" %}
<span class="badge bg-warning text-dark">IP</span>
{% else %}
<span class="badge bg-secondary">{{ listing.asset_type.as_str() }}</span>
<span class="badge bg-secondary">{{ listing.asset_type }}</span>
{% endif %}
</td>
<td>${{ listing.price }}</td>
<td>{{ listing.listing_type.as_str() }}</td>
<td>{{ listing.listing_type }}</td>
<td>{{ listing.seller_name }}</td>
<td>{{ listing.created_at|date }}</td>
<td>

View File

@ -58,17 +58,17 @@
<td>{{ listing.title }}</td>
<td>${{ listing.price }}</td>
<td>
<span class="badge bg-primary">{{ listing.listing_type.as_str() }}</span>
<span class="badge bg-primary">{{ listing.listing_type }}</span>
</td>
<td>
{% if listing.status.as_str() == "Active" %}
<span class="badge bg-success">{{ listing.status.as_str() }}</span>
{% elif listing.status.as_str() == "Sold" %}
<span class="badge bg-info">{{ listing.status.as_str() }}</span>
{% elif listing.status.as_str() == "Cancelled" %}
<span class="badge bg-danger">{{ listing.status.as_str() }}</span>
{% elif listing.status.as_str() == "Expired" %}
<span class="badge bg-warning text-dark">{{ listing.status.as_str() }}</span>
{% if listing.status == "Active" %}
<span class="badge bg-success">{{ listing.status }}</span>
{% elif listing.status == "Sold" %}
<span class="badge bg-info">{{ listing.status }}</span>
{% elif listing.status == "Cancelled" %}
<span class="badge bg-danger">{{ listing.status }}</span>
{% elif listing.status == "Expired" %}
<span class="badge bg-warning text-dark">{{ listing.status }}</span>
{% endif %}
</td>
<td>{{ listing.created_at|date }}</td>
@ -85,7 +85,7 @@
<a href="/marketplace/{{ listing.id }}" class="btn btn-sm btn-outline-primary">
<i class="bi bi-eye"></i>
</a>
{% if listing.status.as_str() == "Active" %}
{% if listing.status == "Active" %}
<form action="/marketplace/{{ listing.id }}/cancel" method="post" class="d-inline">
<button type="submit" class="btn btn-sm btn-outline-danger" onclick="return confirm('Are you sure you want to cancel this listing?')">
<i class="bi bi-x-circle"></i>