Files
backend_fiesta/services/utilsService.go
abhishek 84dfa8e640 Add a synthetic "All" category to getappcategories
The mobile app needs an "All" tile to browse every product regardless of
category. Rather than inserting a real app_category row (which would break
once any category-scoped product filter treats it as an actual, empty
category), the service now prepends a synthetic entry with categoryid=0 —
reusing the "0 = no category filter" convention GetAllProducts already
implements in FetchFilteredProducts.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-24 11:04:37 +05:30

73 lines
2.3 KiB
Go

package services
import (
"nearle/models"
"nearle/repositories"
)
type UtilsService interface {
GetApptypes(tag string) ([]models.Apptypes, error)
SendNotification(token string, notification models.FcmNotification, data map[string]string) error
GetSubcategories(moduleid int, categoryid int) ([]models.Appsubcategories, error)
GetApplocations(aid int) ([]models.Applocations, error)
GetApplocationConfig(aid int) ([]models.Applocations, error)
GetAppConfig(configID int) (models.Appconfig, error)
GetAppCategory() ([]models.AppCategory, error)
}
type utilsService struct {
repo repositories.UtilsRepository
}
func NewUtilsService(repo repositories.UtilsRepository) UtilsService {
return &utilsService{repo: repo}
}
func (s *utilsService) GetApptypes(tag string) ([]models.Apptypes, error) {
return s.repo.GetApptypes(tag)
}
func (s *utilsService) SendNotification(token string, notification models.FcmNotification, data map[string]string) error {
return s.repo.SendNotification(token, notification, data)
}
func (s *utilsService) GetSubcategories(moduleid int, categoryid int) ([]models.Appsubcategories, error) {
return s.repo.GetSubcategories(moduleid, categoryid)
}
func (s *utilsService) GetApplocations(aid int) ([]models.Applocations, error) {
return s.repo.GetApplocations(aid)
}
func (s *utilsService) GetApplocationConfig(aid int) ([]models.Applocations, error) {
return s.repo.GetApplocationConfig(aid)
}
func (s *utilsService) GetAppConfig(configID int) (models.Appconfig, error) {
return s.repo.GetAppConfig(configID)
}
func (s *utilsService) GetAppCategory() ([]models.AppCategory, error) {
categories, err := s.repo.GetAppCategory()
if err != nil {
return nil, err
}
// "All" is a synthetic pseudo-category, not a real app_category row — it
// must never be inserted into app_category itself, since product-listing
// filters (e.g. ProductController.GetAllProducts) already treat
// categoryid=0 as "no category filter". Keeping this row's id at 0 reuses
// that existing convention instead of adding a new one.
all := models.AppCategory{
Categoryid: 0,
Categoryname: "All",
Categorytype: 7,
Sortorder: 0,
Crossaxis: 1,
Mainaxis: 1,
Status: "Active",
}
return append([]models.AppCategory{all}, categories...), nil
}