Skip to content

Commit 2b2216a

Browse files
Merge pull request #19 from spurtcms/M2-Predev
M2 predev
2 parents 942cd7d + c68d4de commit 2b2216a

31 files changed

+14679
-8069
lines changed

controller/authcontroller.go

Lines changed: 306 additions & 235 deletions
Large diffs are not rendered by default.

controller/category.go

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ package controller
22

33
import (
44
"context"
5+
"net/http"
56
"spurtcms-graphql/graph/model"
6-
"log"
77
"strconv"
88
"strings"
99

1010
"github.com/gin-gonic/gin"
1111
"gorm.io/gorm"
1212
)
1313

14-
func CategoriesList(db *gorm.DB, ctx context.Context, limit, offset, categoryGroupId, hierarchyLevel, checkEntriesPresence *int) (model.CategoriesList, error) {
14+
func CategoriesList(db *gorm.DB, ctx context.Context, limit, offset, categoryGroupId *int, categoryGroupSlug *string, hierarchyLevel, checkEntriesPresence *int) (*model.CategoriesList, error) {
1515

1616
c, _ := ctx.Value(ContextKey).(*gin.Context)
1717

18-
memberid := c.GetInt("memberid")
18+
// memberid := c.GetInt("memberid")
1919

2020
var categories []model.Category
2121

@@ -25,11 +25,41 @@ func CategoriesList(db *gorm.DB, ctx context.Context, limit, offset, categoryGro
2525

2626
selectGroupRemove := ""
2727

28-
if categoryGroupId != nil {
28+
if categoryGroupId!=nil {
2929

3030
category_string = `WHERE id = ` + strconv.Itoa(*categoryGroupId)
3131

3232
selectGroupRemove = `AND id != ` + strconv.Itoa(*categoryGroupId)
33+
34+
}else if categoryGroupSlug!=nil{
35+
36+
slugStrings := strings.Split(*categoryGroupSlug, "-")
37+
38+
var finalSlug_string string
39+
40+
if len(slugStrings) > 1 {
41+
42+
for index, slugparts := range slugStrings {
43+
44+
if index == len(slugStrings)-1 {
45+
46+
finalSlug_string += slugparts
47+
48+
} else {
49+
50+
finalSlug_string += slugparts + " "
51+
}
52+
}
53+
54+
}else{
55+
56+
finalSlug_string = *categoryGroupSlug
57+
}
58+
59+
category_string = `WHERE id = (select id from tbl_categories where is_deleted = 0 and category_slug = '`+finalSlug_string+`')`
60+
61+
selectGroupRemove = `AND id != (select id from tbl_categories where is_deleted = 0 and category_slug = '`+finalSlug_string+`')`
62+
3363
}
3464

3565
hierarchy_string := ""
@@ -62,20 +92,24 @@ func CategoriesList(db *gorm.DB, ctx context.Context, limit, offset, categoryGro
6292
res := `WITH RECURSIVE cat_tree AS (
6393
SELECT id, category_name, category_slug,image_path, parent_id,created_on,modified_on,is_deleted` + selecthierarchy_string + `
6494
FROM tbl_categories ` + category_string + `
65-
UNION ALL
95+
UNION
6696
SELECT cat.id, cat.category_name, cat.category_slug, cat.image_path ,cat.parent_id,cat.created_on,cat.modified_on,
6797
cat.is_deleted` + fromhierarchy_string + `
6898
FROM tbl_categories AS cat
6999
JOIN cat_tree ON cat.parent_id = cat_tree.id ` + hierarchy_string + ` )`
70100

71-
if err := db.Debug().Raw(` ` + res + `SELECT cat_tree.* FROM cat_tree where is_deleted = 0 ` + selectGroupRemove + outerlevel + ` and parent_id != 0 order by id desc ` + limit_offString).Find(&categories).Error; err != nil {
101+
if err := db.Debug().Raw(` ` + res + `SELECT distinct(cat_tree.id),cat_tree.* FROM cat_tree where is_deleted = 0 ` + selectGroupRemove + outerlevel + ` and parent_id != 0 order by id desc ` + limit_offString).Find(&categories).Error; err != nil {
102+
103+
c.AbortWithError(http.StatusInternalServerError,err)
72104

73-
return model.CategoriesList{}, err
105+
return &model.CategoriesList{}, err
74106
}
75107

76-
if err := db.Raw(` ` + res + ` SELECT count(*) FROM cat_tree where is_deleted = 0 ` + selectGroupRemove + outerlevel + ` and parent_id != 0 group by id order by id desc`).Count(&count).Error; err != nil {
108+
if err := db.Raw(` ` + res + ` SELECT count(distinct(cat_tree.id)) FROM cat_tree where is_deleted = 0 ` + selectGroupRemove + outerlevel + ` and parent_id != 0 group by id order by id desc`).Count(&count).Error; err != nil {
77109

78-
return model.CategoriesList{}, err
110+
c.AbortWithError(http.StatusInternalServerError,err)
111+
112+
return &model.CategoriesList{}, err
79113
}
80114

81115
var final_categoriesList []model.Category
@@ -92,29 +126,29 @@ func CategoriesList(db *gorm.DB, ctx context.Context, limit, offset, categoryGro
92126

93127
Query := db.Table("tbl_channel_entries").Select("tbl_channel_entries.categories_id").Joins("inner join tbl_channels on tbl_channels.id = tbl_channel_entries.channel_id").Where("tbl_channels.is_deleted = 0 and tbl_channels.is_active = 1 and tbl_channel_entries.is_deleted = 0 and tbl_channel_entries.status = 1").Where(`` + strconv.Itoa(category.ID) + `= any(string_to_array(tbl_channel_entries.categories_id,',')::integer[])`)
94128

95-
if memberid > 0 {
129+
// if memberid > 0 {
96130

97-
innerSubQuery := db.Table("tbl_channel_entries").Select("tbl_channel_entries.id").Joins("inner join tbl_channels on tbl_channels.id = tbl_channel_entries.channel_id").Where("tbl_channels.is_deleted = 0 and tbl_channels.is_active = 1 and tbl_channel_entries.is_deleted = 0 and tbl_channel_entries.status = 1").Where(`` + strconv.Itoa(category.ID) + `= any(string_to_array(tbl_channel_entries.categories_id,',')::integer[])`)
131+
// innerSubQuery := db.Table("tbl_channel_entries").Select("tbl_channel_entries.id").Joins("inner join tbl_channels on tbl_channels.id = tbl_channel_entries.channel_id").Where("tbl_channels.is_deleted = 0 and tbl_channels.is_active = 1 and tbl_channel_entries.is_deleted = 0 and tbl_channel_entries.status = 1").Where(`` + strconv.Itoa(category.ID) + `= any(string_to_array(tbl_channel_entries.categories_id,',')::integer[])`)
98132

99-
subquery := db.Table("tbl_access_control_pages").Select("tbl_access_control_pages.entry_id").Joins("inner join tbl_access_control_user_group on tbl_access_control_user_group.id = tbl_access_control_pages.access_control_user_group_id").
100-
Joins("inner join tbl_member_groups on tbl_member_groups.id = tbl_access_control_user_group.member_group_id").Joins("inner join tbl_members on tbl_members.member_group_id = tbl_member_groups.id")
133+
// subquery := db.Table("tbl_access_control_pages").Select("tbl_access_control_pages.entry_id").Joins("inner join tbl_access_control_user_groups on tbl_access_control_user_groups.id = tbl_access_control_pages.access_control_user_group_id").
134+
// Joins("inner join tbl_member_groups on tbl_member_groups.id = tbl_access_control_user_groups.member_group_id").Joins("inner join tbl_members on tbl_members.member_group_id = tbl_member_groups.id")
101135

102-
subquery = subquery.Where("tbl_members.is_deleted = 0 and tbl_member_groups.is_deleted = 0 and tbl_access_control_pages.is_deleted = 0 and tbl_access_control_user_group.is_deleted = 0 and tbl_members.id = ?", memberid).Where("tbl_access_control_pages.entry_id in (?)", innerSubQuery)
136+
// subquery = subquery.Where("tbl_members.is_deleted = 0 and tbl_member_groups.is_deleted = 0 and tbl_access_control_pages.is_deleted = 0 and tbl_access_control_user_groups.is_deleted = 0 and tbl_members.id = ?", memberid).Where("tbl_access_control_pages.entry_id in (?)", innerSubQuery)
103137

104-
Query = Query.Where("tbl_channel_entries.id not in (?)", subquery)
105-
}
138+
// Query = Query.Where("tbl_channel_entries.id not in (?)", subquery)
139+
// }
106140

107141
err := Query.Where("tbl_channels.is_deleted = 0 and tbl_channels.is_active = 1 and tbl_channel_entries.is_deleted = 0 and tbl_channel_entries.status = 1").Where(`` + strconv.Itoa(category.ID) + `= any(string_to_array(tbl_channel_entries.categories_id,',')::integer[])`).Find(&categoryIds).Error
108142

109143
if err != nil {
110144

111-
return model.CategoriesList{}, err
145+
c.AbortWithError(http.StatusInternalServerError,err)
146+
147+
return &model.CategoriesList{}, err
112148
}
113149

114150
if categoryIds != "" {
115151

116-
log.Println("categoryIds", categoryIds)
117-
118152
var modified_path string
119153

120154
if category.ImagePath != "" {
@@ -153,5 +187,5 @@ func CategoriesList(db *gorm.DB, ctx context.Context, limit, offset, categoryGro
153187
count = int64(len(final_categoriesList))
154188
}
155189

156-
return model.CategoriesList{Categories: final_categoriesList, Count: int(count)}, nil
190+
return &model.CategoriesList{Categories: final_categoriesList, Count: int(count)}, nil
157191
}

0 commit comments

Comments
 (0)