Skip to content

Commit

Permalink
Merge pull request #15 from FIAP-3SOAT-G15/add-logs
Browse files Browse the repository at this point in the history
Add logs
  • Loading branch information
wellyfrs authored May 19, 2024
2 parents 1a96fe5 + 0444dc0 commit 6500ed3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
uses: aws-actions/amazon-ecr-login@v2

- name: Build, tag, and push docker image to Amazon ECR
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
#if: github.ref == 'refs/heads/main' && github.event_name == 'push'
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ vars.AWS_ECR_REPO_NAME }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.fiap.stock.domain.errors.SelfOrderManagementException
import com.fiap.stock.usecases.CreateComponentUseCase
import com.fiap.stock.usecases.LoadComponentUseCase
import com.fiap.stock.usecases.SearchComponentUseCase
import org.slf4j.LoggerFactory

class ComponentService(
private val componentRepository: ComponentGateway,
Expand All @@ -18,6 +19,8 @@ class ComponentService(
) : LoadComponentUseCase,
SearchComponentUseCase,
CreateComponentUseCase {
private val log = LoggerFactory.getLogger(javaClass)

override fun getByComponentNumber(componentNumber: Long): Component {
return componentRepository.findByComponentNumber(componentNumber)
?: throw SelfOrderManagementException(
Expand Down Expand Up @@ -47,6 +50,7 @@ class ComponentService(
component: Component,
initialQuantity: Long,
): Component {
log.info("Creating component $component with initial quantity of $initialQuantity")
val savedComponent = componentRepository.create(component)
val stock = Stock(componentNumber = savedComponent.number!!, quantity = initialQuantity)
stockRepository.create(stock)
Expand Down
21 changes: 15 additions & 6 deletions src/main/kotlin/com/fiap/stock/usecases/services/ProductService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.fiap.stock.domain.errors.ErrorType
import com.fiap.stock.domain.errors.SelfOrderManagementException
import com.fiap.stock.domain.valueobjects.ProductCategory
import com.fiap.stock.usecases.*
import org.slf4j.LoggerFactory

class ProductService(
private val productRepository: ProductGateway,
Expand All @@ -15,6 +16,8 @@ class ProductService(
SearchProductUseCase,
AssembleProductsUseCase,
RemoveProductUseCase {
private val log = LoggerFactory.getLogger(javaClass)

override fun getByProductNumber(productNumber: Long): Product {
return productRepository.findByProductNumber(productNumber)
?: throw SelfOrderManagementException(
Expand All @@ -39,28 +42,34 @@ class ProductService(
product: Product,
components: List<Long>,
): Product {
val newProduct = product.copy(components = components.map(loadComponentUseCase::getByComponentNumber))
return productRepository.create(newProduct)
log.info("Creating product $product with components: $components")
return productRepository.create(
product.copy(components = components.map(loadComponentUseCase::getByComponentNumber))
)
}

override fun update(
product: Product,
components: List<Long>,
): Product {
val newProduct = product.copy(components = components.map(loadComponentUseCase::getByComponentNumber))
return productRepository.update(newProduct)
log.info("Updating product $product with components: $components")
return productRepository.update(
product.copy(components = components.map(loadComponentUseCase::getByComponentNumber))
)
}

override fun delete(productNumber: Long): Product {
log.info("Removing product [$productNumber]")
return productRepository.delete(productNumber)
}

override fun compose(
productNumber: Long,
subItemsNumbers: List<Long>,
subitemsNumbers: List<Long>,
): Product {
log.info("Composing product [$productNumber] with sub items numbers: $subitemsNumbers")
val product = getByProductNumber(productNumber)
val subItems = subItemsNumbers.map(::getByProductNumber)
val subItems = subitemsNumbers.map(::getByProductNumber)
val newProduct = product.copy(subItems = subItems)
return productRepository.update(newProduct)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import com.fiap.stock.domain.errors.ErrorType
import com.fiap.stock.domain.errors.SelfOrderManagementException
import com.fiap.stock.usecases.AdjustStockUseCase
import com.fiap.stock.usecases.LoadStockUseCase
import org.slf4j.LoggerFactory

class StockService(
private val stockRepository: StockGateway,
) : LoadStockUseCase,
AdjustStockUseCase {
private val log = LoggerFactory.getLogger(javaClass)

override fun getByComponentNumber(componentNumber: Long): Stock {
return stockRepository.findByComponentNumber(componentNumber)
?: throw SelfOrderManagementException(
Expand All @@ -23,6 +26,7 @@ class StockService(
componentNumber: Long,
quantity: Long,
): Stock {
log.info("Incrementing component [$componentNumber] by +$quantity")
val stock = getByComponentNumber(componentNumber)
return stockRepository.update(stock.copy(quantity = stock.quantity + quantity))
}
Expand All @@ -31,6 +35,7 @@ class StockService(
componentNumber: Long,
quantity: Long,
): Stock {
log.info("Decrementing component [$componentNumber] by -$quantity")
val stock = getByComponentNumber(componentNumber)
if (stock.hasSufficientInventory(quantity)) {
throw SelfOrderManagementException(
Expand Down

0 comments on commit 6500ed3

Please sign in to comment.