Created
March 19, 2021 02:06
-
-
Save srdelarosa/09f8c531a0b74a6b939e4131e40f8498 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.newhorizons.takeitnow.products.infrastructure.repository; | |
import com.newhorizons.takeitnow.products.application.mainmodule.dto.ProductDto; | |
import com.newhorizons.takeitnow.products.application.mainmodule.mapper.IProductMapper; | |
import com.newhorizons.takeitnow.products.domain.entity.Product; | |
import com.newhorizons.takeitnow.products.domain.repository.IProductRepository; | |
import com.newhorizons.takeitnow.products.infrastructure.crud.IProductCrudRepository; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.stereotype.Repository; | |
import java.util.List; | |
import java.util.Optional; | |
@Repository | |
public class ProductRepository implements IProductRepository { | |
@Autowired | |
private IProductCrudRepository productCrudRepository; | |
@Autowired | |
private IProductMapper productMapper; | |
public List<ProductDto> getAll(){ | |
List<Product> products = (List<Product>)productCrudRepository.findAll(); | |
return productMapper.toProductsDto(products); | |
} | |
public Optional<ProductDto> getProduct(long id){ | |
return productCrudRepository.findById(id).map(e -> productMapper.toProductDto(e)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment