Skip to content

Instantly share code, notes, and snippets.

@srdelarosa
Created March 19, 2021 02:06
Show Gist options
  • Save srdelarosa/09f8c531a0b74a6b939e4131e40f8498 to your computer and use it in GitHub Desktop.
Save srdelarosa/09f8c531a0b74a6b939e4131e40f8498 to your computer and use it in GitHub Desktop.
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