fix date to localdate
This commit is contained in:
@@ -124,6 +124,8 @@ class SpaceController(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@GetMapping("/{spaceId}/transactions/{id}")
|
||||
fun getTransaction(
|
||||
@PathVariable spaceId: String,
|
||||
|
||||
@@ -15,6 +15,14 @@ import java.time.LocalDate
|
||||
@Repository
|
||||
interface BudgetRepo: ReactiveMongoRepository<Budget, String> {
|
||||
|
||||
|
||||
// @Id var id: String? = null,
|
||||
// @DBRef var space: Space? = null,
|
||||
// var name: String,
|
||||
// var dateFrom: LocalDate,
|
||||
// var dateTo: LocalDate,
|
||||
|
||||
|
||||
override fun findAll(sort: Sort): Flux<Budget>
|
||||
|
||||
fun findByDateFromLessThanEqualAndDateToGreaterThanEqual(dateOne: LocalDate, dateTwo: LocalDate): Mono<Budget>
|
||||
@@ -26,6 +34,6 @@ interface BudgetRepo: ReactiveMongoRepository<Budget, String> {
|
||||
@Query("{ 'space': { '\$ref': 'spaces','\$id': ?0 } }")
|
||||
fun findBySpaceId(spaceId: ObjectId, sort: Sort): Flux<Budget>
|
||||
|
||||
@Query("{ 'space': { '\$ref': 'spaces','\$id': ?0 } }")
|
||||
@Query("{ 'space': { '\$ref': 'spaces','\$id': ?0 }, }", fields = "{'id': 1, 'name':1, 'dateFrom':1, 'dateTo':1}")
|
||||
fun findBySpaceId(spaceId: ObjectId): Flux<Budget>
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import org.springframework.data.domain.Sort
|
||||
import org.springframework.data.domain.Sort.Direction
|
||||
import org.springframework.data.mongodb.core.MongoTemplate
|
||||
import org.springframework.data.mongodb.core.ReactiveMongoTemplate
|
||||
import org.springframework.data.mongodb.core.aggregation.Aggregation
|
||||
import org.springframework.data.mongodb.core.aggregation.Aggregation.*
|
||||
import org.springframework.data.mongodb.core.aggregation.DateOperators.DateToString
|
||||
import org.springframework.data.mongodb.core.query.Criteria
|
||||
@@ -222,7 +223,7 @@ class FinancialService(
|
||||
|
||||
println("Space ID type: ${spaceObjectId::class.java}, value: $spaceObjectId")
|
||||
// Применяем сортировку к запросу
|
||||
budgetRepo.findBySpaceId(spaceObjectId, sort).collectList()
|
||||
findProjectedBudgets(spaceObjectId).collectList()
|
||||
}
|
||||
|
||||
|
||||
@@ -230,6 +231,17 @@ class FinancialService(
|
||||
}
|
||||
}
|
||||
}
|
||||
fun findProjectedBudgets(spaceId: ObjectId): Flux<Budget> {
|
||||
val lookupSpaces = lookup("spaces", "space.\$id", "_id", "spaceDetails")
|
||||
|
||||
val matchStage = Aggregation.match(Criteria.where("spaceDetails._id").`is`(spaceId))
|
||||
// matchCriteria.add(Criteria.where("spaceDetails._id").`is`(ObjectId(spaceId)))
|
||||
val projectStage = Aggregation.project("_id", "name", "dateFrom", "dateTo") // Оставляем только нужные поля
|
||||
val sort = sort(Sort.by(Sort.Order.desc("_id")))
|
||||
val aggregation = Aggregation.newAggregation(lookupSpaces, matchStage, projectStage, sort)
|
||||
|
||||
return reactiveMongoTemplate.aggregate(aggregation, "budgets", Budget::class.java)
|
||||
}
|
||||
|
||||
// @Cacheable("budgets", key = "#id")
|
||||
fun getBudget(id: String): Mono<BudgetDTO> {
|
||||
|
||||
@@ -15,6 +15,7 @@ logging.level.org.springframework.data.mongodb.core.ReactiveMongoTemplate=INFO
|
||||
logging.level.org.springframework.security = INFO
|
||||
logging.level.org.springframework.data.mongodb.code = INFO
|
||||
logging.level.org.springframework.web.reactive=INFO
|
||||
logging.level.org.mongodb.driver.protocol.command = INFO
|
||||
|
||||
server.compression.enabled=true
|
||||
server.compression.mime-types=application/json
|
||||
|
||||
Reference in New Issue
Block a user