Skip to content

Commit

Permalink
Add mock helper utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Koroliuk committed Jan 7, 2024
1 parent 32aea78 commit 636a664
Show file tree
Hide file tree
Showing 45 changed files with 289 additions and 295 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import com.invictoprojects.streetlyshop.persistence.AttributeValueRepository
import com.invictoprojects.streetlyshop.persistence.domain.model.Language
import com.invictoprojects.streetlyshop.persistence.domain.model.product.attribute.AttributeDefinition
import com.invictoprojects.streetlyshop.persistence.domain.model.product.attribute.AttributeValue
import com.invictoprojects.streetlyshop.util.toDTO
import com.invictoprojects.streetlyshop.web.controller.dto.AttributeDefinitionDTO
import com.invictoprojects.streetlyshop.web.controller.dto.toDTO
import com.invictoprojects.streetlyshop.web.controller.request.AddAttributeDefinitionRequest
import com.invictoprojects.streetlyshop.web.controller.request.UpdateAttributeNameRequest
import org.bson.types.ObjectId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.invictoprojects.streetlyshop.service
import com.invictoprojects.streetlyshop.persistence.ProductRepository
import com.invictoprojects.streetlyshop.persistence.impl.toObjectId
import com.invictoprojects.streetlyshop.service.model.AttributeSearchAggregation
import com.invictoprojects.streetlyshop.util.toDTO
import com.invictoprojects.streetlyshop.web.controller.dto.AttributeSearchDTO
import com.invictoprojects.streetlyshop.web.controller.dto.toDTO
import com.invictoprojects.streetlyshop.web.controller.request.AttributeSearchRequest
import org.springframework.stereotype.Service

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import com.invictoprojects.streetlyshop.persistence.CategoryRepository
import com.invictoprojects.streetlyshop.persistence.domain.model.Language
import com.invictoprojects.streetlyshop.persistence.domain.model.product.Category
import com.invictoprojects.streetlyshop.persistence.impl.toObjectId
import com.invictoprojects.streetlyshop.util.toDTO
import com.invictoprojects.streetlyshop.web.controller.dto.CategoryDTO
import com.invictoprojects.streetlyshop.web.controller.dto.toDTO
import com.invictoprojects.streetlyshop.web.controller.request.CreateCategoryRequest
import com.invictoprojects.streetlyshop.web.controller.request.UpdateCategoryNameRequest
import org.bson.types.ObjectId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import com.invictoprojects.streetlyshop.persistence.domain.model.product.content
import com.invictoprojects.streetlyshop.persistence.impl.toObjectId
import com.invictoprojects.streetlyshop.service.facade.AuthenticationFacade
import com.invictoprojects.streetlyshop.util.toAttribute
import com.invictoprojects.streetlyshop.util.toDTO
import com.invictoprojects.streetlyshop.web.controller.dto.ContentDTO
import com.invictoprojects.streetlyshop.web.controller.dto.toDTO
import com.invictoprojects.streetlyshop.web.controller.request.CreateContentRequest
import com.invictoprojects.streetlyshop.web.controller.request.UpdateContentRequest
import com.invictoprojects.streetlyshop.web.exception.UserNotAuthorizedException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import com.invictoprojects.streetlyshop.persistence.ExchangeRateRepository
import com.invictoprojects.streetlyshop.persistence.VariantRepository
import com.invictoprojects.streetlyshop.persistence.domain.model.Currency
import com.invictoprojects.streetlyshop.persistence.domain.model.product.variant.price.ExchangeRate
import com.invictoprojects.streetlyshop.util.toDTO
import com.invictoprojects.streetlyshop.web.controller.dto.ExchangeRateDTO
import com.invictoprojects.streetlyshop.web.controller.dto.toDTO
import com.invictoprojects.streetlyshop.web.controller.request.UpdateExchangeRateRequest
import com.invictoprojects.streetlyshop.web.exception.ExchangeRateNotFoundException
import org.springframework.data.repository.findByIdOrNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import com.invictoprojects.streetlyshop.persistence.MediaRepository
import com.invictoprojects.streetlyshop.persistence.domain.model.media.Media
import com.invictoprojects.streetlyshop.persistence.impl.toObjectId
import com.invictoprojects.streetlyshop.service.facade.AuthenticationFacade
import com.invictoprojects.streetlyshop.util.toDTO
import com.invictoprojects.streetlyshop.web.controller.dto.MediaDTO
import com.invictoprojects.streetlyshop.web.controller.dto.toDTO
import org.bson.types.ObjectId
import org.springframework.stereotype.Service
import org.springframework.web.multipart.MultipartFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import com.invictoprojects.streetlyshop.persistence.domain.model.order.OrderLine
import com.invictoprojects.streetlyshop.persistence.domain.model.order.OrderStatus
import com.invictoprojects.streetlyshop.persistence.impl.toObjectId
import com.invictoprojects.streetlyshop.service.facade.AuthenticationFacade
import com.invictoprojects.streetlyshop.util.toDTO
import com.invictoprojects.streetlyshop.web.controller.dto.OrderDTO
import com.invictoprojects.streetlyshop.web.controller.dto.OrderLineDTO
import com.invictoprojects.streetlyshop.web.controller.dto.toDTO
import com.invictoprojects.streetlyshop.web.controller.request.CreateOrderRequest
import com.invictoprojects.streetlyshop.web.controller.request.OrderLineRequest
import com.invictoprojects.streetlyshop.web.controller.request.UpdateOrderStatusRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import com.invictoprojects.streetlyshop.persistence.domain.model.product.Paginat
import com.invictoprojects.streetlyshop.persistence.domain.model.product.variant.VariantInfo
import com.invictoprojects.streetlyshop.persistence.impl.toObjectId
import com.invictoprojects.streetlyshop.service.model.ProductSearchAggregation
import com.invictoprojects.streetlyshop.util.toDTO
import com.invictoprojects.streetlyshop.util.toDecimal128
import com.invictoprojects.streetlyshop.web.controller.dto.PaginatedProductSearchDTO
import com.invictoprojects.streetlyshop.web.controller.dto.VariantInfoDTO
import com.invictoprojects.streetlyshop.web.controller.dto.toDTO
import com.invictoprojects.streetlyshop.web.controller.request.ProductSearchRequest
import org.springframework.stereotype.Service

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import com.invictoprojects.streetlyshop.persistence.domain.model.product.Product
import com.invictoprojects.streetlyshop.persistence.impl.toObjectId
import com.invictoprojects.streetlyshop.service.facade.AuthenticationFacade
import com.invictoprojects.streetlyshop.util.toAttribute
import com.invictoprojects.streetlyshop.util.toDTO
import com.invictoprojects.streetlyshop.web.controller.dto.AttributeDTO
import com.invictoprojects.streetlyshop.web.controller.dto.ProductDTO
import com.invictoprojects.streetlyshop.web.controller.dto.toDTO
import com.invictoprojects.streetlyshop.web.controller.request.CreateProductRequest
import com.invictoprojects.streetlyshop.web.controller.request.UpdateProductRequest
import com.invictoprojects.streetlyshop.web.exception.UserNotAuthorizedException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import com.invictoprojects.streetlyshop.persistence.domain.model.product.Review
import com.invictoprojects.streetlyshop.persistence.domain.model.product.variant.Variant
import com.invictoprojects.streetlyshop.persistence.impl.toObjectId
import com.invictoprojects.streetlyshop.service.facade.AuthenticationFacade
import com.invictoprojects.streetlyshop.util.toDTO
import com.invictoprojects.streetlyshop.web.controller.dto.ReviewDTO
import com.invictoprojects.streetlyshop.web.controller.dto.toDTO
import com.invictoprojects.streetlyshop.web.controller.request.AddReviewRequest
import org.bson.types.ObjectId
import org.springframework.stereotype.Service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import com.invictoprojects.streetlyshop.persistence.domain.model.product.variant
import com.invictoprojects.streetlyshop.persistence.impl.toObjectId
import com.invictoprojects.streetlyshop.service.facade.AuthenticationFacade
import com.invictoprojects.streetlyshop.util.toAttribute
import com.invictoprojects.streetlyshop.util.toDTO
import com.invictoprojects.streetlyshop.util.toDecimal128
import com.invictoprojects.streetlyshop.web.controller.dto.VariantDTO
import com.invictoprojects.streetlyshop.web.controller.dto.toDTO
import com.invictoprojects.streetlyshop.web.controller.request.CreateVariantRequest
import com.invictoprojects.streetlyshop.web.exception.UserNotAuthorizedException
import org.bson.types.ObjectId
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.invictoprojects.streetlyshop.util;
package com.invictoprojects.streetlyshop.util

import org.bson.types.Decimal128
import java.math.BigDecimal
Expand Down
Original file line number Diff line number Diff line change
@@ -1,215 +1,9 @@
package com.invictoprojects.streetlyshop.util

import com.invictoprojects.streetlyshop.persistence.domain.model.customer.Customer
import com.invictoprojects.streetlyshop.persistence.domain.model.media.Media
import com.invictoprojects.streetlyshop.persistence.domain.model.order.Order
import com.invictoprojects.streetlyshop.persistence.domain.model.order.OrderLine
import com.invictoprojects.streetlyshop.persistence.domain.model.product.Category
import com.invictoprojects.streetlyshop.persistence.domain.model.product.PaginatedProductSearch
import com.invictoprojects.streetlyshop.persistence.domain.model.product.Product
import com.invictoprojects.streetlyshop.persistence.domain.model.product.Review
import com.invictoprojects.streetlyshop.persistence.domain.model.product.attribute.Attribute
import com.invictoprojects.streetlyshop.persistence.domain.model.product.attribute.AttributeDefinition
import com.invictoprojects.streetlyshop.persistence.domain.model.product.attribute.AttributeSearch
import com.invictoprojects.streetlyshop.persistence.domain.model.product.attribute.AttributeValue
import com.invictoprojects.streetlyshop.persistence.domain.model.product.content.Content
import com.invictoprojects.streetlyshop.persistence.domain.model.product.variant.Stock
import com.invictoprojects.streetlyshop.persistence.domain.model.product.variant.Variant
import com.invictoprojects.streetlyshop.persistence.domain.model.product.variant.VariantInfo
import com.invictoprojects.streetlyshop.persistence.domain.model.product.variant.price.ExchangeRate
import com.invictoprojects.streetlyshop.persistence.domain.model.product.variant.price.Price
import com.invictoprojects.streetlyshop.persistence.impl.toObjectId
import com.invictoprojects.streetlyshop.service.toDTO
import com.invictoprojects.streetlyshop.web.controller.dto.*

fun AttributeDefinition.toDTO(): AttributeDefinitionDTO {
return AttributeDefinitionDTO(id.toString(), name, starred, searchable, priority, values?.map { it.toDTO() })
}

fun AttributeValue.toDTO(): AttributeValueDTO {
return AttributeValueDTO(id.toString(), name)
}

fun AttributeSearch.toDTO(): AttributeSearchDTO {
return AttributeSearchDTO(
id = id.toString(),
definition = definition.toDTO(),
values = values.map { it.toDTO() }
)
}

fun Attribute.toDTO(): AttributeDTO {
return AttributeDTO(
id = id.toString(),
valueId = valueId.toString(),
definition = definition?.toDTO(),
value = value?.toDTO()
)
}

fun Category.toDTO(): CategoryDTO {
return CategoryDTO(
id = id.toString(),
parentCategoryId = parentCategoryId?.toString(),
name = name,
subcategoryIds = subcategoryIds.map { it.toString() }.toMutableList(),
creationDate = creationDate,
modifiedDate = modifiedDate
)
}

fun Content.toDTO(): ContentDTO {
return ContentDTO(
id = id.toString(),
productId = productId.toString(),
name = name,
description = description,
variantIds = variantIds.map { it.toString() },
variants = variants.map { it.toDTO() },
attributes = attributes.map { it.toDTO() },
creationDate = creationDate,
modifiedDate = modifiedDate
)
}

fun Customer.toDTO(): CustomerDTO {
return CustomerDTO(
id = id.toString(),
name = name,
surname = surname,
middleName = middleName,
avatar = avatar,
phone = phone,
birthDay = birthDay,
gender = gender, nickname = nickname,
email = email,
registeredAt = registeredAt
)
}

fun ExchangeRate.toDTO(): ExchangeRateDTO {
return ExchangeRateDTO(
modifiedDate = modifiedDate,
rate = rate.bigDecimalValue()
)
}

fun Media.toDTO(): MediaDTO {
return MediaDTO(
id = id.toString(),
url = url,
uploadedBy = uploadedBy.toString(),
uploadDate = uploadDate
)
}

fun OrderLine.toDTO(): OrderLineDTO {
return OrderLineDTO(id = id.toString(), variantInfo = variantInfo.toDTO(), quantity = quantity)
}

fun Order.toDTO(): OrderDTO {
return OrderDTO(
id = id.toString(),
customerId = customerId.toString(),
customer = customer.toDTO(),
creationDate = creationDate,
modifiedDate = modifiedDate,
deliveryService = deliveryService,
city = city,
department = department,
recipientName = recipientName,
recipientSurname = recipientSurname,
recipientMiddleName = recipientMiddleName,
status = status,
lines = lines.map { it.toDTO() }
)
}
import com.invictoprojects.streetlyshop.web.controller.dto.AttributeDTO

fun AttributeDTO.toAttribute(): Attribute {
return Attribute(id = id.toObjectId(), valueId = valueId.toObjectId())
}

fun PaginatedProductSearch.toDTO(): PaginatedProductSearchDTO {
return PaginatedProductSearchDTO(
paginatedResults = paginatedResults.map { it.toDTO() }.toMutableList(),
totalCount = totalCount
)
}

fun VariantInfo.toDTO(): VariantInfoDTO {
return VariantInfoDTO(
contentId = contentId.toString(),
productId = productId.toString(),
product = product.toDTO(),
name = name,
description = description,
attributes = attributes.map { it.toDTO() }.toMutableList(),
variantIds = variantIds.map { it.toString() }.toMutableList(),
variants = variants.toDTO(),
languageCode = languageCode,
creationDate = creationDate,
modifiedDate = modifiedDate,
createdBy = createdBy.toString()
)
}

fun Product.toDTO(): ProductDTO {
return ProductDTO(
id = id.toString(),
categoryId = categoryId.toString(),
category = category?.toDTO(),
creationDate = creationDate,
modifiedDate = modifiedDate,
contentIds = contentIds.map { it.toString() },
contents = contents.map { it.toDTO() },
attributes = attributes.map { it.toDTO() },
status = status,
rating = rating,
reviewCount = reviewCount,
reviewIds = reviewIds.map { it.toString() },
reviews = reviews.map { it.toDTO() },
favoriteCount = favoriteCount
)
}

fun Review.toDTO(): ReviewDTO {
return ReviewDTO(
id = id.toString(),
productId = productId.toString(),
contentId = contentId.toString(),
variantId = variantId.toString(),
createdBy = createdBy.toString(),
customerName = customerName,
customerAvatar = customerAvatar,
creationDate = creationDate,
medias = medias.map { it.toDTO() }.toMutableList(),
text = text,
rating = rating
)
}

fun Variant.toDTO(): VariantDTO {
return VariantDTO(
id = id.toString(),
barcode = barcode,
productId = productId.toString(),
contentId = contentId.toString(),
medias = medias,
attributes = attributes.map { it.toDTO() },
creationDate = creationDate,
modifiedDate = modifiedDate,
prices = prices.mapValues { (_, price) -> price.toDTO() },
stock = stock.toDTO()
)
}

fun Price.toDTO(): PriceDTO {
return PriceDTO(salePrice = salePrice.bigDecimalValue(), originalPrice = originalPrice.bigDecimalValue())
}

fun Stock.toDTO(): StockDTO {
return StockDTO(quantity)
}



Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
package com.invictoprojects.streetlyshop.web.controller.dto

import com.invictoprojects.streetlyshop.persistence.domain.model.product.attribute.Attribute

data class AttributeDTO(
var id: String,
var valueId: String,
var definition: AttributeDefinitionDTO? = null,
var value: AttributeValueDTO? = null
)

fun Attribute.toDTO(): AttributeDTO {
return AttributeDTO(
id = id.toString(),
valueId = valueId.toString(),
definition = definition?.toDTO(),
value = value?.toDTO()
)
}
Loading

0 comments on commit 636a664

Please sign in to comment.