From 796a48fd13f4dad6236be8ecf53e25b2940ad16b Mon Sep 17 00:00:00 2001 From: Ebite God'sgift Uloamaka Date: Fri, 9 Aug 2024 23:09:14 +0100 Subject: [PATCH 1/2] fix: removed struct on the help center service --- internal/models/help_center.go | 6 ++++++ services/helpcenter/helpcenter.go | 21 +++++++-------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/internal/models/help_center.go b/internal/models/help_center.go index 05152b0d..35d1e825 100644 --- a/internal/models/help_center.go +++ b/internal/models/help_center.go @@ -8,6 +8,12 @@ import ( "gorm.io/gorm" ) +type HelpCntSummary struct { + ID string `json:"id"` + Title string `json:"title"` + Content string `json:"content"` + Author string `json:"author"` +} type HelpCenter struct { ID string `gorm:"type:uuid; primaryKey" json:"id"` diff --git a/services/helpcenter/helpcenter.go b/services/helpcenter/helpcenter.go index 62e6fa6d..faff4905 100644 --- a/services/helpcenter/helpcenter.go +++ b/services/helpcenter/helpcenter.go @@ -9,13 +9,6 @@ import ( "gorm.io/gorm" ) -type HelpCntSummary struct { - ID string `json:"id"` - Title string `json:"title"` - Content string `json:"content"` - Author string `json:"author"` -} - func CreateHelpCenterTopic(req models.CreateHelpCenter, db *gorm.DB) (models.HelpCenter, error) { helpCnt := models.HelpCenter{ ID: utility.GenerateUUID(), @@ -33,7 +26,7 @@ func CreateHelpCenterTopic(req models.CreateHelpCenter, db *gorm.DB) (models.Hel return helpCnt, nil } -func GetPaginatedTopics(c *gin.Context, db *gorm.DB) ([]HelpCntSummary, postgresql.PaginationResponse, error) { +func GetPaginatedTopics(c *gin.Context, db *gorm.DB) ([]models.HelpCntSummary, postgresql.PaginationResponse, error) { helpCnt := models.HelpCenter{} helpCnts, paginationResponse, err := helpCnt.FetchAllTopics(db, c) @@ -42,12 +35,12 @@ func GetPaginatedTopics(c *gin.Context, db *gorm.DB) ([]HelpCntSummary, postgres } if len(helpCnts) == 0 { - return nil, paginationResponse, gorm.ErrRecordNotFound + return []models.HelpCntSummary{}, paginationResponse, nil } - var topicSummaries []HelpCntSummary + var topicSummaries []models.HelpCntSummary for _, Hlp := range helpCnts { - summary := HelpCntSummary{ + summary := models.HelpCntSummary{ ID: Hlp.ID, Title: Hlp.Title, Content: Hlp.Content, @@ -69,7 +62,7 @@ func FetchTopicByID(db *gorm.DB, id string) (models.HelpCenter, error) { return helpCnt, nil } -func SearchHelpCenterTopics(c *gin.Context, db *gorm.DB, query string) ([]HelpCntSummary, postgresql.PaginationResponse, error) { +func SearchHelpCenterTopics(c *gin.Context, db *gorm.DB, query string) ([]models.HelpCntSummary, postgresql.PaginationResponse, error) { var helpCnt models.HelpCenter topics, paginationResponse, err := helpCnt.SearchHelpCenterTopics(db, c, query) @@ -81,9 +74,9 @@ func SearchHelpCenterTopics(c *gin.Context, db *gorm.DB, query string) ([]HelpCn return nil, paginationResponse, gorm.ErrRecordNotFound } - var topicSummaries []HelpCntSummary + var topicSummaries []models.HelpCntSummary for _, topic := range topics { - summary := HelpCntSummary{ + summary := models.HelpCntSummary{ ID: topic.ID, Title: topic.Title, Content: topic.Content, From 99d83e3f9e5966c3a7c39e5f58e9153f5f9ce7c7 Mon Sep 17 00:00:00 2001 From: Ebite God'sgift Uloamaka Date: Sat, 10 Aug 2024 12:02:24 +0100 Subject: [PATCH 2/2] fix: removed help center struct --- services/helpcenter/helpcenter.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/services/helpcenter/helpcenter.go b/services/helpcenter/helpcenter.go index faff4905..0d890cc0 100644 --- a/services/helpcenter/helpcenter.go +++ b/services/helpcenter/helpcenter.go @@ -1,4 +1,4 @@ -package service +package helpcenter import ( @@ -28,18 +28,18 @@ func CreateHelpCenterTopic(req models.CreateHelpCenter, db *gorm.DB) (models.Hel func GetPaginatedTopics(c *gin.Context, db *gorm.DB) ([]models.HelpCntSummary, postgresql.PaginationResponse, error) { helpCnt := models.HelpCenter{} - helpCnts, paginationResponse, err := helpCnt.FetchAllTopics(db, c) + topics, paginationResponse, err := helpCnt.FetchAllTopics(db, c) if err != nil { return nil, paginationResponse, err } - if len(helpCnts) == 0 { + if len(topics) == 0 { return []models.HelpCntSummary{}, paginationResponse, nil } var topicSummaries []models.HelpCntSummary - for _, Hlp := range helpCnts { + for _, Hlp := range topics { summary := models.HelpCntSummary{ ID: Hlp.ID, Title: Hlp.Title, @@ -71,7 +71,7 @@ func SearchHelpCenterTopics(c *gin.Context, db *gorm.DB, query string) ([]models } if len(topics) == 0 { - return nil, paginationResponse, gorm.ErrRecordNotFound + return []models.HelpCntSummary{}, paginationResponse, nil } var topicSummaries []models.HelpCntSummary