make format diagonalley

This commit is contained in:
Tiago vasconcelos 2022-08-16 12:19:31 +01:00
parent 39bae68b1c
commit 58b046254f
8 changed files with 1037 additions and 978 deletions

View file

@ -1,10 +1,11 @@
import asyncio import asyncio
from fastapi import APIRouter from fastapi import APIRouter
from starlette.staticfiles import StaticFiles
from lnbits.db import Database from lnbits.db import Database
from lnbits.helpers import template_renderer from lnbits.helpers import template_renderer
from lnbits.tasks import catch_everything_and_restart from lnbits.tasks import catch_everything_and_restart
from starlette.staticfiles import StaticFiles
db = Database("ext_diagonalley") db = Database("ext_diagonalley")
@ -26,6 +27,7 @@ diagonalley_static_files = [
# ) # )
# else: # else:
def diagonalley_renderer(): def diagonalley_renderer():
return template_renderer(["lnbits/extensions/diagonalley/templates"]) return template_renderer(["lnbits/extensions/diagonalley/templates"])
# return template_renderer(["lnbits/extensions/diagonalley/templates"]) # return template_renderer(["lnbits/extensions/diagonalley/templates"])

View file

@ -235,7 +235,10 @@ async def create_diagonalley_order(wallet_id: str, data: createOrder) -> Orders:
assert link, "Newly created link couldn't be retrieved" assert link, "Newly created link couldn't be retrieved"
return link 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: for item in data:
item_id = urlsafe_short_hash() item_id = urlsafe_short_hash()
await db.execute( 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) order_details = await get_diagonalley_order_details(order_id)
return order_details return order_details
async def get_diagonalley_order_details(order_id: str) -> List[OrderDetail]: async def get_diagonalley_order_details(order_id: str) -> List[OrderDetail]:
rows = await db.fetchall( rows = await db.fetchall(
f"SELECT * FROM diagonalley.order_details WHERE order_id = ?", (order_id,) 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] return [OrderDetail(**row) for row in rows]
async def get_diagonalley_order(order_id: str) -> Optional[Orders]: async def get_diagonalley_order(order_id: str) -> Optional[Orders]:
row = await db.fetchone( row = await db.fetchone(
"SELECT * FROM diagonalley.orders WHERE id = ?", (order_id,) "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: async def delete_diagonalley_order(order_id: str) -> None:
await db.execute("DELETE FROM diagonalley.orders WHERE id = ?", (order_id,)) await db.execute("DELETE FROM diagonalley.orders WHERE id = ?", (order_id,))
### Market/Marketplace ### Market/Marketplace
async def get_diagonalley_markets(user: str) -> List[Market]: async def get_diagonalley_markets(user: str) -> List[Market]:
rows = await db.fetchall( rows = await db.fetchall("SELECT * FROM diagonalley.markets WHERE usr = ?", (user,))
'SELECT * FROM diagonalley.markets WHERE usr = ?', (user,)
)
return [Market(**row) for row in rows] return [Market(**row) for row in rows]
async def get_diagonalley_market(market_id: str) -> Optional[Market]: async def get_diagonalley_market(market_id: str) -> Optional[Market]:
row = await db.fetchone( 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 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,) "SELECT * FROM diagonalley.market_stalls WHERE marketid = ?", (market_id,)
) )
return [Stalls(**row) for row in rows] return [Stalls(**row) for row in rows]

View file

@ -111,4 +111,3 @@ async def m001_initial(db):
); );
""" """
) )

View file

@ -55,12 +55,14 @@ class Zones(BaseModel):
cost: int cost: int
countries: str countries: str
class OrderDetail(BaseModel): class OrderDetail(BaseModel):
id: str id: str
order_id: str order_id: str
product_id: str product_id: str
quantity: int quantity: int
class createOrderDetails(BaseModel): class createOrderDetails(BaseModel):
product_id: str = Query(...) product_id: str = Query(...)
quantity: int = Query(..., ge=1) quantity: int = Query(..., ge=1)
@ -95,11 +97,13 @@ class Orders(BaseModel):
shipped: bool shipped: bool
time: int time: int
class CreateMarket(BaseModel): class CreateMarket(BaseModel):
usr: str = Query(...) usr: str = Query(...)
name: str = Query(None) name: str = Query(None)
stalls: List[str] = Query(...) stalls: List[str] = Query(...)
class Market(BaseModel): class Market(BaseModel):
id: str id: str
usr: str usr: str

View file

@ -9,26 +9,28 @@
<h5 class="text-subtitle1 q-my-none"> <h5 class="text-subtitle1 q-my-none">
Diagon Alley: Decentralised Market-Stalls Diagon Alley: Decentralised Market-Stalls
</h5> </h5>
<p> <p>Each Stall has its own keys!<br /></p>
Each Stall has its own keys!<br />
<ol> <ol>
<li>Create Shipping Zones you're willing to ship to</li> <li>Create Shipping Zones you're willing to ship to</li>
<li>Create a Stall to list yiur products on</li> <li>Create a Stall to list yiur products on</li>
<li>Create products to put on the Stall</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> </ol>
Make a list of products to sell, point your list of products at a public 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. 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 Ratings are managed by the relay. Your stall can be listed in multiple
relays, even over TOR, if you wish to be anonymous.<br /> relays, even over TOR, if you wish to be anonymous.<br />
More information on the More information on the
<a href="https://github.com/lnbits/Diagon-Alley" <a href="https://github.com/lnbits/Diagon-Alley">Diagon Alley Protocol</a
>Diagon Alley Protocol</a
><br /> ><br />
<small> <small>
Created by, <a href="https://github.com/benarc">Ben Arc</a></small Created by, <a href="https://github.com/benarc">Ben Arc</a></small
> >
</p> <!-- </p> -->
</q-card-section> </q-card-section>
</q-card> </q-card>
</q-expansion-item> </q-expansion-item>

View file

@ -118,7 +118,12 @@
>Create Product</q-btn >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 >Cancel</q-btn
> >
</div> </div>
@ -162,7 +167,12 @@
>Create Shipping Zone</q-btn >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 >Cancel</q-btn
> >
</div> </div>
@ -205,7 +215,12 @@
>Launch</q-btn >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 >Cancel</q-btn
> >
</div> </div>
@ -284,7 +299,9 @@
v-model.trim="stallDialog.data.nostrShops" v-model.trim="stallDialog.data.nostrShops"
label="Nostr shop public keys (seperate by comma)" label="Nostr shop public keys (seperate by comma)"
></q-input> --> ></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"> <div class="row q-mt-lg">
<q-btn <q-btn
v-if="stallDialog.data.id" v-if="stallDialog.data.id"
@ -302,7 +319,12 @@
type="submit" type="submit"
>Create Store</q-btn >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 >Cancel</q-btn
> >
</div> </div>
@ -313,33 +335,50 @@
<div class="col-12 col-md-8 col-lg-7 q-gutter-y-md"> <div class="col-12 col-md-8 col-lg-7 q-gutter-y-md">
<q-card> <q-card>
<q-card-section> <q-card-section>
<q-btn
<q-btn unelevated v-if="stalls.length > 0" color="primary" @click="productDialog.show = true" unelevated
v-if="stalls.length > 0"
color="primary"
@click="productDialog.show = true"
>+ Product <q-tooltip> List a product </q-tooltip></q-btn >+ 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 >+ Product <q-tooltip> List a product </q-tooltip></q-btn
> >
<q-btn unelevated color="primary" @click="zoneDialog.show = true" <q-btn unelevated color="primary" @click="zoneDialog.show = true"
>+ Shipping Zone<q-tooltip> Create a shipping zone </q-tooltip></q-btn >+ 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 >+ Store
<q-tooltip> Create a stall to list products on </q-tooltip></q-btn <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 >+ Store
<q-tooltip> Create a store to list products on </q-tooltip></q-btn <q-tooltip> Create a store to list products on </q-tooltip></q-btn
> >
<q-btn unelevated color="primary" @click="shopDialog.show = true" <q-btn unelevated color="primary" @click="shopDialog.show = true"
>Launch frontend shop (not Nostr) >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-section>
</q-card> </q-card>
<q-card> <!-- ORDERS TABLE --> <q-card>
<!-- ORDERS TABLE -->
<q-card-section> <q-card-section>
<div class="row items-center no-wrap q-mb-md"> <div class="row items-center no-wrap q-mb-md">
<div class="col"> <div class="col">
@ -403,7 +442,8 @@
</q-card-section> </q-card-section>
</q-card> </q-card>
<q-card> <!-- PRODUCTS TABLE --> <q-card>
<!-- PRODUCTS TABLE -->
<q-card-section> <q-card-section>
<div class="row items-center no-wrap q-mb-md"> <div class="row items-center no-wrap q-mb-md">
<div class="col"> <div class="col">
@ -483,7 +523,8 @@
</q-card-section> </q-card-section>
</q-card> </q-card>
<q-card> <!-- STORES TABLE --> <q-card>
<!-- STORES TABLE -->
<q-card-section> <q-card-section>
<div class="row items-center no-wrap q-mb-md"> <div class="row items-center no-wrap q-mb-md">
<div class="col"> <div class="col">
@ -556,7 +597,8 @@
</q-card-section> </q-card-section>
</q-card> </q-card>
<q-card> <!-- ZONES TABLE --> <q-card>
<!-- ZONES TABLE -->
<q-card-section> <q-card-section>
<div class="row items-center no-wrap q-mb-md"> <div class="row items-center no-wrap q-mb-md">
<div class="col"> <div class="col">
@ -632,14 +674,18 @@
<q-card-section> <q-card-section>
<h6 class="text-subtitle1 q-my-none">Messages</h6> <h6 class="text-subtitle1 q-my-none">Messages</h6>
</q-card-section> </q-card-section>
<q-card-section class="q-pa-none" > <q-card-section class="q-pa-none">
<q-separator></q-separator> <q-separator></q-separator>
<div class="column q-ma-md q-pb-lg" <div class="column q-ma-md q-pb-lg" style="height: 350px">
style="height: 350px">
<div class="col q-pb-md"> <div class="col q-pb-md">
<q-select v-model="customerKey" style="width: 80%;" <q-select
:options="customerKeys" label="Customers" @input="getMessages(customerKey)"></q-select> v-model="customerKey"
style="width: 80%"
:options="customerKeys"
label="Customers"
@input="getMessages(customerKey)"
></q-select>
</div> </div>
<div class="col-8 q-px-md"> <div class="col-8 q-px-md">
<div v-for="message in customerMessages"> <div v-for="message in customerMessages">
@ -648,14 +694,11 @@
:text="[message[1]]" :text="[message[1]]"
sent sent
></q-chat-message> ></q-chat-message>
<q-chat-message <q-chat-message v-else :text="[message[1]]"></q-chat-message>
v-else
:text="[message[1]]"
></q-chat-message>
</div> </div>
</div> </div>
<div class="col on-right" style="width: 90%"> <div class="col on-right" style="width: 90%">
<q-input > <q-input>
<template v-slot:after> <template v-slot:after>
<q-btn round dense flat icon="send" /> <q-btn round dense flat icon="send" />
</template> </template>
@ -665,44 +708,43 @@
</q-card-section> </q-card-section>
</q-card> </q-card>
</div> </div>
</div>
</div>
</div> </div>
<!-- </div>
</div> -->
{% endblock %} {% block scripts %} {{ window_vars(user) }} {% endblock %} {% block scripts %} {{ window_vars(user) }}
<script src="https://cdn.jsdelivr.net/npm/pica@6.1.1/dist/pica.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/pica@6.1.1/dist/pica.min.js"></script>
<script> <script>
Vue.component(VueQrcode.name, VueQrcode)
Vue.component(VueQrcode.name, VueQrcode) const pica = window.pica()
const pica = window.pica() const mapStalls = obj => {
const mapStalls = obj => {
obj._data = _.clone(obj) obj._data = _.clone(obj)
return obj return obj
} }
const mapProducts = obj => { const mapProducts = obj => {
obj._data = _.clone(obj) obj._data = _.clone(obj)
console.log(obj) console.log(obj)
return obj return obj
} }
const mapZone = obj => { const mapZone = obj => {
obj._data = _.clone(obj) obj._data = _.clone(obj)
return obj return obj
} }
const mapOrders = obj => { const mapOrders = obj => {
obj._data = _.clone(obj) obj._data = _.clone(obj)
return obj return obj
} }
const mapKeys = obj => { const mapKeys = obj => {
obj._data = _.clone(obj) obj._data = _.clone(obj)
return obj return obj
} }
const humanReadableZones = (zones) => { const humanReadableZones = zones => {
return zones.map(z => `${z.id} - ${z.countries}`) return zones.map(z => `${z.id} - ${z.countries}`)
} }
new Vue({ new Vue({
el: '#vue', el: '#vue',
mixins: [windowMixin], mixins: [windowMixin],
data: function () { data: function () {
@ -922,7 +964,7 @@ new Vue({
}, },
zoneDialog: { zoneDialog: {
show: false, show: false,
data: {countries:[]} data: {countries: []}
}, },
marketDialog: { marketDialog: {
show: false, show: false,
@ -950,11 +992,11 @@ new Vue({
} }
}, },
methods: { methods: {
resetDialog(dialog){ resetDialog(dialog) {
this[dialog].show = false this[dialog].show = false
this[dialog].data = {} this[dialog].data = {}
}, },
generateKeys: function(){ generateKeys: function () {
var self = this var self = this
LNbits.api LNbits.api
.request( .request(
@ -971,11 +1013,9 @@ new Vue({
LNbits.utils.notifyApiError(error) LNbits.utils.notifyApiError(error)
}) })
}, },
restoreKeys: function(){ restoreKeys: function () {},
},
capitalizeFirstLetter: function (string) { capitalizeFirstLetter: function (string) {
return string.charAt(0).toUpperCase() + string.slice(1); return string.charAt(0).toUpperCase() + string.slice(1)
}, },
errorMessage: function (error) { errorMessage: function (error) {
this.$q.notify({ this.$q.notify({
@ -1024,9 +1064,13 @@ new Vue({
var link = _.findWhere(self.stalls, {id: linkId}) var link = _.findWhere(self.stalls, {id: linkId})
this.zoneOptions = humanReadableZones(this.zones) this.zoneOptions = humanReadableZones(this.zones)
this.stallDialog.data = _.clone(link._data) 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(",") this.stallDialog.data.shippingzones = shippingzones //this.stallDialog.data.shippingzones.split(",")
console.log(this.stallDialog.data) console.log(this.stallDialog.data)
//let zones = this.zoneOptions //let zones = this.zoneOptions
@ -1041,7 +1085,7 @@ new Vue({
privatekey: this.stallDialog.data.privatekey, privatekey: this.stallDialog.data.privatekey,
relays: this.stallDialog.data.relays, relays: this.stallDialog.data.relays,
shippingzones: this.stallDialog.data.shippingzones shippingzones: this.stallDialog.data.shippingzones
.map(z => z.split("-")[0].trim()) .map(z => z.split('-')[0].trim())
.toString() .toString()
} }
if (this.stallDialog.data.id) { if (this.stallDialog.data.id) {
@ -1135,7 +1179,7 @@ new Vue({
self.g.user.wallets[0].inkey self.g.user.wallets[0].inkey
) )
.then(function (response) { .then(function (response) {
console.log("RESP DATA", response.data) console.log('RESP DATA', response.data)
if (response.data) { if (response.data) {
self.products = response.data.map(mapProducts) self.products = response.data.map(mapProducts)
} }
@ -1149,7 +1193,9 @@ new Vue({
var link = _.findWhere(self.products, {id: linkId}) var link = _.findWhere(self.products, {id: linkId})
self.productDialog.data = _.clone(link._data) 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 self.productDialog.show = true
}, },
@ -1225,7 +1271,7 @@ new Vue({
let self = this let self = this
const walletId = _.findWhere(this.stalls, {id: data.stall}).wallet const walletId = _.findWhere(this.stalls, {id: data.stall}).wallet
console.log("DATA", walletId, data) console.log('DATA', walletId, data)
LNbits.api LNbits.api
.request( .request(
'POST', 'POST',
@ -1233,12 +1279,12 @@ new Vue({
_.findWhere(self.g.user.wallets, {id: walletId}).inkey, _.findWhere(self.g.user.wallets, {id: walletId}).inkey,
data data
) )
.then((response) => { .then(response => {
console.log(response) console.log(response)
self.products.push(mapProducts(response.data)) self.products.push(mapProducts(response.data))
self.resetDialog('productDialog') self.resetDialog('productDialog')
}) })
.catch((error) => { .catch(error => {
LNbits.utils.notifyApiError(error) LNbits.utils.notifyApiError(error)
}) })
}, },
@ -1256,11 +1302,11 @@ new Vue({
_.findWhere(this.g.user.wallets, {id: walletId}).adminkey _.findWhere(this.g.user.wallets, {id: walletId}).adminkey
) )
.then(() => { .then(() => {
this.products = _.reject(this.products, (obj) => { this.products = _.reject(this.products, obj => {
return obj.id == productId return obj.id == productId
}) })
}) })
.catch((error) => { .catch(error => {
LNbits.utils.notifyApiError(error) LNbits.utils.notifyApiError(error)
}) })
}) })
@ -1284,7 +1330,6 @@ new Vue({
if (response.data) { if (response.data) {
console.log(response) console.log(response)
self.zones = response.data.map(mapZone) self.zones = response.data.map(mapZone)
} }
}) })
.catch(function (error) { .catch(function (error) {
@ -1294,7 +1339,7 @@ new Vue({
openZoneUpdateDialog: function (linkId) { openZoneUpdateDialog: function (linkId) {
var self = this var self = this
var link = _.findWhere(self.zones, {id: linkId}) 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++) { for (let i = 0; i < countriesArray.length; i++) {
countriesArray[i] = self.capitalizeFirstLetter(countriesArray[i]) countriesArray[i] = self.capitalizeFirstLetter(countriesArray[i])
} }
@ -1386,19 +1431,19 @@ new Vue({
//////////////////////////////////////// ////////////////////////////////////////
//////////////////MARKET////////////////// //////////////////MARKET//////////////////
//////////////////////////////////////// ////////////////////////////////////////
getMarkets(){ getMarkets() {
LNbits.api LNbits.api
.request( .request(
'GET', 'GET',
'/diagonalley/api/v1/markets', '/diagonalley/api/v1/markets',
this.g.user.wallets[0].inkey this.g.user.wallets[0].inkey
) )
.then((response) => { .then(response => {
if (response.data) { if (response.data) {
this.shops = response.data.map(mapShops) this.shops = response.data.map(mapShops)
} }
}) })
.catch((error) => { .catch(error => {
LNbits.utils.notifyApiError(error) LNbits.utils.notifyApiError(error)
}) })
}, },
@ -1412,7 +1457,7 @@ new Vue({
sendShopFormData: function () { sendShopFormData: function () {
let data = {...this.marketDialog.data} let data = {...this.marketDialog.data}
if(!data.usr) { if (!data.usr) {
data.usr = this.g.user.id data.usr = this.g.user.id
} }
@ -1455,13 +1500,13 @@ new Vue({
this.g.user.wallets[0].inkey, this.g.user.wallets[0].inkey,
data data
) )
.then((response) => { .then(response => {
this.shops.push(mapShops(response.data)) this.shops.push(mapShops(response.data))
this.shopDialog.show = false this.shopDialog.show = false
this.shopDialog.data = {} this.shopDialog.data = {}
data = {} data = {}
}) })
.catch((error) => { .catch(error => {
LNbits.utils.notifyApiError(error) LNbits.utils.notifyApiError(error)
}) })
}, },
@ -1589,10 +1634,9 @@ new Vue({
'cb4c0164fe03fcdadcbfb4f76611c71620790944c24f21a1cd119395cdedfe1b', 'cb4c0164fe03fcdadcbfb4f76611c71620790944c24f21a1cd119395cdedfe1b',
'a9c17358a6dc4ceb3bb4d883eb87967a66b3453a0f3199f0b1c8eef8070c6a07' 'a9c17358a6dc4ceb3bb4d883eb87967a66b3453a0f3199f0b1c8eef8070c6a07'
] ]
console.log(_.pick(this.g.user, "id")) console.log(_.pick(this.g.user, 'id'))
} }
} }
}) })
</script> </script>
{% endblock %} {% endblock %}

View file

@ -40,10 +40,11 @@ async def display(request: Request, stall_id):
{ {
"request": request, "request": request,
"stall": stall, "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) # @diagonalley_ext.get("/market/{market_id}", response_class=HTMLResponse)
# async def display(request: Request, stall_id): # async def display(request: Request, stall_id):
# stalls = await get_diagonalley_stall(stall_id) # stalls = await get_diagonalley_stall(stall_id)

View file

@ -5,6 +5,8 @@ from uuid import uuid4
from fastapi import Request from fastapi import Request
from fastapi.param_functions import Query from fastapi.param_functions import Query
from fastapi.params import Depends from fastapi.params import Depends
from starlette.exceptions import HTTPException
from lnbits.core.crud import get_user from lnbits.core.crud import get_user
from lnbits.core.services import create_invoice from lnbits.core.services import create_invoice
from lnbits.decorators import ( from lnbits.decorators import (
@ -13,7 +15,6 @@ from lnbits.decorators import (
require_admin_key, require_admin_key,
require_invoice_key, require_invoice_key,
) )
from starlette.exceptions import HTTPException
from . import db, diagonalley_ext from . import db, diagonalley_ext
from .crud import ( from .crud import (
@ -94,7 +95,7 @@ async def api_diagonalley_products(
@diagonalley_ext.post("/api/v1/products") @diagonalley_ext.post("/api/v1/products")
@diagonalley_ext.put("/api/v1/products/{product_id}") @diagonalley_ext.put("/api/v1/products/{product_id}")
async def api_diagonalley_product_create( async def api_diagonalley_product_create(
data: createProduct, product_id = None, wallet: WalletTypeInfo = Depends(get_key_type) data: createProduct, product_id=None, wallet: WalletTypeInfo = Depends(get_key_type)
): ):
if product_id: if product_id:
@ -102,7 +103,7 @@ async def api_diagonalley_product_create(
if not product: if not product:
return {"message": "Withdraw product does not exist."} return {"message": "Withdraw product does not exist."}
stall = await get_diagonalley_stall(stall_id = product.stall) stall = await get_diagonalley_stall(stall_id=product.stall)
if stall.wallet != wallet.wallet.id: if stall.wallet != wallet.wallet.id:
return {"message": "Not your withdraw product."} return {"message": "Not your withdraw product."}
@ -392,15 +393,18 @@ async def api_diagonalley_stall_order(
# MARKETS # MARKETS
## ##
@diagonalley_ext.get("/api/v1/markets") @diagonalley_ext.get("/api/v1/markets")
async def api_diagonalley_orders( async def api_diagonalley_orders(wallet: WalletTypeInfo = Depends(get_key_type)):
wallet: WalletTypeInfo = Depends(get_key_type)
):
try: 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: except:
return {"message": "We could not retrieve the markets."} return {"message": "We could not retrieve the markets."}
@diagonalley_ext.post("/api/v1/markets") @diagonalley_ext.post("/api/v1/markets")
@diagonalley_ext.put("/api/v1/markets/{market_id}") @diagonalley_ext.put("/api/v1/markets/{market_id}")
async def api_diagonalley_stall_create( async def api_diagonalley_stall_create(