Fixes tag serialization.

This commit is contained in:
Stefan Schallerl 2025-02-13 17:38:22 +01:00
parent b117439c4b
commit b0953a9d66
2 changed files with 10 additions and 3 deletions

View file

@ -45,7 +45,9 @@ value class Tag private constructor(val value: String) {
private val splitter = Regex("\\s+") private val splitter = Regex("\\s+")
fun of(value: String): Tag = fun of(value: String): Tag =
value.trim().let { v -> value.trim().let { v ->
require(v.matches(validator)) require(v.matches(validator)) {
"\"$value\" isn't a valid tag"
}
Tag(v.lowercase()) Tag(v.lowercase())
} }

View file

@ -52,11 +52,16 @@ private val tagSplitRegex = Regex("\\s+")
object TagAdapter { object TagAdapter {
fun parse(ser: String?): List<Tag> { fun parse(ser: String?): List<Tag> {
return ser?.trim()?.let { if (it.isNotBlank()) it.split(tagSplitRegex).map { Tag.of(it) } else emptyList() } return ser?.trim()?.let {
if (it.isNotBlank()) it
.split(tagSplitRegex)
.filter { it.isNotBlank() }
.map { Tag.of(it) } else emptyList()
}
?: emptyList() ?: emptyList()
} }
fun List<Tag>.serialize() = if (this.isEmpty()) "" else this.joinToString(",") { it.value } fun List<Tag>.serialize() = if (this.isEmpty()) "" else this.joinToString(" ") { it.value }
} }
fun List<Document>.grouped(): Map<Int, Map<Month, List<Document>>> = fun List<Document>.grouped(): Map<Int, Map<Month, List<Document>>> =