Skip to content

Commit

Permalink
fix: BidEntity crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Altair-Bueno committed May 26, 2022
1 parent 9bc99f0 commit 47a905f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
4 changes: 1 addition & 3 deletions src/main/java/uma/taw/ubayspring/entity/BidEntityPK.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package uma.taw.ubayspring.entity;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import java.io.Serializable;
import java.util.Objects;

Expand All @@ -12,7 +10,7 @@
public class BidEntityPK implements Serializable {
//@Id
//@Column(name = "id", nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
//@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
//@Id
//@Column(name = "product_id", nullable = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package uma.taw.ubayspring.repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.criteria.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import uma.taw.ubayspring.entity.BidEntity;
import uma.taw.ubayspring.entity.ClientEntity;
import uma.taw.ubayspring.entity.ProductEntity;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -31,16 +33,16 @@ public Stream<BidEntity> getFilteredBidsFromVendor(ClientEntity vendor, int page
// from BidEntity bidTable, ProductEntity productTable, ClientEntity clientTable
// where productTable.vendor = :vendor and
// bidTable.product = productTable and
// bidTable.user = clientTable
// bidTable.client = clientTable
// order by bidTable.publish_date
Root<BidEntity> bidTable = query.from(BidEntity.class);
Root<ProductEntity> productTable = query.from(ProductEntity.class);
Root<ClientEntity> clientTable = query.from(ClientEntity.class);

List<Predicate> predicateList = new ArrayList<>();
predicateList.add(builder.equal(bidTable.get("product"),productTable));
predicateList.add(builder.equal(bidTable.get("user"),clientTable));
predicateList.add(builder.equal(productTable.get("vendor"), vendor));
predicateList.add(builder.equal(bidTable.get("client"),clientTable));
predicateList.add(builder.equal(productTable.get("vendedor"), vendor));
if (startDate != null) predicateList.add(builder.greaterThanOrEqualTo(bidTable.get("publishDate"),startDate));
if (endDate != null) predicateList.add(builder.lessThanOrEqualTo(bidTable.get("publishDate"),endDate));
if (productTitle != null) predicateList.add(builder.like(builder.lower(productTable.get("title")),"%" + productTitle.toLowerCase() + "%"));
Expand All @@ -59,7 +61,7 @@ public Stream<BidEntity> getFilteredBidsFromVendor(ClientEntity vendor, int page
.getResultStream();
}

public Stream<BidEntity> getFilteredBidsFromUser(ClientEntity user, int page, Date startDate, Date endDate, String productTitle, String vendorName,String orderBy,boolean asc) {
public Stream<BidEntity> getFilteredBidsFromUser(ClientEntity client, int page, Date startDate, Date endDate, String productTitle, String vendorName,String orderBy,boolean asc) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<BidEntity> query = builder.createQuery(BidEntity.class);

Expand All @@ -68,9 +70,9 @@ public Stream<BidEntity> getFilteredBidsFromUser(ClientEntity user, int page, Da
Root<ClientEntity> clientTable = query.from(ClientEntity.class);

List<Predicate> predicateList = new ArrayList<>();
predicateList.add(builder.equal(bidTable.get("user"), user));
predicateList.add(builder.equal(bidTable.get("client"), client));
predicateList.add(builder.equal(bidTable.get("product"),productTable));
predicateList.add(builder.equal(productTable.get("vendor"),clientTable));
predicateList.add(builder.equal(productTable.get("vendedor"),clientTable));
if (startDate != null) predicateList.add(builder.greaterThanOrEqualTo(bidTable.get("publishDate"),startDate));
if (endDate != null) predicateList.add(builder.lessThanOrEqualTo(bidTable.get("publishDate"),endDate));
if (productTitle != null) predicateList.add(builder.like(builder.lower(productTable.get("title")),"%" + productTitle.toLowerCase() + "%"));
Expand Down Expand Up @@ -110,7 +112,7 @@ public BidEntity getHighestBidByProduct(ProductEntity product) {

/*
* Returns a list containing the (closed) bids
* that have been made by the user given
* that have been made by the client given
* by parameter.
*
* @author Fran Hernandez
Expand Down

0 comments on commit 47a905f

Please sign in to comment.