Skip to content

Commit

Permalink
feat: fixed search by product name
Browse files Browse the repository at this point in the history
  • Loading branch information
JordenReuter committed Sep 19, 2024
1 parent 071c024 commit a998839
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class WorkspaceSearchCriteria implements Serializable {

private String baseUrl;

private String productName;

private Integer pageNumber = 0;

private Integer pageSize = 100;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import jakarta.persistence.criteria.Predicate;

import org.tkit.onecx.workspace.domain.criteria.WorkspaceSearchCriteria;
import org.tkit.onecx.workspace.domain.models.Product_;
import org.tkit.onecx.workspace.domain.models.Workspace;
import org.tkit.quarkus.jpa.daos.AbstractDAO;
import org.tkit.quarkus.jpa.daos.Page;
Expand Down Expand Up @@ -150,11 +151,17 @@ public PageResult<Workspace> findBySearchCriteria(WorkspaceSearchCriteria criter
if (criteria.getNames() != null && !criteria.getNames().isEmpty()) {
predicates.add(workspaceTable.get(NAME).in(criteria.getNames()));
}

if (criteria.getProductName() != null && !criteria.getProductName().isEmpty()) {
// cq.where(cb.equal(workspaceTable.get(PRODUCTS).get(Product_.PRODUCT_NAME), criteria.getProductName()));
var workspaceQuery = this.getEntityManager().createQuery(cq);
workspaceQuery.setHint(HINT_LOAD_GRAPH,
this.getEntityManager().getEntityGraph(Workspace.WORKSPACE_PRODUCTS));
addSearchStringPredicate(predicates, cb, workspaceTable.get(PRODUCTS).get(Product_.PRODUCT_NAME),
criteria.getProductName());
}
if (!predicates.isEmpty()) {
cq.where(cb.and(predicates.toArray(new Predicate[0])));
}

cq.orderBy(cb.asc(workspaceTable.get(NAME)));

return createPageQuery(cq, Page.of(criteria.getPageNumber(), criteria.getPageSize())).getPageResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public interface WorkspaceMapper {
@Mapping(target = "operator", ignore = true)
void update(UpdateWorkspaceRequestDTO dto, @MappingTarget Workspace workspace);

@Mapping(target = "productName", ignore = true)
@Mapping(target = "baseUrl", ignore = true)
@Mapping(target = "names", ignore = true)
WorkspaceSearchCriteria map(WorkspaceSearchCriteriaDTO dto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void getALlWorkspacesByProductNameTest() {
.extract().as(WorkspacePageResultDTOV1.class);

assertThat(dto).isNotNull();
assertThat(dto.getStream()).isNotNull().isNotEmpty().hasSize(6);
assertThat(dto.getStream()).isNotNull().isNotEmpty().hasSize(2);
}

@Test
Expand Down

0 comments on commit a998839

Please sign in to comment.