Skip to content

Commit

Permalink
#28894 returning category_name on the hierarchy Endpoint (#29210)
Browse files Browse the repository at this point in the history
### Proposed Changes
* returning category_name
  • Loading branch information
freddyDOTCMS authored Jul 12, 2024
1 parent 409266e commit c58feda
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
public class CategoryFactoryImpl extends CategoryFactory {

public static final String INODE = "inode";
public static final String CATEGORY_NAME = "category_name";
CategoryCache catCache;
final CategorySQL categorySQL;

Expand Down Expand Up @@ -989,6 +990,8 @@ public List<HierarchyShortCategory> findHierarchy(final Collection<String> inode
final String queryTemplate = "WITH RECURSIVE CategoryHierarchy AS ( SELECT " +
"c.inode," +
"c.inode AS root_inode," +
"c.category_name," +
"c.category_name AS root_category_name," +
"1 AS level," +
"json_build_object('inode', c.inode, 'categoryName', c.category_name, 'key', c.category_key)::varchar AS path " +
"FROM Category c " +
Expand All @@ -997,13 +1000,15 @@ public List<HierarchyShortCategory> findHierarchy(final Collection<String> inode
"SELECT " +
"c.inode, " +
"ch.root_inode AS root_inode, " +
"c.category_name, " +
"ch.root_category_name AS root_category_name, " +
"ch.level + 1 AS level, " +
"CONCAT(json_build_object('inode', c.inode, 'categoryName', c.category_name, 'key', c.category_key)::varchar, ',', ch.path) AS path " +
"FROM Category c JOIN tree t ON c.inode = t.parent JOIN CategoryHierarchy ch ON t.child = ch.inode " +
")," +
"MaxLevels AS (SELECT root_inode, MAX(level) AS max_level FROM CategoryHierarchy GROUP BY root_inode) " +
"SELECT " +
"ch.root_inode as inode, " +
"ch.root_inode as inode, ch.root_category_name as category_name, " +
"CONCAT('[', path, ']')::jsonb as path " +
"FROM CategoryHierarchy ch JOIN MaxLevels ml ON ch.root_inode = ml.root_inode AND ch.level = ml.max_level;";

Expand All @@ -1016,7 +1021,8 @@ public List<HierarchyShortCategory> findHierarchy(final Collection<String> inode
return dc.loadObjectResults().stream().map(row -> {
final List<ShortCategory> parentList = getShortCategories(row.get("path").toString());

return new HierarchyShortCategory(row.get(INODE).toString(), parentList.subList(0, parentList.size() - 1));
return new HierarchyShortCategory(row.get(INODE).toString(), row.get(CATEGORY_NAME).toString(),
parentList.subList(0, parentList.size() - 1));
}).collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
*/
public class HierarchyShortCategory implements Serializable {
private final String inode;
private final String categoryName;
private final List<ShortCategory> parentList;

public HierarchyShortCategory(final String inode, final List<ShortCategory> parentList) {
public HierarchyShortCategory(final String inode, final String categoryName, final List<ShortCategory> parentList) {
this.inode = inode;
this.parentList = parentList;
this.categoryName = categoryName;
}

public String getInode() {
Expand All @@ -22,4 +24,8 @@ public String getInode() {
public List<ShortCategory> getParentList() {
return parentList;
}

public String getCategoryName() {
return categoryName;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"_postman_id": "12554162-5748-4f0b-a315-85639e82d87b",
"_postman_id": "4aaa5f5d-78ea-498e-a1a4-3b367004de5e",
"name": "Category",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "30436704"
Expand Down Expand Up @@ -3524,11 +3524,13 @@
" { ",
"",
" if (jsonData.entity[i]['inode'] === child2CategoryInodeHierarchy) {",
" pm.expect('Hierarchy Child 2').to.have.equals(jsonData.entity[i].categoryName);",
" pm.expect(1).to.have.equals(jsonData.entity[i].parentList.length);",
" pm.expect('Hierarchy Top level Category').to.have.equals(jsonData.entity[i].parentList[0].categoryName);",
" pm.expect(pm.collectionVariables.get(\"topCategoryInodeHierarchy\")).to.have.equals(jsonData.entity[i].parentList[0].inode);",
" pm.expect('Hierarchy_TOP_LEVEL').to.have.equals(jsonData.entity[i].parentList[0].key);",
" } else if (jsonData.entity[i]['inode'] === grantChildCategoryInodeHierarchy) {",
" pm.expect('Hierarchy Grandchild 1').to.have.equals(jsonData.entity[i].categoryName);",
" pm.expect(2).to.have.equals(jsonData.entity[i].parentList.length);",
"",
" pm.expect('Hierarchy Top level Category').to.have.equals(jsonData.entity[i].parentList[0].categoryName);",
Expand Down

0 comments on commit c58feda

Please sign in to comment.