+ wishlist item is active

This commit is contained in:
xds
2025-07-17 13:07:34 +03:00
parent 1bcbf5e53a
commit 2e054088ce
6 changed files with 44 additions and 13 deletions

View File

@@ -36,7 +36,8 @@ class WishListMapper : FromDocumentMapper {
reserveDoc.getString("name")
) else null,
updatedAt = it.getDate("updatedAt").toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(),
createdAt = it.getDate("createdAt").toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime()
createdAt = it.getDate("createdAt").toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(),
isActive = it.getBoolean("isActive")
)
}.toMutableList(),
updatedAt = document.getDate("updatedAt").toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(),

View File

@@ -27,6 +27,7 @@ data class WishListItem(
var price: Double,
var link: String,
var images: MutableList<String> = mutableListOf(),
var isActive: Boolean,
var reservedBy: Reserve? = null,
var updatedAt: LocalDateTime = LocalDateTime.now(),
var createdAt: LocalDateTime = LocalDateTime.now()
@@ -35,5 +36,4 @@ data class WishListItem(
data class Reserve(
val aid: String,
val name: String? = null,
)

View File

@@ -48,9 +48,11 @@ class WishListService(
val match = match(
Criteria.where("spaceDetails._id").`is`(ObjectId(spaceId))
.andOperator(
Criteria.where("ownerDetails._id").`is`(ObjectId(user.id))
.orOperator(Criteria.where("isPrivate").`is`(false))
Criteria().orOperator(
Criteria.where("ownerDetails._id").`is`(ObjectId(user.id)),
Criteria.where("isPrivate").`is`(false)
)
)
)
val aggregation = newAggregation(*(getLookupsAndUnwinds().toTypedArray()), match)
@@ -60,13 +62,14 @@ class WishListService(
}.toList()
}
suspend fun getList(listId: String): WishList {
suspend fun getList(listId: String, isActive: Boolean = true): WishList {
val user = userService.getByUserNameWoPass(
ReactiveSecurityContextHolder.getContext().awaitSingle().authentication.name
)
val match = match(
Criteria.where("_id").`is`(ObjectId(listId))
.andOperator(Criteria.where("ownerDetails._id").`is`(ObjectId(user.id)))
// .andOperator(Criteria.where("ownerDetails._id").`is`(ObjectId(user.id)))
.andOperator(Criteria.where("isActive").`is`(isActive))
)

View File

@@ -1,12 +1,19 @@
package space.luminic.budgerapp.services
import com.mongodb.client.model.Filters.and
import com.mongodb.client.model.Filters.eq
import kotlinx.coroutines.reactor.awaitSingle
import kotlinx.coroutines.reactor.awaitSingleOrNull
import org.bson.Document
import org.bson.types.ObjectId
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.AggregationOperation
import org.springframework.data.mongodb.core.aggregation.LookupOperation
import org.springframework.data.mongodb.core.aggregation.VariableOperators
import org.springframework.data.mongodb.core.query.Criteria
import org.springframework.data.mongodb.core.query.Criteria.expr
import org.springframework.stereotype.Service
import space.luminic.budgerapp.mappers.WishListMapper
import space.luminic.budgerapp.models.NotFoundException
@@ -27,7 +34,32 @@ class WishlistExternalService(
val unwindSpace = unwind("spaceDetails")
val lookupOwner = lookup("users", "owner.\$id", "_id", "ownerDetails")
val unwindOwner = unwind("ownerDetails")
val lookupItems = lookup("wishlistItems", "items.\$id", "_id", "itemsDetails")
// val lookupItems = lookup("wishlistItems", "items.\$id", "_id", "itemsDetails")
// Расширенный lookup с фильтром isActive == true
val lookupItems = AggregationOperation { context ->
Document(
"\$lookup", Document()
.append("from", "wishlistItems")
.append("let", Document("itemIds", "\$items.\$id"))
.append("pipeline", listOf(
Document(
"\$match", Document(
"\$expr", Document(
"\$and", listOf(
Document("\$in", listOf("\$_id", Document("\$map", Document()
.append("input", "\$\$itemIds")
.append("as", "id")
.append("in", Document("\$toObjectId", "\$\$id"))
))),
Document("\$eq", listOf("\$isActive", true))
)
)
)
)
))
.append("as", "itemsDetails")
)
}
val match = match(
Criteria.where("_id").`is`(ObjectId(wishListId))
)

View File

@@ -17,5 +17,4 @@ spring.datasource.url=jdbc:postgresql://213.183.51.243/familybudget_app
spring.datasource.username=familybudget_app
spring.datasource.password=FB1q2w3e4r!
telegram.bot.token = 6972242509:AAGyXuL3T-BNE4XMoo_qvtaYxw_SuiS_dDs

View File

@@ -4,13 +4,9 @@ server.port=8082
#server.servlet.context-path=/api
spring.webflux.base-path=/api
spring.profiles.active=dev
spring.profiles.active=prod
spring.main.web-application-type=reactive
logging.level.org.springframework.web=INFO
logging.level.org.springframework.data = INFO
logging.level.org.springframework.data.mongodb.core.ReactiveMongoTemplate=INFO