Add /market/:id route

This commit is contained in:
ekzyis 2023-11-08 23:52:28 +01:00
parent 8d5aad5744
commit 55afc3b097
6 changed files with 63 additions and 17 deletions

View File

@ -48,7 +48,7 @@ func HandleMarket(sc context.ServerContext) echo.HandlerFunc {
"NoShare": shares[1],
"Orders": orders,
}
return sc.Render(c, http.StatusOK, "market.html", data)
return c.JSON(http.StatusOK, data)
}
}

View File

@ -41,6 +41,7 @@ func addFrontendRoutes(e *echo.Echo, sc ServerContext) {
func addBackendRoutes(e *echo.Echo, sc ServerContext) {
GET(e, sc, "/api/markets", handler.HandleMarkets)
GET(e, sc, "/api/market/:id", handler.HandleMarket)
GET(e, sc, "/api/login", handler.HandleLogin)
GET(e, sc, "/api/login/callback", handler.HandleLoginCallback)
POST(e, sc, "/api/logout", handler.HandleLogout)

View File

@ -0,0 +1,32 @@
<template>
<!-- eslint-disable -->
<div class="my-3">
<pre>
_ _
_ __ ___ __ _ _ __| | _____| |_
| '_ ` _ \ / _` | '__| |/ / _ \ __|
| | | | | | (_| | | | ( __/ |_
|_| |_| |_|\__,_|_| |_|\_\___|\__|</pre>
</div>
<div class="font-mono">{{ market.Description }}</div>
<!-- eslint-enable -->
</template>
<script setup>
import { ref } from 'vue'
import { useRoute } from 'vue-router'
const route = useRoute()
const marketId = route.params.id
const market = ref(null)
const url = '/api/market/' + marketId
await fetch(url)
.then(r => r.json())
.then(body => {
market.value = body
})
.catch(console.error)
</script>

View File

@ -5,19 +5,23 @@ import App from './App.vue'
import './registerServiceWorker'
import './index.css'
import MarketView from '@/views/MarketView'
import MarketsView from '@/views/MarketsView'
import LoginView from '@/views/LoginView'
import UserView from '@/views/UserView'
import MarketView from '@/views/MarketView'
const routes = [
{
path: '/', component: MarketView
path: '/', component: MarketsView
},
{
path: '/login', component: LoginView
},
{
path: '/user', component: UserView
},
{
path: '/market/:id', component: MarketView
}
]
const router = VueRouter.createRouter({

View File

@ -1,21 +1,9 @@
<template>
<!-- eslint-disable -->
<div class="my-3">
<pre>
_ _ _ _
__| | ___| |_ __ | |__ (_)
/ _` |/ _ \ | '_ \| '_ \| |
| (_| | __/ | |_) | | | | |
\__,_|\___|_| .__/|_| |_|_|
|_|.market </pre>
</div>
<!-- eslint-enable -->
<Suspense>
<MarketList />
<Market />
</Suspense>
</template>
<script setup>
import MarketList from '@/components/MarketList'
import Market from '@/components/Market'
</script>

View File

@ -0,0 +1,21 @@
<template>
<!-- eslint-disable -->
<div class="my-3">
<pre>
_ _ _ _
__| | ___| |_ __ | |__ (_)
/ _` |/ _ \ | '_ \| '_ \| |
| (_| | __/ | |_) | | | | |
\__,_|\___|_| .__/|_| |_|_|
|_|.market </pre>
</div>
<!-- eslint-enable -->
<Suspense>
<MarketList />
</Suspense>
</template>
<script setup>
import MarketList from '@/components/MarketList'
</script>