Skip to content

Commit

Permalink
fix: Minor bug fixes, remove ingredient
Browse files Browse the repository at this point in the history
  • Loading branch information
Lastaapps committed Jan 20, 2025
1 parent 471356d commit 05e61c8
Show file tree
Hide file tree
Showing 24 changed files with 118 additions and 131 deletions.
25 changes: 25 additions & 0 deletions .idea/runConfigurations/Generate_DB_migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024, Petr Laštovička as Lasta apps, All rights reserved
* Copyright 2025, Petr Laštovička as Lasta apps, All rights reserved
*
* This file is part of Menza.
*
Expand All @@ -23,7 +23,6 @@ import cz.lastaapps.api.core.domain.model.WeekDayDish
import cz.lastaapps.api.core.domain.model.WeekDish
import cz.lastaapps.api.core.domain.model.WeekDishCategory
import cz.lastaapps.menza.api.agata.data.model.dto.WeekDishDto
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
import kotlinx.datetime.LocalDate

Expand Down Expand Up @@ -64,5 +63,4 @@ private fun WeekDishDto.toDomain() =
amount = amount?.trim(),
priceNormal = null,
priceDiscounted = null,
ingredients = persistentListOf(),
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024, Petr Laštovička as Lasta apps, All rights reserved
* Copyright 2025, Petr Laštovička as Lasta apps, All rights reserved
*
* This file is part of Menza.
*
Expand Down Expand Up @@ -91,14 +91,13 @@ internal fun DishEntity.toDomain(
photoLink = dish.photoLink,
pictogram = pictograms.map(PictogramEntity::name).toImmutableList(),
servingPlaces =
servingPlaces
.map { entity ->
ServingPlace(
name = entity.name,
abbrev = entity.abbrev,
)
}.toImmutableList(),
ingredients = persistentListOf(),
servingPlaces
.map { entity ->
ServingPlace(
name = entity.name,
abbrev = entity.abbrev,
)
}.toImmutableList(),
isActive = isActive,
)
}
Expand Down Expand Up @@ -161,16 +160,16 @@ internal fun InfoEntity?.toDomain(
openingTimes = openingTimes.toDomain().toImmutableList(),
links = links.map { it.toDomain() }.toImmutableList(),
address =
address?.let {
Address(
location = address.address.let(::LocationName),
gps =
LatLong(
lat = address.lat.toFloat(),
long = address.long.toFloat(),
),
)
},
address?.let {
Address(
location = address.address.let(::LocationName),
gps =
LatLong(
lat = address.lat.toFloat(),
long = address.long.toFloat(),
),
)
},
)

private fun ContactEntity.toDomain() =
Expand All @@ -191,25 +190,25 @@ fun List<OpenTimeEntity>.toDomain() =
name = one.servingPlaceName,
abbrev = one.servingPlaceAbbrev,
types =
entities1
.groupBy { it.description }
.entries
.map { (description, entities2) ->
PlaceOpeningType(
description = description,
times =
entities2
.map {
PlaceOpeningTime(
startDay = it.dayFrom ?: DayOfWeek.MONDAY,
endDay = it.dayTo ?: it.dayFrom ?: DayOfWeek.MONDAY,
startTime = it.timeFrom,
endTime = it.timeTo,
)
}.sortedBy { it.startDay }
.toImmutableList(),
)
}.toImmutableList(),
entities1
.groupBy { it.description }
.entries
.map { (description, entities2) ->
PlaceOpeningType(
description = description,
times =
entities2
.map {
PlaceOpeningTime(
startDay = it.dayFrom ?: DayOfWeek.MONDAY,
endDay = it.dayTo ?: it.dayFrom ?: DayOfWeek.MONDAY,
startTime = it.timeFrom,
endTime = it.timeTo,
)
}.sortedBy { it.startDay }
.toImmutableList(),
)
}.toImmutableList(),
)
}

Expand All @@ -230,10 +229,10 @@ internal fun List<StrahovEntity>.toDomain(language: DataLanguage) =
nameShort = null,
name = value.groupName.trim(),
dishList =
values
.sortedBy { it.itemOrder }
.map { it.toDomain(language) }
.toImmutableList(),
values
.sortedBy { it.itemOrder }
.map { it.toDomain(language) }
.toImmutableList(),
)
}.toImmutableList()

Expand All @@ -250,6 +249,5 @@ private fun StrahovEntity.toDomain(language: DataLanguage) =
photoLink = photoLink,
pictogram = persistentListOf(),
servingPlaces = persistentListOf(),
ingredients = persistentListOf(),
isActive = true,
)
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ internal class BuffetScraperImpl : BuffetScraper {
type = type.removeHtml(),
name = name.removeHtml(),
price = price.toInt(),
ingredients = emptyList(),
order = index,
)
}.mapLeft {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024, Petr Laštovička as Lasta apps, All rights reserved
* Copyright 2025, Petr Laštovička as Lasta apps, All rights reserved
*
* This file is part of Menza.
*
Expand Down Expand Up @@ -39,7 +39,6 @@ internal object BuffetDatabaseFactory {
DishEntity.Adapter(
buffetAdapter = BuffetAdapter,
dayOfWeekAdapter = DayOfWeekAdapter,
ingredientsAdapter = StringListAdapter,
),
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024, Petr Laštovička as Lasta apps, All rights reserved
* Copyright 2025, Petr Laštovička as Lasta apps, All rights reserved
*
* This file is part of Menza.
*
Expand Down Expand Up @@ -38,7 +38,6 @@ private fun List<DishDayDto>.toEntity(buffet: BuffetType) =
type = dish.type,
name = dish.name,
price = dish.price.toLong(),
ingredients = dish.ingredients,
itemOrder = dish.order.toLong(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ internal fun List<DishEntity>.toDomainDays(menzaType: MenzaType.Buffet): List<Pa
photoLink = null,
pictogram = persistentListOf(),
servingPlaces = persistentListOf(),
ingredients = dish.ingredients.toImmutableList(),
isActive = true,
)
}.toPersistentList(),
Expand Down Expand Up @@ -111,7 +110,6 @@ internal fun List<DishEntity>.toDomainWeek(
amount = null,
priceNormal = dish.price.toFloat(),
priceDiscounted = null,
ingredients = dish.ingredients.toImmutableList(),
)
}.toPersistentList(),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023, Petr Laštovička as Lasta apps, All rights reserved
* Copyright 2025, Petr Laštovička as Lasta apps, All rights reserved
*
* This file is part of Menza.
*
Expand Down Expand Up @@ -30,6 +30,5 @@ internal data class DishDto(
val type: String,
val name: String,
val price: Int,
val ingredients: List<String>,
val order: Int,
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024, Petr Laštovička as Lasta apps, All rights reserved
* Copyright 2025, Petr Laštovička as Lasta apps, All rights reserved
*
* This file is part of Menza.
*
Expand Down Expand Up @@ -37,5 +37,5 @@ internal fun MenzaType.Buffet.toType(): BuffetType =
internal fun BuffetType.toMenzaType() =
when (this) {
BuffetType.FS -> FS
BuffetType.FEL -> FS
BuffetType.FEL -> FEL
}
5 changes: 2 additions & 3 deletions api/buffet/src/commonMain/sqldelight/buffet/Dish.sq
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ import kotlin.collections.List;
import kotlinx.datetime.DayOfWeek;
import kotlin.String;

-- Primary key is not used as they can put really anything there and I don't want to crash because of it
-- PRIMARY KEY (buffet, dayOfWeek, type)
CREATE TABLE DishEntity (
buffet TEXT AS BuffetType NOT NULL,
dayOfWeek INTEGER AS DayOfWeek NOT NULL,
type TEXT NOT NULL,
name TEXT NOT NULL,
price INTEGER NOT NULL,
ingredients TEXT AS List<String> NOT NULL,
itemOrder INTEGER NOT NULL
-- Primary key is not used as they can put really anything there and I don't want to crash because of it
-- PRIMARY KEY (buffet, dayOfWeek, type)
);

getForBuffet:
Expand Down
Binary file not shown.
22 changes: 22 additions & 0 deletions api/buffet/src/commonMain/sqldelight/migrations/1.sqm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import cz.lastaapps.api.buffet.domain.model.BuffetType;
import kotlin.collections.List;
import kotlinx.datetime.DayOfWeek;
import kotlin.String;

-- drop ingredients
CREATE TABLE DishEntityTmp(
buffet TEXT AS BuffetType NOT NULL,
dayOfWeek INTEGER AS DayOfWeek NOT NULL,
type TEXT NOT NULL,
name TEXT NOT NULL,
price INTEGER NOT NULL,
itemOrder INTEGER NOT NULL
);
INSERT INTO DishEntityTmp(
buffet, dayOfWeek, type, name, price, itemOrder
)
SELECT
buffet, dayOfWeek, type, name, price, itemOrder
FROM DishEntity;
DROP TABLE DishEntity;
ALTER TABLE DishEntityTmp RENAME TO DishEntity;
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ class BuffetScraperTest :
type shouldBe "Hlavní jídlo 2"
name shouldBe "Kuřecí steak s pikantní omáčkou, hranolky"
price shouldBe 139
ingredients shouldBe
listOf()
}

commonTest(fel, listOf(4, 4, 3, 3, 5))
Expand All @@ -106,8 +104,6 @@ class BuffetScraperTest :
type shouldBe "Hlavní jídlo 1"
name shouldBe "Plněný paprikový lusk, houskové knedlíky (rýže )"
price shouldBe 138
ingredients shouldBe
listOf()
}
}

Expand Down Expand Up @@ -136,8 +132,6 @@ class BuffetScraperTest :
type shouldBe "Hlavní jídlo 2"
name shouldBe "Smažený květák, vařené brambory, tatarská omáčka"
price shouldBe 139
ingredients shouldBe
listOf()
}

commonTest(fel, listOf(4, 4, 3, 3, 5))
Expand All @@ -146,8 +140,6 @@ class BuffetScraperTest :
type shouldBe "Hlavní jídlo 1"
name shouldBe "Smažená aljašská treska, bramborová kaše"
price shouldBe 136
ingredients shouldBe
listOf()
}
}

Expand Down Expand Up @@ -190,7 +182,7 @@ private fun commonTest(
// checks if all the html parts were successfully removed
buffet
.map { day ->
day.dishList.map { listOf(it.name, it.type, it.ingredients.toString()) }
day.dishList.map { listOf(it.name, it.type) }
}.flatten()
.flatten()
.forEach {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023, Petr Laštovička as Lasta apps, All rights reserved
* Copyright 2025, Petr Laštovička as Lasta apps, All rights reserved
*
* This file is part of Menza.
*
Expand Down Expand Up @@ -37,5 +37,4 @@ data class WeekDish(
val amount: String?,
val priceNormal: Float?,
val priceDiscounted: Float?,
val ingredients: ImmutableList<String>,
)
Loading

0 comments on commit 05e61c8

Please sign in to comment.