✅ Seznam funkcij za implementacijo (po tvoji logiki aplikacije):
Urejanje oglasa (/edit-listing)
Brisanje oglasa (deleteListing)
Potrditev dostave (confirmDelivery)
Podrobnosti izdelka / naročila (/order-details)
Nalaganje izdelka (/create-listing)
Spremljanje statusa naročila (v teku, dostavljeno)
Sistem ocen po transakciji
Avtomatski prikaz uporabniškega statusa (Buyer, Seller)
🛠️ 1. edit-listing.html – Urejanje obstoječega oglasa
<h2>Uredi oglas</h2> <form id="editListingForm"> <input type="hidden" name="listingId" value=""><label>Naslov</label>
<input type="text" name="title" required>
<label>Cena (v π)</label>
<input type="number" name="price" required>
<label>Opis</label>
<textarea name="description"></textarea><label>Status</label>
<select name="status">
<option value="Aktiven">Aktiven</option>
<option value="Prodan">Prodan</option>
</select>
<button type="submit">Shrani spremembe</button>
</form> <script> const params = new URLSearchParams(window.location.search); const listingId = params.get("id"); // Naloži obstoječe podatke oglasa fetch(`/api/get-listing?id=${listingId}`) .then(res => res.json()) .then(data => { document.querySelector("input[name=listingId]").value = data.id; document.querySelector("input[name=title]").value = data.title; document.querySelector("input[name=price]").value = data.price; document.querySelector("textarea[name=description]").value = data.description; document.querySelector("select[name=status]").value = data.status; }); document.getElementById("editListingForm").addEventListener("submit", e => { e.preventDefault(); const formData = new FormData(e.target); fetch("/api/edit-listing", { method: "POST", body: JSON.stringify(Object.fromEntries(formData)), headers: { "Content-Type": "application/json" } }).then(() => { alert("Oglas posodobljen."); window.location.href = "/my-listings"; }); }); </script>🧹 2. deleteListing(id) – Brisanje oglasa
function deleteListing(id) {
if (confirm("Ali res želiš izbrisati ta oglas?")) {
fetch(/api/delete-listing?id=${id}, {
method: "DELETE"
}).then(() => {
alert("Oglas izbrisan.");
location.reload();
});
}
}
📦 3. confirmDelivery(orderId) – Potrditev dostave
function confirmDelivery(orderId) {
fetch(/api/confirm-delivery?id=${orderId}, {
method: "POST"
}).then(() => {
alert("Dostava potrjena.");
location.reload();
});
}
📄 4. order-details.html – Podrobnosti naročila
<h2>Podrobnosti naročila</h2> <div id="orderDetails"></div> <script> const orderId = new URLSearchParams(window.location.search).get("id"); fetch(`/api/order-details?id=${orderId}`) .then(res => res.json()) .then(data => { document.getElementById("orderDetails").innerHTML = ` <p><strong>Izdelek:</strong> ${data.item}</p> <p><strong>Cena:</strong> ${data.price}π</p> <p><strong>Status:</strong> ${data.status}</p> <p><strong>Kupec:</strong> ${data.buyer}</p> `; if (data.status === "V teku") { document.getElementById("orderDetails").innerHTML += ` <button onclick="confirmDelivery(${orderId})">Potrdi dostavo</button> `; } }); </script>🆕 5. create-listing.html – Dodaj nov oglas
<h2>Dodaj nov oglas</h2> <form id="newListingForm"> <label>Naslov</label> <input type="text" name="title" required><label>Cena (v π)</label>
<input type="number" name="price" required>
<label>Opis</label>
<textarea name="description"></textarea><button type="submit">Objavi oglas</button>
</form> <script> document.getElementById("newListingForm").addEventListener("submit", e => { e.preventDefault(); const formData = new FormData(e.target); fetch("/api/create-listing", { method: "POST", body: JSON.stringify(Object.fromEntries(formData)), headers: { "Content-Type": "application/json" } }).then(() => { alert("Oglas objavljen."); window.location.href = "/my-listings"; }); }); </script>⭐ 6. Sistem ocen po transakciji
To si že imel, samo dodamo še, da se ocena shrani v bazo (v rate-experience.html → backend endpoint /api/rate):
document.getElementById("rateForm").addEventListener("submit", e => {
e.preventDefault();
const formData = new FormData(e.target);
fetch("/api/rate", {
method: "POST",
body: JSON.stringify(Object.fromEntries(formData)),
headers: { "Content-Type": "application/json" }
}).then(() => {
alert("Hvala za oceno!");
window.location.href = "/dashboard";
});
});
👤 7. Dinamičen prikaz uporabnika (tip: Seller, Buyer)
V profile.html:
<p>Tip: <span id="userType"></span></p> <script> fetch("/api/profile-info") .then(res => res.json()) .then(data => { document.getElementById("userType").innerText = data.type === "both" ? "Buyer & Seller" : data.type === "buyer" ? "Buyer" : "Seller"; }); </script>Odličen pregled! Vidim, da imaš jasno strukturo funkcionalnosti. Dodajam še manjkajoče komponente in izboljšave za popolno delovanje:
Opravičujem se za napako! Popravljam glavno aplikacijo, da se bo pravilno prikazala: