+ wishlist item is active
This commit is contained in:
@@ -36,7 +36,8 @@ class WishListMapper : FromDocumentMapper {
|
|||||||
reserveDoc.getString("name")
|
reserveDoc.getString("name")
|
||||||
) else null,
|
) else null,
|
||||||
updatedAt = it.getDate("updatedAt").toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(),
|
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(),
|
}.toMutableList(),
|
||||||
updatedAt = document.getDate("updatedAt").toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(),
|
updatedAt = document.getDate("updatedAt").toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(),
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ data class WishListItem(
|
|||||||
var price: Double,
|
var price: Double,
|
||||||
var link: String,
|
var link: String,
|
||||||
var images: MutableList<String> = mutableListOf(),
|
var images: MutableList<String> = mutableListOf(),
|
||||||
|
var isActive: Boolean,
|
||||||
var reservedBy: Reserve? = null,
|
var reservedBy: Reserve? = null,
|
||||||
var updatedAt: LocalDateTime = LocalDateTime.now(),
|
var updatedAt: LocalDateTime = LocalDateTime.now(),
|
||||||
var createdAt: LocalDateTime = LocalDateTime.now()
|
var createdAt: LocalDateTime = LocalDateTime.now()
|
||||||
@@ -35,5 +36,4 @@ data class WishListItem(
|
|||||||
data class Reserve(
|
data class Reserve(
|
||||||
val aid: String,
|
val aid: String,
|
||||||
val name: String? = null,
|
val name: String? = null,
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -48,8 +48,10 @@ class WishListService(
|
|||||||
val match = match(
|
val match = match(
|
||||||
Criteria.where("spaceDetails._id").`is`(ObjectId(spaceId))
|
Criteria.where("spaceDetails._id").`is`(ObjectId(spaceId))
|
||||||
.andOperator(
|
.andOperator(
|
||||||
Criteria.where("ownerDetails._id").`is`(ObjectId(user.id))
|
Criteria().orOperator(
|
||||||
.orOperator(Criteria.where("isPrivate").`is`(false))
|
Criteria.where("ownerDetails._id").`is`(ObjectId(user.id)),
|
||||||
|
Criteria.where("isPrivate").`is`(false)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -60,13 +62,14 @@ class WishListService(
|
|||||||
}.toList()
|
}.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getList(listId: String): WishList {
|
suspend fun getList(listId: String, isActive: Boolean = true): WishList {
|
||||||
val user = userService.getByUserNameWoPass(
|
val user = userService.getByUserNameWoPass(
|
||||||
ReactiveSecurityContextHolder.getContext().awaitSingle().authentication.name
|
ReactiveSecurityContextHolder.getContext().awaitSingle().authentication.name
|
||||||
)
|
)
|
||||||
val match = match(
|
val match = match(
|
||||||
Criteria.where("_id").`is`(ObjectId(listId))
|
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))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,19 @@
|
|||||||
package space.luminic.budgerapp.services
|
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.awaitSingle
|
||||||
import kotlinx.coroutines.reactor.awaitSingleOrNull
|
import kotlinx.coroutines.reactor.awaitSingleOrNull
|
||||||
import org.bson.Document
|
import org.bson.Document
|
||||||
import org.bson.types.ObjectId
|
import org.bson.types.ObjectId
|
||||||
import org.springframework.data.mongodb.core.ReactiveMongoTemplate
|
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.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
|
||||||
|
import org.springframework.data.mongodb.core.query.Criteria.expr
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import space.luminic.budgerapp.mappers.WishListMapper
|
import space.luminic.budgerapp.mappers.WishListMapper
|
||||||
import space.luminic.budgerapp.models.NotFoundException
|
import space.luminic.budgerapp.models.NotFoundException
|
||||||
@@ -27,7 +34,32 @@ class WishlistExternalService(
|
|||||||
val unwindSpace = unwind("spaceDetails")
|
val unwindSpace = unwind("spaceDetails")
|
||||||
val lookupOwner = lookup("users", "owner.\$id", "_id", "ownerDetails")
|
val lookupOwner = lookup("users", "owner.\$id", "_id", "ownerDetails")
|
||||||
val unwindOwner = unwind("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(
|
val match = match(
|
||||||
Criteria.where("_id").`is`(ObjectId(wishListId))
|
Criteria.where("_id").`is`(ObjectId(wishListId))
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -17,5 +17,4 @@ spring.datasource.url=jdbc:postgresql://213.183.51.243/familybudget_app
|
|||||||
spring.datasource.username=familybudget_app
|
spring.datasource.username=familybudget_app
|
||||||
spring.datasource.password=FB1q2w3e4r!
|
spring.datasource.password=FB1q2w3e4r!
|
||||||
|
|
||||||
|
|
||||||
telegram.bot.token = 6972242509:AAGyXuL3T-BNE4XMoo_qvtaYxw_SuiS_dDs
|
telegram.bot.token = 6972242509:AAGyXuL3T-BNE4XMoo_qvtaYxw_SuiS_dDs
|
||||||
@@ -4,13 +4,9 @@ server.port=8082
|
|||||||
#server.servlet.context-path=/api
|
#server.servlet.context-path=/api
|
||||||
spring.webflux.base-path=/api
|
spring.webflux.base-path=/api
|
||||||
|
|
||||||
spring.profiles.active=dev
|
spring.profiles.active=prod
|
||||||
spring.main.web-application-type=reactive
|
spring.main.web-application-type=reactive
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
logging.level.org.springframework.web=INFO
|
logging.level.org.springframework.web=INFO
|
||||||
logging.level.org.springframework.data = INFO
|
logging.level.org.springframework.data = INFO
|
||||||
logging.level.org.springframework.data.mongodb.core.ReactiveMongoTemplate=INFO
|
logging.level.org.springframework.data.mongodb.core.ReactiveMongoTemplate=INFO
|
||||||
|
|||||||
Reference in New Issue
Block a user