Skip to content

Commit

Permalink
Merge pull request #177 from Uplace/fix-pagination
Browse files Browse the repository at this point in the history
Fixed pagination closes #172 and fixes some bugs
  • Loading branch information
arnaugarcia committed May 8, 2018
2 parents 24fd436 + 37228f7 commit 6150890
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 29 deletions.
28 changes: 16 additions & 12 deletions src/main/java/com/arnaugarcia/uplace/domain/Photo.java
Expand Up @@ -13,6 +13,7 @@
import javax.validation.constraints.*;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Objects;

/**
Expand Down Expand Up @@ -148,19 +149,20 @@ public void setProperty(Property property) {
}
// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove


@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Photo photo = (Photo) o;
if (photo.getId() == null || getId() == null) {
return false;
}
return Objects.equals(getId(), photo.getId());
if (this == o) return true;
if (!(o instanceof Photo)) return false;
Photo photo1 = (Photo) o;
return Objects.equals(id, photo1.id) &&
Objects.equals(name, photo1.name) &&
Objects.equals(description, photo1.description) &&
Objects.equals(photoUrl, photo1.photoUrl) &&
Objects.equals(publicId, photo1.publicId) &&
Arrays.equals(photo, photo1.photo) &&
Objects.equals(thumbnail, photo1.thumbnail) &&
Objects.equals(property, photo1.property);
}

@Override
Expand All @@ -174,7 +176,9 @@ public String toString() {
"id=" + id +
", name='" + name + '\'' +
", description='" + description + '\'' +
", photo='" + photo + '\'' +
", photoUrl='" + photoUrl + '\'' +
", publicId='" + publicId + '\'' +
", photo=" + Arrays.toString(photo) +
", thumbnail=" + thumbnail +
", property=" + property +
'}';
Expand Down
36 changes: 25 additions & 11 deletions src/main/java/com/arnaugarcia/uplace/domain/Property.java
Expand Up @@ -134,7 +134,7 @@ public class Property implements Serializable {
@JoinColumn(unique = true, nullable = false)
private Location location;

@OneToMany(mappedBy = "property", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
@OneToMany(mappedBy = "property", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Set<Photo> photos = new HashSet<>();

Expand Down Expand Up @@ -429,19 +429,32 @@ public void setRealEstate(RealEstate realEstate) {

// jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove


@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (this == o) return true;
if (!(o instanceof Property)) return false;
Property property = (Property) o;
if (property.getId() == null || getId() == null) {
return false;
}
return Objects.equals(getId(), property.getId());
return Objects.equals(id, property.id) &&
Objects.equals(title, property.title) &&
Objects.equals(created, property.created) &&
Objects.equals(updated, property.updated) &&
Objects.equals(propertyType, property.propertyType) &&
Objects.equals(description, property.description) &&
transaction == property.transaction &&
Objects.equals(reference, property.reference) &&
Objects.equals(priceTransfer, property.priceTransfer) &&
Objects.equals(priceSell, property.priceSell) &&
Objects.equals(priceRent, property.priceRent) &&
Objects.equals(yearConstruction, property.yearConstruction) &&
Objects.equals(newCreation, property.newCreation) &&
Objects.equals(visible, property.visible) &&
Objects.equals(surface, property.surface) &&
Objects.equals(location, property.location) &&
Objects.equals(photos, property.photos) &&
Objects.equals(managers, property.managers) &&
Objects.equals(requests, property.requests) &&
Objects.equals(realEstate, property.realEstate);
}

@Override
Expand Down Expand Up @@ -470,6 +483,7 @@ public String toString() {
", location=" + location +
", photos=" + photos +
", managers=" + managers +
", requests=" + requests +
", realEstate=" + realEstate +
'}';
}
Expand Down
Expand Up @@ -40,6 +40,14 @@ public interface PropertyRepository<T extends Property> extends JpaRepository<T,
@Override
Page<T> findAll(Specification<T> specification, Pageable pageable);

@EntityGraph(value = "graph.PropertyAll", type = EntityGraph.EntityGraphType.LOAD)
@Override
void delete(T t);

@EntityGraph(value = "graph.PropertyAll", type = EntityGraph.EntityGraphType.LOAD)
@Override
void delete(Iterable<? extends T> iterable);

/**
* Query to get a property by reference
*
Expand All @@ -50,6 +58,7 @@ public interface PropertyRepository<T extends Property> extends JpaRepository<T,
@Query("SELECT p FROM Property p left join fetch p.managers where p.reference = :reference")
T findByReference(@Param("reference") String reference);

@EntityGraph(value = "graph.PropertyAll", type = EntityGraph.EntityGraphType.LOAD)
List<T> findByReferenceIn(Collection<String> references);

@Query("SELECT p FROM Property p ORDER BY p.created DESC")
Expand Down
Expand Up @@ -123,7 +123,7 @@ public void delete(String references) {
log.debug("Request to delete Property : {}", references);
String[] referencesList = references.split(",");
List<T> properties = propertyRepository.findByReferenceIn(Arrays.asList(referencesList));
if (properties.size() <= 0) {
if (properties.size() != referencesList.length) {
throw new BadRequestAlertException("Reference not found", "PROPERTY", ErrorConstants.ERR_BAD_REFERENCE);
}
propertyRepository.delete(properties);
Expand Down
Expand Up @@ -86,11 +86,13 @@ <h2>
</div>
</div>
<!-- /.table-wrapper -->
<ul class="pagination pull-right">
<ngb-pagination class="pagination pull-right" [collectionSize]="totalItems"
<ul class="pagination pull-right" *ngIf="properties.length >=! ITEMS_PER_PAGE">
<ngb-pagination class="pagination pull-right"
[collectionSize]="totalItems"
[(page)]="page" [pageSize]="itemsPerPage" [maxSize]="5"
[rotate]="true" [boundaryLinks]="true"
(pageChange)="loadPage(page)">
</ngb-pagination>
</ul>
</div>
<!-- /.container -->
8 changes: 5 additions & 3 deletions src/main/webapp/app/entities/property/property.component.html
Expand Up @@ -172,11 +172,13 @@ <h3 *ngIf="property.location && property.location.hide">
<!-- /.row -->
<div *ngIf="properties && properties.length">
<div class="row">
<div class="col-sm-12">
<ngb-pagination class="pagination pull-right" [collectionSize]="totalItems"
<div class="col-sm-12" *ngIf="properties.length >=! ITEMS_PER_PAGE">
<ngb-pagination class="pagination pull-right"
[collectionSize]="totalItems"
[(page)]="page" [pageSize]="itemsPerPage" [maxSize]="5"
[rotate]="true" [boundaryLinks]="true"
(pageChange)="loadPage(page)"></ngb-pagination>
(pageChange)="loadPage(page)">
</ngb-pagination>
</div>
</div>
</div>
Expand Down

0 comments on commit 6150890

Please sign in to comment.