Commit 2c27ce40 authored by Jakub Balga's avatar Jakub Balga
Browse files

Remaining service methods moved

parent 361d2db1
Pipeline #130903 passed with stages
in 1 minute and 58 seconds
package cz.muni.fi.pa165.winery.persistence.dao.wine;
import cz.muni.fi.pa165.winery.persistence.dao.DaoBase;
import cz.muni.fi.pa165.winery.persistence.entities.ProductReview;
import cz.muni.fi.pa165.winery.persistence.entities.WineBottle;
import java.util.List;
/**
* @author Michaela Korenkova
*/
public interface WineBottleDao extends DaoBase<WineBottle> {
List<WineBottle> getAll(double minPrice, double maxPrice);
List<WineBottle> getAllOnStock();
}
package cz.muni.fi.pa165.winery.persistence.dao.wine;
import cz.muni.fi.pa165.winery.exceptions.WineryDataAccessException;
import cz.muni.fi.pa165.winery.persistence.dao.DaoBaseImpl;
import cz.muni.fi.pa165.winery.persistence.entities.ProductReview;
import cz.muni.fi.pa165.winery.persistence.entities.WineBottle;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @author Michaela Korenkova
*/
......@@ -12,4 +16,27 @@ public class WineBottleDaoImpl extends DaoBaseImpl<WineBottle> implements WineBo
public WineBottleDaoImpl() {
super(WineBottle.class);
}
public List<WineBottle> getAll(double minPrice, double maxPrice) {
try {
return entityManager.createQuery("select entity from " + WineBottle.class.getName()
+ " entity " + "where entity.price >= " + minPrice + " and " +
"entity.price <= " + maxPrice, WineBottle.class)
.getResultList();
}
catch (Exception ex) {
throw new WineryDataAccessException(ex.getMessage(), ex);
}
}
public List<WineBottle> getAllOnStock() {
try {
return entityManager.createQuery("select entity from " + WineBottle.class.getName()
+ " entity " + "where entity.stock > 0 ", WineBottle.class)
.getResultList();
}
catch (Exception ex) {
throw new WineryDataAccessException(ex.getMessage(), ex);
}
}
}
\ No newline at end of file
package cz.muni.fi.pa165.winery.persistence.dao.wine;
import cz.muni.fi.pa165.winery.persistence.dao.DaoBase;
import cz.muni.fi.pa165.winery.persistence.entities.ProductReview;
import cz.muni.fi.pa165.winery.persistence.entities.WineType;
import java.util.List;
/**
* @author Jakub Balga
*/
public interface WineTypeDao extends DaoBase<WineType> {
List<WineType> getAllByGrape(long id);
}
package cz.muni.fi.pa165.winery.persistence.dao.wine;
import cz.muni.fi.pa165.winery.exceptions.WineryDataAccessException;
import cz.muni.fi.pa165.winery.persistence.dao.DaoBaseImpl;
import cz.muni.fi.pa165.winery.persistence.entities.ProductReview;
import cz.muni.fi.pa165.winery.persistence.entities.WineType;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @author Jakub Balga
*/
......@@ -14,5 +18,14 @@ public class WineTypeDaoImpl extends DaoBaseImpl<WineType> implements WineTypeDa
super(WineType.class);
}
public List<WineType> getAllByGrape(long id) {
try {
return entityManager.createQuery("select entity from " + WineType.class.getName()
+ " entity " + "where entity.grape = " + id, WineType.class)
.getResultList();
}
catch (Exception ex) {
throw new WineryDataAccessException(ex.getMessage(), ex);
}
}
}
package cz.muni.fi.pa165.winery.services.wine;
import cz.muni.fi.pa165.winery.dto.wine.WineBottleDto;
import cz.muni.fi.pa165.winery.persistence.dao.review.ProductReviewDao;
import cz.muni.fi.pa165.winery.persistence.dao.wine.WineBottleDao;
import cz.muni.fi.pa165.winery.persistence.entities.WineBottle;
import cz.muni.fi.pa165.winery.services.PersistenceServiceImpl;
......@@ -22,14 +23,13 @@ public class WineBottleServiceImpl extends PersistenceServiceImpl<WineBottleDto,
@Override
public List<WineBottleDto> getAll(double minPrice, double maxPrice) {
return getAll().stream().filter(e -> e.getPrice().doubleValue() >= minPrice &&
e.getPrice().doubleValue() <= maxPrice)
.collect(Collectors.toList());
var entities = ((WineBottleDao)getDao()).getAll(minPrice, maxPrice);
return entities.stream().map(this::mapToDto).collect(Collectors.toList());
}
@Override
public List<WineBottleDto> getAllOnStock() {
return getAll().stream().filter(e -> e.getStock() > 0)
.collect(Collectors.toList());
var entities = ((WineBottleDao)getDao()).getAllOnStock();
return entities.stream().map(this::mapToDto).collect(Collectors.toList());
}
}
......@@ -26,25 +26,9 @@ public class WineTypeServiceImpl extends PersistenceServiceImpl<WineTypeDto, Win
this.wineBottleMapper = wineBottleMapper;
}
@Override
protected WineTypeDto mapToDto(WineType wineType) {
var dto = super.mapToDto(wineType);
dto.setWineBottles(wineType.getWineBottles().stream()
.map(x -> wineBottleMapper.mapToDto(x)).collect(Collectors.toSet()));
return dto;
}
@Override
protected WineType mapToEntity(WineTypeDto record) {
var entity = super.mapToEntity(record);
entity.setWineBottles(record.getWineBottles().stream()
.map(x -> wineBottleMapper.mapToEntity(x)).collect(Collectors.toSet()));
return entity;
}
@Override
public List<WineTypeDto> getAllByGrape(long id) {
return getAll().stream().filter(e -> e.getGrape().getId() == id)
.collect(Collectors.toList());
var entities = ((WineTypeDao)getDao()).getAllByGrape(id);
return entities.stream().map(this::mapToDto).collect(Collectors.toList());
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment