Skip to content

Commit

Permalink
Merge pull request #347 from uloamaka/fix/create-help-center-topic
Browse files Browse the repository at this point in the history
Fix: moved struct in create help center service
  • Loading branch information
Cyberguru1 authored Aug 10, 2024
2 parents 9060a21 + f578895 commit 23d5a0f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
6 changes: 6 additions & 0 deletions internal/models/help_center.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
31 changes: 12 additions & 19 deletions services/helpcenter/helpcenter.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package service
package helpcenter

import (

Expand All @@ -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(),
Expand All @@ -33,21 +26,21 @@ 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)
topics, paginationResponse, err := helpCnt.FetchAllTopics(db, c)

if err != nil {
return nil, paginationResponse, err
}

if len(helpCnts) == 0 {
return nil, paginationResponse, gorm.ErrRecordNotFound
if len(topics) == 0 {
return []models.HelpCntSummary{}, paginationResponse, nil
}

var topicSummaries []HelpCntSummary
for _, Hlp := range helpCnts {
summary := HelpCntSummary{
var topicSummaries []models.HelpCntSummary
for _, Hlp := range topics {
summary := models.HelpCntSummary{
ID: Hlp.ID,
Title: Hlp.Title,
Content: Hlp.Content,
Expand All @@ -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)

Expand All @@ -78,12 +71,12 @@ func SearchHelpCenterTopics(c *gin.Context, db *gorm.DB, query string) ([]HelpCn
}

if len(topics) == 0 {
return nil, paginationResponse, gorm.ErrRecordNotFound
return []models.HelpCntSummary{}, paginationResponse, nil
}

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,
Expand Down

0 comments on commit 23d5a0f

Please sign in to comment.