Add mini-slider API and wire the homepage projects carousel.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -157,6 +157,39 @@ func (r repository) GetBanners(ctx context.Context, limit, page int) (users.Data
|
||||
return dt, nil
|
||||
}
|
||||
|
||||
func (r repository) GetMiniSliders(ctx context.Context, lang string) (users.DataMiniSliderDTO, error) {
|
||||
var dt users.DataMiniSliderDTO
|
||||
lang = users.NormalizeLang(lang)
|
||||
|
||||
q := ` SELECT
|
||||
id, title, img
|
||||
FROM mini_slider
|
||||
ORDER BY created_at ASC;`
|
||||
|
||||
rows, err := r.client.Query(ctx, q)
|
||||
if err != nil {
|
||||
r.logger.Error("get mini sliders :::", err)
|
||||
return dt, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
ss := []users.MiniSliderDTO{}
|
||||
for rows.Next() {
|
||||
var s users.MiniSliderDTO
|
||||
var title users.Language
|
||||
errS := rows.Scan(&s.Id, &title, &s.Image)
|
||||
if errS != nil {
|
||||
r.logger.Error("errS :::", errS)
|
||||
continue
|
||||
}
|
||||
s.Title = title.Pick(lang)
|
||||
ss = append(ss, s)
|
||||
}
|
||||
dt.MiniSliders = ss
|
||||
dt.Count = len(ss)
|
||||
return dt, nil
|
||||
}
|
||||
|
||||
func (r repository) GetBannerById(ctx context.Context, id int, lang string) (users.BannerDTO, error) {
|
||||
var b users.BannerDTO
|
||||
lang = users.NormalizeLang(lang)
|
||||
|
||||
@@ -94,6 +94,17 @@ type DataBannerDTO struct {
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
type DataMiniSliderDTO struct {
|
||||
MiniSliders []MiniSliderDTO `json:"miniSliders"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
type MiniSliderDTO struct {
|
||||
Id int `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Image string `json:"imagePath"`
|
||||
}
|
||||
|
||||
type BannerListItemDTO struct {
|
||||
Id int `json:"id"`
|
||||
Image string `json:"imagePath"`
|
||||
|
||||
@@ -17,6 +17,7 @@ const (
|
||||
getOneSubCategoryURL = "/sub-categories/:id"
|
||||
getBannersURL = "/banners"
|
||||
getOneBannerURL = "/banners/:id"
|
||||
getMiniSlidersURL = "/mini-sliders"
|
||||
getStaticsURL = "/static"
|
||||
getOneStaticURL = "/static/:id"
|
||||
getCurrencyURL = "/currency"
|
||||
@@ -42,6 +43,7 @@ func (h *handler) Register(router *gin.RouterGroup) {
|
||||
router.GET(getOneSubCategoryURL, h.GetSubCategory)
|
||||
router.GET(getBannersURL, h.GetBanners)
|
||||
router.GET(getOneBannerURL, h.GetOneBanner)
|
||||
router.GET(getMiniSlidersURL, h.GetMiniSliders)
|
||||
router.GET(getStaticsURL, h.GetStatics)
|
||||
router.GET(getOneStaticURL, h.GetOneStatic)
|
||||
router.GET(getCurrencyURL, h.GetCurrency)
|
||||
@@ -163,6 +165,26 @@ func (h *handler) GetBanners(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, successResult)
|
||||
}
|
||||
|
||||
// GetMiniSliders godoc
|
||||
// @Description homepage mini sliders (image + overlay title)
|
||||
// @Tags mini-sliders
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param lang query string false "tm|ru|en (default tm)"
|
||||
// @Success 200 {object} DataMiniSliderDTO
|
||||
// @Router /client/users/mini-sliders [get]
|
||||
func (h *handler) GetMiniSliders(c *gin.Context) {
|
||||
result, err := h.repository.GetMiniSliders(c.Request.Context(), queryLang(c))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
|
||||
return
|
||||
}
|
||||
|
||||
successResult := appresult.Success
|
||||
successResult.Data = result
|
||||
c.JSON(http.StatusOK, successResult)
|
||||
}
|
||||
|
||||
// GetOneBanner godoc
|
||||
// @Description banner by id
|
||||
// @Tags banners
|
||||
|
||||
@@ -12,6 +12,8 @@ type Repository interface {
|
||||
GetBanners(ctx context.Context, limit, page int) (DataBannerDTO, error)
|
||||
GetBannerById(ctx context.Context, id int, lang string) (BannerDTO, error)
|
||||
|
||||
GetMiniSliders(ctx context.Context, lang string) (DataMiniSliderDTO, error)
|
||||
|
||||
GetStatics(ctx context.Context, limit, page int, lang string) (DataStaticDTO, error)
|
||||
GetStaticById(ctx context.Context, id int, lang string) (StaticDTO, error)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user