Created
January 10, 2021 12:39
Custom repository implementation for ProductRepositoryCustom
This file contains 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.api.reporting.respositories; | |
import com.api.reporting.models.Product; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.data.mongodb.core.MongoTemplate; | |
import org.springframework.data.mongodb.core.query.Criteria; | |
import org.springframework.data.mongodb.core.query.Query; | |
import java.util.List; | |
import java.util.Optional; | |
public class ProductRepositoryImpl implements ProductRepositoryCustom { | |
private static final String COLLECTION = "products"; | |
@Autowired | |
MongoTemplate mongoTemplate; | |
public Optional<List<Product>> findByName(String name) { | |
Query query = new Query().addCriteria(Criteria.where("name").is(name)); | |
List<Product> search = mongoTemplate.find(query, Product.class, COLLECTION); | |
return Optional.of(search); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment