Skip to content

Commit

Permalink
fix: New buffet format without ingredients
Browse files Browse the repository at this point in the history
  • Loading branch information
Lastaapps committed Jan 19, 2025
1 parent 5413c9b commit db5b4b3
Show file tree
Hide file tree
Showing 9 changed files with 558 additions and 2,841 deletions.
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 @@ -81,7 +81,7 @@ internal class BuffetScraperImpl : BuffetScraper {
// Matches dishes
// type name price contains
private val dishesRegex =
"""([^/]*):([^●]*)●\s*(\d+)[^(]*\(([^).]*)"""
"""([^/]*):([^●]*)●\s*(\d+)"""
.toRegex(regexOptions)
}

Expand Down Expand Up @@ -187,14 +187,19 @@ internal class BuffetScraperImpl : BuffetScraper {
dishesRegex
.findAll(this)
.mapIndexed { index, match ->
println("------------------------------------------")
println(match.groupValues.drop(1).joinToString(" ||| "))
println("------------------------------------------")

Either
.catch {
val (type, name, price, contains) = match.destructured
val (type, name, price) = match.destructured
println("$type $name $price")
DishDto(
type = type.removeHtml(),
name = name.removeHtml(),
price = price.toInt(),
ingredients = contains.split(",").map { it.removeHtml() },
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 @@ -31,6 +31,7 @@ import cz.lastaapps.api.core.domain.model.dish.DishID
import cz.lastaapps.core.util.extensions.findDayOfWeek
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toImmutableList
import kotlinx.collections.immutable.toPersistentList
import kotlinx.datetime.Clock
import kotlinx.datetime.DateTimeUnit
import kotlinx.datetime.DayOfWeek
Expand All @@ -45,31 +46,34 @@ internal fun List<DishEntity>.toDomainDays(menzaType: MenzaType.Buffet): List<Pa
.sortedBy { it.key }
.map { (dayOfWeek, dayDishList) ->
dayOfWeek to
dayDishList.map { dish ->
DishCategory(
nameShort = null,
name = dish.type,
dishList =
persistentListOf(
// each dish has it's own category
Dish(
menzaType,
id = DishID(dish.name),
language = Czech,
amount = null,
name = dish.name,
priceDiscounted = null,
priceNormal = dish.price.toFloat(),
allergens = null,
photoLink = null,
pictogram = persistentListOf(),
servingPlaces = persistentListOf(),
ingredients = dish.ingredients.toImmutableList(),
isActive = true,
),
),
)
}
dayDishList
.groupBy { it.type }
.map { (type, dishes) ->
DishCategory(
nameShort = null,
name = type,
dishList =
dishes
.map { dish ->
// each dish has it's own category
Dish(
menzaType,
id = DishID(dish.name),
language = Czech,
amount = null,
name = dish.name,
priceDiscounted = null,
priceNormal = dish.price.toFloat(),
allergens = null,
photoLink = null,
pictogram = persistentListOf(),
servingPlaces = persistentListOf(),
ingredients = dish.ingredients.toImmutableList(),
isActive = true,
)
}.toPersistentList(),
)
}
}

internal fun List<DishEntity>.toDomainWeek(
Expand All @@ -93,22 +97,24 @@ internal fun List<DishEntity>.toDomainWeek(
WeekDayDish(
date = date,
categories =
dayDishList
.map { dish ->
WeekDishCategory(
name = dish.type,
dishList =
persistentListOf(
// each dish has it's own category
WeekDish(
name = dish.name,
amount = null,
priceNormal = dish.price.toFloat(),
priceDiscounted = null,
ingredients = dish.ingredients.toImmutableList(),
),
),
)
}.toImmutableList(),
dayDishList
.groupBy { it.type }
.map { (type, dishes) ->
WeekDishCategory(
name = type,
dishList =
dishes
.map { dish ->
// each dish has it's own category
WeekDish(
name = dish.name,
amount = null,
priceNormal = dish.price.toFloat(),
priceDiscounted = null,
ingredients = dish.ingredients.toImmutableList(),
)
}.toPersistentList(),
)
}.toImmutableList(),
)
}.toImmutableList()
Loading

0 comments on commit db5b4b3

Please sign in to comment.