Skip to content

Commit

Permalink
Display total hours and starts if available (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwitkowski authored Aug 6, 2024
1 parent 383f532 commit bc4329a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 26 deletions.
23 changes: 14 additions & 9 deletions backend/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ def as_dict(self):
return {
"id": self.id,
"date": self.date.strftime("%Y-%m-%d"),
"creationDate": self.creation_datetime,
"url": self.offer_url,
"title": self.title,
"price": self.price,
"currency": self.currency,
"currency_code": self.currency_code,
"price": {
"amount": self.price,
"currency": self.currency,
"currency_code": self.currency_code
},
"hours": self.hours,
"starts": self.starts,
"location": self.location,
"aircraft_type": self.aircraft_type,
"manufacturer": self.manufacturer,
Expand Down Expand Up @@ -117,13 +120,15 @@ def get_exchange_rates_as_dict(session):
def convert_prices(offers, session):
exchange_rates = get_exchange_rates_as_dict(session)
for offer in offers:
offer["price_in_euro"] = offer["price"]
offer["exchange_rate"] = "1.0"
price = offer["price"]

if offer["currency_code"] and offer["currency_code"] != "EUR":
if price["currency_code"] and price["currency_code"] != "EUR":
# EZB exchange rates are base=EUR, quote=X
offer["price_in_euro"] = round(offer["price"] / exchange_rates[offer["currency_code"]], 2)
offer["exchange_rate"] = exchange_rates[offer["currency_code"]]
price["amount_in_euro"] = round(price["amount"] / exchange_rates[price["currency_code"]], 2)
price["exchange_rate"] = exchange_rates[price["currency_code"]]
else:
price["amount_in_euro"] = price["amount"]
price["exchange_rate"] = "1.0"
return offers


Expand Down
11 changes: 8 additions & 3 deletions backend/tests/test_db.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
from ddt import ddt, data
from decimal import Decimal

import tests.test__testcontainers_setup
import db
Expand All @@ -16,11 +17,15 @@ def test_should_store_and_fetch_offer(self):

# when
db.store_offer(sample_offer)
all_glider_offers = db.get_offers()

# then
all_gliders_in_db = db.get_offers()
self.assertEqual(len(all_gliders_in_db), 1)
self.assertEqual(all_gliders_in_db[0]["title"], "Glider A")
self.assertEqual(len(all_glider_offers), 1)
glider_offer = all_glider_offers[0]
self.assertEqual(glider_offer["title"], "Glider A")
self.assertEqual(glider_offer["price"]["amount"], Decimal("29500"))
self.assertEqual(glider_offer["price"]["currency"], "€")
self.assertEqual(glider_offer["price"]["currency_code"], "EUR")

def test_should_filter_offers_by_aircraft_type(self):
# given
Expand Down
9 changes: 6 additions & 3 deletions ui/src/components/OfferThumb.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
<small>{{ offer.date }}, {{ offer.location }}</small>
,
<small>
<strong>{{ formatPrice(offer.price, offer.currency_code) }}</strong>
<strong>{{ formatPrice(offer.price.amount, offer.price.currency_code) }}</strong>
</small>
</p>
<small>
<p v-if="offer.hours">Total: {{ offer.hours }}h, {{ offer.starts }} starts</p>
</small>
<small>
<p v-if="offer.manufacturer">
<router-link
:to="{
name: 'offer_details',
name: 'model_details',
params: { aircraftType: offer.aircraft_type, manufacturer: offer.manufacturer, model: offer.model }
}"
>
Expand Down Expand Up @@ -65,7 +68,7 @@ export default {
box-sizing: border-box;
small {
font-size: 12px;
color: #ee6c4d;
color: #cc6c4d;
}
}
Expand Down
8 changes: 6 additions & 2 deletions ui/src/components/__tests__/OfferThumb.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ describe('OfferThumb', () => {
location: 'Edlb, L\u00fcdinghausen, Nordrhein-Westfalen, Germany',
manufacturer: 'Rolladen Schneider',
model: 'LS4',
price: '28000.00',
price_in_euro: '28000.00',
price: {
amount: '28000.00',
amount_in_euro: '28000.00',
currency: '€',
currency_code: 'EUR'
},
title: 'LS-4',
url: 'https://www.segelflug.de/osclass/index.php?page=item&id=42370'
}
Expand Down
8 changes: 4 additions & 4 deletions ui/src/router/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createRouter, createWebHistory } from 'vue-router'
import OffersList from '../views/OffersList.vue'
import OfferDetails from '../views/OfferDetails.vue'
import ModelDetails from '../views/ModelDetails.vue'
import { nextTick } from 'vue'

const router = createRouter({
Expand Down Expand Up @@ -28,8 +28,8 @@ const router = createRouter({
},
{
path: '/:aircraftType/:manufacturer/:model',
name: 'offer_details',
component: OfferDetails,
name: 'model_details',
component: ModelDetails,
props: true
}
]
Expand All @@ -44,7 +44,7 @@ router.afterEach((to) => {
document.title = `${to.params.aircraftType.charAt(0).toUpperCase()}${to.params.aircraftType.slice(1)} offers`
break

case 'offer_details':
case 'model_details':
document.title = `${to.params.manufacturer} ${to.params.model} (${to.params.aircraftType}) offers`
break

Expand Down
15 changes: 10 additions & 5 deletions ui/src/views/OfferDetails.vue → ui/src/views/ModelDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@
<th>Date</th>
<th>Title</th>
<th>Location</th>
<th>Hours / starts</th>
<th>Price</th>
<th />
</tr>
<tr v-for="offer in offers.slice().reverse()" :key="offer.id">
<td>{{ offer.date }}</td>
<td>{{ offer.title }}</td>
<td>{{ offer.location }}</td>
<td>{{ formatPrice(offer.price, offer.currency_code) }}</td>
<td>
<div v-if="offer.hours">{{ offer.hours }}h, {{ offer.starts }} starts</div>
<div v-else>n/a</div>
</td>
<td>{{ formatPrice(offer.price.amount, offer.price.currency_code) }}</td>
<td>
<div class="icon">
<small>
Expand All @@ -52,7 +57,7 @@ import ChartistTooltip from 'chartist-plugin-tooltips-updated'
import { formatPrice, median } from '@/utils.js'
export default {
name: 'OfferDetails',
name: 'ModelDetails',
components: {},
props: {
Expand Down Expand Up @@ -119,14 +124,14 @@ export default {
let prices = []
for (let i = 0; i < this.offers.length; i += 1) {
const offer = this.offers[i]
if (!isNaN(offer.price_in_euro)) {
prices.push(Number(offer.price_in_euro))
if (!isNaN(offer.price.amount_in_euro)) {
prices.push(Number(offer.price.amount_in_euro))
}
const datapoint = {
meta: offer.title,
x: new Date(offer.date),
y: Number(offer.price_in_euro)
y: Number(offer.price.amount_in_euro)
}
if (this.dateAlreadyPresent(datapoint.x)) {
this.chartData.series.push([datapoint])
Expand Down

0 comments on commit bc4329a

Please sign in to comment.