fix spaces

This commit is contained in:
xds
2025-02-18 16:16:43 +03:00
parent 2610eb0404
commit 5a689bcd95
8 changed files with 1125 additions and 1106 deletions

View File

@@ -0,0 +1,55 @@
package space.luminic.budgerapp.mappers
import com.mongodb.DBRef
import org.bson.Document
import org.springframework.stereotype.Component
import space.luminic.budgerapp.models.*
import java.time.ZoneId
@Component
class BudgetMapper : FromDocumentMapper {
override fun fromDocument(document: Document): Budget {
return Budget(
id = document.getObjectId("_id").toString(),
space = Space(id = document.get("spaceDetails", Document::class.java).getObjectId("_id").toString()),
name = document.getString("name"),
dateFrom = document.getDate("dateFrom").toInstant().atZone(ZoneId.systemDefault()).toLocalDate(),
dateTo = document.getDate("dateTo").toInstant().atZone(ZoneId.systemDefault()).toLocalDate(),
categories = document.getList("categories", Document::class.java).map { cat ->
val categoryDetailed = document.getList("categoriesDetails", Document::class.java).first {
it.getObjectId("_id").toString() == cat.get("category", DBRef::class.java).id.toString()
}
BudgetCategory(
category = Category(
id = cat.get("category", DBRef::class.java).id.toString(),
type = CategoryType(
categoryDetailed.get("type", Document::class.java).getString("code"),
categoryDetailed.get("type", Document::class.java).getString("name")
),
name = categoryDetailed.getString("name"),
description = categoryDetailed.getString("description"),
icon = categoryDetailed.getString("icon")
), currentLimit = cat.getDouble("currentLimit")
)
}.toMutableList(),
incomeCategories = document.getList("incomeCategories", Document::class.java).map { cat ->
val categoryDetailed =
document.getList("incomeCategoriesDetails", Document::class.java).first { it ->
it.getObjectId("_id").toString() == cat.get("category", DBRef::class.java).id.toString()
}
BudgetCategory(
category = Category(
id = cat.get("category", DBRef::class.java).id.toString(),
type = CategoryType(
categoryDetailed.get("type", Document::class.java).getString("code"),
categoryDetailed.get("type", Document::class.java).getString("name")
),
name = categoryDetailed.getString("name"),
description = categoryDetailed.getString("description"),
icon = categoryDetailed.getString("icon")
), currentLimit = cat.getDouble("currentLimit")
)
}.toMutableList()
)
}
}