make format diagonalley
This commit is contained in:
parent
39bae68b1c
commit
58b046254f
8 changed files with 1037 additions and 978 deletions
|
|
@ -1,10 +1,11 @@
|
|||
import asyncio
|
||||
|
||||
from fastapi import APIRouter
|
||||
from starlette.staticfiles import StaticFiles
|
||||
|
||||
from lnbits.db import Database
|
||||
from lnbits.helpers import template_renderer
|
||||
from lnbits.tasks import catch_everything_and_restart
|
||||
from starlette.staticfiles import StaticFiles
|
||||
|
||||
db = Database("ext_diagonalley")
|
||||
|
||||
|
|
@ -26,6 +27,7 @@ diagonalley_static_files = [
|
|||
# )
|
||||
# else:
|
||||
|
||||
|
||||
def diagonalley_renderer():
|
||||
return template_renderer(["lnbits/extensions/diagonalley/templates"])
|
||||
# return template_renderer(["lnbits/extensions/diagonalley/templates"])
|
||||
|
|
|
|||
|
|
@ -235,7 +235,10 @@ async def create_diagonalley_order(wallet_id: str, data: createOrder) -> Orders:
|
|||
assert link, "Newly created link couldn't be retrieved"
|
||||
return link
|
||||
|
||||
async def create_diagonalley_order_details(order_id: str, data: List[createOrderDetails]):
|
||||
|
||||
async def create_diagonalley_order_details(
|
||||
order_id: str, data: List[createOrderDetails]
|
||||
):
|
||||
for item in data:
|
||||
item_id = urlsafe_short_hash()
|
||||
await db.execute(
|
||||
|
|
@ -253,6 +256,7 @@ async def create_diagonalley_order_details(order_id: str, data: List[createOrder
|
|||
order_details = await get_diagonalley_order_details(order_id)
|
||||
return order_details
|
||||
|
||||
|
||||
async def get_diagonalley_order_details(order_id: str) -> List[OrderDetail]:
|
||||
rows = await db.fetchall(
|
||||
f"SELECT * FROM diagonalley.order_details WHERE order_id = ?", (order_id,)
|
||||
|
|
@ -260,6 +264,7 @@ async def get_diagonalley_order_details(order_id: str) -> List[OrderDetail]:
|
|||
|
||||
return [OrderDetail(**row) for row in rows]
|
||||
|
||||
|
||||
async def get_diagonalley_order(order_id: str) -> Optional[Orders]:
|
||||
row = await db.fetchone(
|
||||
"SELECT * FROM diagonalley.orders WHERE id = ?", (order_id,)
|
||||
|
|
@ -282,18 +287,18 @@ async def get_diagonalley_orders(wallet_ids: Union[str, List[str]]) -> List[Orde
|
|||
async def delete_diagonalley_order(order_id: str) -> None:
|
||||
await db.execute("DELETE FROM diagonalley.orders WHERE id = ?", (order_id,))
|
||||
|
||||
|
||||
### Market/Marketplace
|
||||
|
||||
|
||||
async def get_diagonalley_markets(user: str) -> List[Market]:
|
||||
rows = await db.fetchall(
|
||||
'SELECT * FROM diagonalley.markets WHERE usr = ?', (user,)
|
||||
)
|
||||
rows = await db.fetchall("SELECT * FROM diagonalley.markets WHERE usr = ?", (user,))
|
||||
return [Market(**row) for row in rows]
|
||||
|
||||
|
||||
async def get_diagonalley_market(market_id: str) -> Optional[Market]:
|
||||
row = await db.fetchone(
|
||||
'SELECT * FROM diagonalley.markets WHERE id = ?', (market_id,)
|
||||
"SELECT * FROM diagonalley.markets WHERE id = ?", (market_id,)
|
||||
)
|
||||
Market(**row) if row else None
|
||||
|
||||
|
|
@ -303,5 +308,3 @@ async def get_diagonalley_market_stalls(market_id: str):
|
|||
"SELECT * FROM diagonalley.market_stalls WHERE marketid = ?", (market_id,)
|
||||
)
|
||||
return [Stalls(**row) for row in rows]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -111,4 +111,3 @@ async def m001_initial(db):
|
|||
);
|
||||
"""
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -55,12 +55,14 @@ class Zones(BaseModel):
|
|||
cost: int
|
||||
countries: str
|
||||
|
||||
|
||||
class OrderDetail(BaseModel):
|
||||
id: str
|
||||
order_id: str
|
||||
product_id: str
|
||||
quantity: int
|
||||
|
||||
|
||||
class createOrderDetails(BaseModel):
|
||||
product_id: str = Query(...)
|
||||
quantity: int = Query(..., ge=1)
|
||||
|
|
@ -95,11 +97,13 @@ class Orders(BaseModel):
|
|||
shipped: bool
|
||||
time: int
|
||||
|
||||
|
||||
class CreateMarket(BaseModel):
|
||||
usr: str = Query(...)
|
||||
name: str = Query(None)
|
||||
stalls: List[str] = Query(...)
|
||||
|
||||
|
||||
class Market(BaseModel):
|
||||
id: str
|
||||
usr: str
|
||||
|
|
|
|||
|
|
@ -9,26 +9,28 @@
|
|||
<h5 class="text-subtitle1 q-my-none">
|
||||
Diagon Alley: Decentralised Market-Stalls
|
||||
</h5>
|
||||
<p>
|
||||
Each Stall has its own keys!<br />
|
||||
<p>Each Stall has its own keys!<br /></p>
|
||||
|
||||
<ol>
|
||||
<li>Create Shipping Zones you're willing to ship to</li>
|
||||
<li>Create a Stall to list yiur products on</li>
|
||||
<li>Create products to put on the Stall</li>
|
||||
<li>List stalls on a simple frontend shop page, or point at Nostr shop client key</li>
|
||||
<li>
|
||||
List stalls on a simple frontend shop page, or point at Nostr shop
|
||||
client key
|
||||
</li>
|
||||
</ol>
|
||||
Make a list of products to sell, point your list of products at a public
|
||||
relay. Buyers browse your products on the relay, and pay you directly.
|
||||
Ratings are managed by the relay. Your stall can be listed in multiple
|
||||
relays, even over TOR, if you wish to be anonymous.<br />
|
||||
More information on the
|
||||
<a href="https://github.com/lnbits/Diagon-Alley"
|
||||
>Diagon Alley Protocol</a
|
||||
<a href="https://github.com/lnbits/Diagon-Alley">Diagon Alley Protocol</a
|
||||
><br />
|
||||
<small>
|
||||
Created by, <a href="https://github.com/benarc">Ben Arc</a></small
|
||||
>
|
||||
</p>
|
||||
<!-- </p> -->
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
</q-expansion-item>
|
||||
|
|
|
|||
|
|
@ -118,7 +118,12 @@
|
|||
>Create Product</q-btn
|
||||
>
|
||||
|
||||
<q-btn v-close-popup flat @click="resetDialog('productDialog')" color="grey" class="q-ml-auto"
|
||||
<q-btn
|
||||
v-close-popup
|
||||
flat
|
||||
@click="resetDialog('productDialog')"
|
||||
color="grey"
|
||||
class="q-ml-auto"
|
||||
>Cancel</q-btn
|
||||
>
|
||||
</div>
|
||||
|
|
@ -162,7 +167,12 @@
|
|||
>Create Shipping Zone</q-btn
|
||||
>
|
||||
|
||||
<q-btn v-close-popup flat @click="resetDialog('zoneDialog')" color="grey" class="q-ml-auto"
|
||||
<q-btn
|
||||
v-close-popup
|
||||
flat
|
||||
@click="resetDialog('zoneDialog')"
|
||||
color="grey"
|
||||
class="q-ml-auto"
|
||||
>Cancel</q-btn
|
||||
>
|
||||
</div>
|
||||
|
|
@ -205,7 +215,12 @@
|
|||
>Launch</q-btn
|
||||
>
|
||||
|
||||
<q-btn v-close-popup flat @click="resetDialog('marketDialog')" color="grey" class="q-ml-auto"
|
||||
<q-btn
|
||||
v-close-popup
|
||||
flat
|
||||
@click="resetDialog('marketDialog')"
|
||||
color="grey"
|
||||
class="q-ml-auto"
|
||||
>Cancel</q-btn
|
||||
>
|
||||
</div>
|
||||
|
|
@ -284,7 +299,9 @@
|
|||
v-model.trim="stallDialog.data.nostrShops"
|
||||
label="Nostr shop public keys (seperate by comma)"
|
||||
></q-input> -->
|
||||
<p><strong><small>Nostr support coming soon!</small></strong></p>
|
||||
<p>
|
||||
<strong><small>Nostr support coming soon!</small></strong>
|
||||
</p>
|
||||
<div class="row q-mt-lg">
|
||||
<q-btn
|
||||
v-if="stallDialog.data.id"
|
||||
|
|
@ -302,7 +319,12 @@
|
|||
type="submit"
|
||||
>Create Store</q-btn
|
||||
>
|
||||
<q-btn v-close-popup flat @click="resetDialog('stallDialog')" color="grey" class="q-ml-auto"
|
||||
<q-btn
|
||||
v-close-popup
|
||||
flat
|
||||
@click="resetDialog('stallDialog')"
|
||||
color="grey"
|
||||
class="q-ml-auto"
|
||||
>Cancel</q-btn
|
||||
>
|
||||
</div>
|
||||
|
|
@ -313,33 +335,50 @@
|
|||
<div class="col-12 col-md-8 col-lg-7 q-gutter-y-md">
|
||||
<q-card>
|
||||
<q-card-section>
|
||||
|
||||
<q-btn unelevated v-if="stalls.length > 0" color="primary" @click="productDialog.show = true"
|
||||
<q-btn
|
||||
unelevated
|
||||
v-if="stalls.length > 0"
|
||||
color="primary"
|
||||
@click="productDialog.show = true"
|
||||
>+ Product <q-tooltip> List a product </q-tooltip></q-btn
|
||||
>
|
||||
<q-btn unelevated v-else color="primary" @click="errorMessage('First set shipping zone(s), then create a stall.')"
|
||||
<q-btn
|
||||
unelevated
|
||||
v-else
|
||||
color="primary"
|
||||
@click="errorMessage('First set shipping zone(s), then create a stall.')"
|
||||
>+ Product <q-tooltip> List a product </q-tooltip></q-btn
|
||||
>
|
||||
<q-btn unelevated color="primary" @click="zoneDialog.show = true"
|
||||
>+ Shipping Zone<q-tooltip> Create a shipping zone </q-tooltip></q-btn
|
||||
>
|
||||
<q-btn unelevated v-if="zones.length > 0" color="primary" @click="openStallDialog()"
|
||||
<q-btn
|
||||
unelevated
|
||||
v-if="zones.length > 0"
|
||||
color="primary"
|
||||
@click="openStallDialog()"
|
||||
>+ Store
|
||||
<q-tooltip> Create a stall to list products on </q-tooltip></q-btn
|
||||
>
|
||||
<q-btn unelevated v-else color="primary" @click="errorMessage('First set shipping zone(s).')"
|
||||
<q-btn
|
||||
unelevated
|
||||
v-else
|
||||
color="primary"
|
||||
@click="errorMessage('First set shipping zone(s).')"
|
||||
>+ Store
|
||||
<q-tooltip> Create a store to list products on </q-tooltip></q-btn
|
||||
>
|
||||
<q-btn unelevated color="primary" @click="shopDialog.show = true"
|
||||
>Launch frontend shop (not Nostr)
|
||||
<q-tooltip> Makes a simple frontend shop for your stalls</q-tooltip></q-btn
|
||||
<q-tooltip>
|
||||
Makes a simple frontend shop for your stalls</q-tooltip
|
||||
></q-btn
|
||||
>
|
||||
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
|
||||
<q-card> <!-- ORDERS TABLE -->
|
||||
<q-card>
|
||||
<!-- ORDERS TABLE -->
|
||||
<q-card-section>
|
||||
<div class="row items-center no-wrap q-mb-md">
|
||||
<div class="col">
|
||||
|
|
@ -403,7 +442,8 @@
|
|||
</q-card-section>
|
||||
</q-card>
|
||||
|
||||
<q-card> <!-- PRODUCTS TABLE -->
|
||||
<q-card>
|
||||
<!-- PRODUCTS TABLE -->
|
||||
<q-card-section>
|
||||
<div class="row items-center no-wrap q-mb-md">
|
||||
<div class="col">
|
||||
|
|
@ -483,7 +523,8 @@
|
|||
</q-card-section>
|
||||
</q-card>
|
||||
|
||||
<q-card> <!-- STORES TABLE -->
|
||||
<q-card>
|
||||
<!-- STORES TABLE -->
|
||||
<q-card-section>
|
||||
<div class="row items-center no-wrap q-mb-md">
|
||||
<div class="col">
|
||||
|
|
@ -556,7 +597,8 @@
|
|||
</q-card-section>
|
||||
</q-card>
|
||||
|
||||
<q-card> <!-- ZONES TABLE -->
|
||||
<q-card>
|
||||
<!-- ZONES TABLE -->
|
||||
<q-card-section>
|
||||
<div class="row items-center no-wrap q-mb-md">
|
||||
<div class="col">
|
||||
|
|
@ -635,11 +677,15 @@
|
|||
<q-card-section class="q-pa-none">
|
||||
<q-separator></q-separator>
|
||||
|
||||
<div class="column q-ma-md q-pb-lg"
|
||||
style="height: 350px">
|
||||
<div class="column q-ma-md q-pb-lg" style="height: 350px">
|
||||
<div class="col q-pb-md">
|
||||
<q-select v-model="customerKey" style="width: 80%;"
|
||||
:options="customerKeys" label="Customers" @input="getMessages(customerKey)"></q-select>
|
||||
<q-select
|
||||
v-model="customerKey"
|
||||
style="width: 80%"
|
||||
:options="customerKeys"
|
||||
label="Customers"
|
||||
@input="getMessages(customerKey)"
|
||||
></q-select>
|
||||
</div>
|
||||
<div class="col-8 q-px-md">
|
||||
<div v-for="message in customerMessages">
|
||||
|
|
@ -648,10 +694,7 @@
|
|||
:text="[message[1]]"
|
||||
sent
|
||||
></q-chat-message>
|
||||
<q-chat-message
|
||||
v-else
|
||||
:text="[message[1]]"
|
||||
></q-chat-message>
|
||||
<q-chat-message v-else :text="[message[1]]"></q-chat-message>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col on-right" style="width: 90%">
|
||||
|
|
@ -666,12 +709,11 @@
|
|||
</q-card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- </div>
|
||||
</div> -->
|
||||
{% endblock %} {% block scripts %} {{ window_vars(user) }}
|
||||
<script src="https://cdn.jsdelivr.net/npm/pica@6.1.1/dist/pica.min.js"></script>
|
||||
<script>
|
||||
|
||||
Vue.component(VueQrcode.name, VueQrcode)
|
||||
|
||||
const pica = window.pica()
|
||||
|
|
@ -698,7 +740,7 @@ const mapKeys = obj => {
|
|||
return obj
|
||||
}
|
||||
|
||||
const humanReadableZones = (zones) => {
|
||||
const humanReadableZones = zones => {
|
||||
return zones.map(z => `${z.id} - ${z.countries}`)
|
||||
}
|
||||
|
||||
|
|
@ -971,11 +1013,9 @@ new Vue({
|
|||
LNbits.utils.notifyApiError(error)
|
||||
})
|
||||
},
|
||||
restoreKeys: function(){
|
||||
|
||||
},
|
||||
restoreKeys: function () {},
|
||||
capitalizeFirstLetter: function (string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
return string.charAt(0).toUpperCase() + string.slice(1)
|
||||
},
|
||||
errorMessage: function (error) {
|
||||
this.$q.notify({
|
||||
|
|
@ -1024,7 +1064,11 @@ new Vue({
|
|||
var link = _.findWhere(self.stalls, {id: linkId})
|
||||
this.zoneOptions = humanReadableZones(this.zones)
|
||||
this.stallDialog.data = _.clone(link._data)
|
||||
let shippingzones = this.zoneOptions.filter(z => this.stallDialog.data.shippingzones.split(",").includes(z.split("-")[0].trim()))
|
||||
let shippingzones = this.zoneOptions.filter(z =>
|
||||
this.stallDialog.data.shippingzones
|
||||
.split(',')
|
||||
.includes(z.split('-')[0].trim())
|
||||
)
|
||||
|
||||
this.stallDialog.data.shippingzones = shippingzones //this.stallDialog.data.shippingzones.split(",")
|
||||
|
||||
|
|
@ -1041,7 +1085,7 @@ new Vue({
|
|||
privatekey: this.stallDialog.data.privatekey,
|
||||
relays: this.stallDialog.data.relays,
|
||||
shippingzones: this.stallDialog.data.shippingzones
|
||||
.map(z => z.split("-")[0].trim())
|
||||
.map(z => z.split('-')[0].trim())
|
||||
.toString()
|
||||
}
|
||||
if (this.stallDialog.data.id) {
|
||||
|
|
@ -1135,7 +1179,7 @@ new Vue({
|
|||
self.g.user.wallets[0].inkey
|
||||
)
|
||||
.then(function (response) {
|
||||
console.log("RESP DATA", response.data)
|
||||
console.log('RESP DATA', response.data)
|
||||
if (response.data) {
|
||||
self.products = response.data.map(mapProducts)
|
||||
}
|
||||
|
|
@ -1149,7 +1193,9 @@ new Vue({
|
|||
var link = _.findWhere(self.products, {id: linkId})
|
||||
|
||||
self.productDialog.data = _.clone(link._data)
|
||||
self.productDialog.data.categories = self.productDialog.data.categories.split(",")
|
||||
self.productDialog.data.categories = self.productDialog.data.categories.split(
|
||||
','
|
||||
)
|
||||
|
||||
self.productDialog.show = true
|
||||
},
|
||||
|
|
@ -1225,7 +1271,7 @@ new Vue({
|
|||
let self = this
|
||||
const walletId = _.findWhere(this.stalls, {id: data.stall}).wallet
|
||||
|
||||
console.log("DATA", walletId, data)
|
||||
console.log('DATA', walletId, data)
|
||||
LNbits.api
|
||||
.request(
|
||||
'POST',
|
||||
|
|
@ -1233,12 +1279,12 @@ new Vue({
|
|||
_.findWhere(self.g.user.wallets, {id: walletId}).inkey,
|
||||
data
|
||||
)
|
||||
.then((response) => {
|
||||
.then(response => {
|
||||
console.log(response)
|
||||
self.products.push(mapProducts(response.data))
|
||||
self.resetDialog('productDialog')
|
||||
})
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
LNbits.utils.notifyApiError(error)
|
||||
})
|
||||
},
|
||||
|
|
@ -1256,11 +1302,11 @@ new Vue({
|
|||
_.findWhere(this.g.user.wallets, {id: walletId}).adminkey
|
||||
)
|
||||
.then(() => {
|
||||
this.products = _.reject(this.products, (obj) => {
|
||||
this.products = _.reject(this.products, obj => {
|
||||
return obj.id == productId
|
||||
})
|
||||
})
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
LNbits.utils.notifyApiError(error)
|
||||
})
|
||||
})
|
||||
|
|
@ -1284,7 +1330,6 @@ new Vue({
|
|||
if (response.data) {
|
||||
console.log(response)
|
||||
self.zones = response.data.map(mapZone)
|
||||
|
||||
}
|
||||
})
|
||||
.catch(function (error) {
|
||||
|
|
@ -1294,7 +1339,7 @@ new Vue({
|
|||
openZoneUpdateDialog: function (linkId) {
|
||||
var self = this
|
||||
var link = _.findWhere(self.zones, {id: linkId})
|
||||
countriesArray = link._data.countries.split(",")
|
||||
countriesArray = link._data.countries.split(',')
|
||||
for (let i = 0; i < countriesArray.length; i++) {
|
||||
countriesArray[i] = self.capitalizeFirstLetter(countriesArray[i])
|
||||
}
|
||||
|
|
@ -1393,12 +1438,12 @@ new Vue({
|
|||
'/diagonalley/api/v1/markets',
|
||||
this.g.user.wallets[0].inkey
|
||||
)
|
||||
.then((response) => {
|
||||
.then(response => {
|
||||
if (response.data) {
|
||||
this.shops = response.data.map(mapShops)
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
LNbits.utils.notifyApiError(error)
|
||||
})
|
||||
},
|
||||
|
|
@ -1455,13 +1500,13 @@ new Vue({
|
|||
this.g.user.wallets[0].inkey,
|
||||
data
|
||||
)
|
||||
.then((response) => {
|
||||
.then(response => {
|
||||
this.shops.push(mapShops(response.data))
|
||||
this.shopDialog.show = false
|
||||
this.shopDialog.data = {}
|
||||
data = {}
|
||||
})
|
||||
.catch((error) => {
|
||||
.catch(error => {
|
||||
LNbits.utils.notifyApiError(error)
|
||||
})
|
||||
},
|
||||
|
|
@ -1589,10 +1634,9 @@ new Vue({
|
|||
'cb4c0164fe03fcdadcbfb4f76611c71620790944c24f21a1cd119395cdedfe1b',
|
||||
'a9c17358a6dc4ceb3bb4d883eb87967a66b3453a0f3199f0b1c8eef8070c6a07'
|
||||
]
|
||||
console.log(_.pick(this.g.user, "id"))
|
||||
console.log(_.pick(this.g.user, 'id'))
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,10 +40,11 @@ async def display(request: Request, stall_id):
|
|||
{
|
||||
"request": request,
|
||||
"stall": stall,
|
||||
"products": [product.dict() for product in products]
|
||||
"products": [product.dict() for product in products],
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
# @diagonalley_ext.get("/market/{market_id}", response_class=HTMLResponse)
|
||||
# async def display(request: Request, stall_id):
|
||||
# stalls = await get_diagonalley_stall(stall_id)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ from uuid import uuid4
|
|||
from fastapi import Request
|
||||
from fastapi.param_functions import Query
|
||||
from fastapi.params import Depends
|
||||
from starlette.exceptions import HTTPException
|
||||
|
||||
from lnbits.core.crud import get_user
|
||||
from lnbits.core.services import create_invoice
|
||||
from lnbits.decorators import (
|
||||
|
|
@ -13,7 +15,6 @@ from lnbits.decorators import (
|
|||
require_admin_key,
|
||||
require_invoice_key,
|
||||
)
|
||||
from starlette.exceptions import HTTPException
|
||||
|
||||
from . import db, diagonalley_ext
|
||||
from .crud import (
|
||||
|
|
@ -392,15 +393,18 @@ async def api_diagonalley_stall_order(
|
|||
# MARKETS
|
||||
##
|
||||
|
||||
|
||||
@diagonalley_ext.get("/api/v1/markets")
|
||||
async def api_diagonalley_orders(
|
||||
wallet: WalletTypeInfo = Depends(get_key_type)
|
||||
):
|
||||
async def api_diagonalley_orders(wallet: WalletTypeInfo = Depends(get_key_type)):
|
||||
try:
|
||||
return [market.dict() for market in await get_diagonalley_markets(wallet.wallet.user)]
|
||||
return [
|
||||
market.dict()
|
||||
for market in await get_diagonalley_markets(wallet.wallet.user)
|
||||
]
|
||||
except:
|
||||
return {"message": "We could not retrieve the markets."}
|
||||
|
||||
|
||||
@diagonalley_ext.post("/api/v1/markets")
|
||||
@diagonalley_ext.put("/api/v1/markets/{market_id}")
|
||||
async def api_diagonalley_stall_create(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue