Localize client API responses by lang query param.
Client endpoints now return a single-language string (default tm) so the frontend can pass ?lang= and skip picking from nested tm/ru/en objects. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -22,9 +22,10 @@ func NewRepository(client postgresql.Client, logger *logging.Logger) users.Repos
|
||||
}
|
||||
}
|
||||
|
||||
func (r repository) GetNews(ctx context.Context, limit, page int) (users.DataNewsDTO, error) {
|
||||
func (r repository) GetNews(ctx context.Context, limit, page int, lang string) (users.DataNewsDTO, error) {
|
||||
|
||||
var dt users.DataNewsDTO
|
||||
lang = users.NormalizeLang(lang)
|
||||
|
||||
// List endpoint: skip news_content (large HTML). Full body is loaded via GetNewsById.
|
||||
// Default to latest 6 when limit/page not provided.
|
||||
@@ -51,11 +52,13 @@ func (r repository) GetNews(ctx context.Context, limit, page int) (users.DataNew
|
||||
ns := []users.NewsDTO{}
|
||||
for rows.Next() {
|
||||
var n users.NewsDTO
|
||||
errN := rows.Scan(&n.Id, &n.Title, &n.Image)
|
||||
var title users.Language
|
||||
errN := rows.Scan(&n.Id, &title, &n.Image)
|
||||
if errN != nil {
|
||||
r.logger.Error("errN :::", errN)
|
||||
continue
|
||||
}
|
||||
n.Title = title.Pick(lang)
|
||||
|
||||
ns = append(ns, n)
|
||||
}
|
||||
@@ -64,16 +67,17 @@ func (r repository) GetNews(ctx context.Context, limit, page int) (users.DataNew
|
||||
return dt, nil
|
||||
}
|
||||
|
||||
func (r repository) GetCategories(ctx context.Context) ([]users.CategoryDTO, error) {
|
||||
func (r repository) GetCategories(ctx context.Context, lang string) ([]users.CategoryDTO, error) {
|
||||
lang = users.NormalizeLang(lang)
|
||||
|
||||
// Menu only needs id/name; page content is loaded via GetSubCategoryById.
|
||||
q := ` SELECT
|
||||
c.id, c.name,
|
||||
c.id, COALESCE(c.name->>$1, ''),
|
||||
COALESCE(
|
||||
jsonb_agg(
|
||||
jsonb_build_object(
|
||||
'id', sc.id, 'categoryId', sc.category_id,
|
||||
'name', sc.name
|
||||
'name', COALESCE(sc.name->>$1, '')
|
||||
)
|
||||
ORDER BY sc.created_at ASC
|
||||
) FILTER (WHERE sc.id IS NOT NULL),
|
||||
@@ -85,7 +89,7 @@ func (r repository) GetCategories(ctx context.Context) ([]users.CategoryDTO, err
|
||||
GROUP BY c.id
|
||||
ORDER BY c.created_at DESC;`
|
||||
|
||||
rows, err := r.client.Query(ctx, q)
|
||||
rows, err := r.client.Query(ctx, q, lang)
|
||||
if err != nil {
|
||||
r.logger.Error("get categories :::", err)
|
||||
return nil, err
|
||||
@@ -153,8 +157,12 @@ func (r repository) GetBanners(ctx context.Context, limit, page int) (users.Data
|
||||
return dt, nil
|
||||
}
|
||||
|
||||
func (r repository) GetBannerById(ctx context.Context, id int) (users.BannerDTO, error) {
|
||||
func (r repository) GetBannerById(ctx context.Context, id int, lang string) (users.BannerDTO, error) {
|
||||
var b users.BannerDTO
|
||||
lang = users.NormalizeLang(lang)
|
||||
|
||||
var title users.Language
|
||||
var contentTm, contentRu, contentEn string
|
||||
|
||||
q := ` SELECT
|
||||
id, title,
|
||||
@@ -164,19 +172,22 @@ func (r repository) GetBannerById(ctx context.Context, id int) (users.BannerDTO,
|
||||
WHERE id = $1;`
|
||||
|
||||
err := r.client.QueryRow(ctx, q, id).Scan(
|
||||
&b.Id, &b.Title,
|
||||
&b.ContentTm, &b.ContentRu, &b.ContentEn,
|
||||
&b.Id, &title,
|
||||
&contentTm, &contentRu, &contentEn,
|
||||
&b.Image, &b.CreatedAt,
|
||||
)
|
||||
if err != nil {
|
||||
return b, err
|
||||
}
|
||||
b.Title = title.Pick(lang)
|
||||
b.Content = users.PickContent(lang, contentTm, contentRu, contentEn)
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func (r repository) GetStatics(ctx context.Context, limit, page int) (users.DataStaticDTO, error) {
|
||||
func (r repository) GetStatics(ctx context.Context, limit, page int, lang string) (users.DataStaticDTO, error) {
|
||||
|
||||
var dt users.DataStaticDTO
|
||||
lang = users.NormalizeLang(lang)
|
||||
|
||||
// Grid only needs id/logo/title. Full body is loaded via GetStaticById.
|
||||
q := ` SELECT
|
||||
@@ -204,11 +215,13 @@ func (r repository) GetStatics(ctx context.Context, limit, page int) (users.Data
|
||||
ss := []users.StaticDTO{}
|
||||
for rows.Next() {
|
||||
var s users.StaticDTO
|
||||
errS := rows.Scan(&s.Id, &s.Logo, &s.Title)
|
||||
var title users.Language
|
||||
errS := rows.Scan(&s.Id, &s.Logo, &title)
|
||||
if errS != nil {
|
||||
r.logger.Error("errS :::", errS)
|
||||
continue
|
||||
}
|
||||
s.Title = title.Pick(lang)
|
||||
|
||||
ss = append(ss, s)
|
||||
}
|
||||
@@ -217,8 +230,12 @@ func (r repository) GetStatics(ctx context.Context, limit, page int) (users.Data
|
||||
return dt, nil
|
||||
}
|
||||
|
||||
func (r repository) GetStaticById(ctx context.Context, id int) (users.StaticDTO, error) {
|
||||
func (r repository) GetStaticById(ctx context.Context, id int, lang string) (users.StaticDTO, error) {
|
||||
var s users.StaticDTO
|
||||
lang = users.NormalizeLang(lang)
|
||||
|
||||
var title users.Language
|
||||
var contentTm, contentRu, contentEn string
|
||||
|
||||
q := ` SELECT
|
||||
id, logo, title,
|
||||
@@ -228,18 +245,24 @@ func (r repository) GetStaticById(ctx context.Context, id int) (users.StaticDTO,
|
||||
WHERE id = $1;`
|
||||
|
||||
err := r.client.QueryRow(ctx, q, id).Scan(
|
||||
&s.Id, &s.Logo, &s.Title,
|
||||
&s.ContentTm, &s.ContentRu, &s.ContentEn,
|
||||
&s.Id, &s.Logo, &title,
|
||||
&contentTm, &contentRu, &contentEn,
|
||||
&s.CreatedAt,
|
||||
)
|
||||
if err != nil {
|
||||
return s, err
|
||||
}
|
||||
s.Title = title.Pick(lang)
|
||||
s.Content = users.PickContent(lang, contentTm, contentRu, contentEn)
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (r repository) GetCurrency(ctx context.Context) (users.CurrencyDTO, error) {
|
||||
func (r repository) GetCurrency(ctx context.Context, lang string) (users.CurrencyDTO, error) {
|
||||
var cu users.CurrencyDTO
|
||||
lang = users.NormalizeLang(lang)
|
||||
|
||||
var title users.Language
|
||||
var contentTm, contentRu, contentEn string
|
||||
|
||||
q := ` SELECT
|
||||
id, title,
|
||||
@@ -250,13 +273,15 @@ func (r repository) GetCurrency(ctx context.Context) (users.CurrencyDTO, error)
|
||||
LIMIT 1;`
|
||||
|
||||
err := r.client.QueryRow(ctx, q).Scan(
|
||||
&cu.Id, &cu.Title,
|
||||
&cu.Content.Tm, &cu.Content.Ru, &cu.Content.En,
|
||||
&cu.Id, &title,
|
||||
&contentTm, &contentRu, &contentEn,
|
||||
&cu.Path, &cu.CreatedAt,
|
||||
)
|
||||
if err != nil {
|
||||
return cu, err
|
||||
}
|
||||
cu.Title = title.Pick(lang)
|
||||
cu.Content = users.PickContent(lang, contentTm, contentRu, contentEn)
|
||||
return cu, nil
|
||||
}
|
||||
|
||||
@@ -278,8 +303,12 @@ func (r repository) GetSetting(ctx context.Context) (users.SettingDTO, error) {
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (r repository) GetSubCategoryById(ctx context.Context, id int) (users.SubCategoryDTO, error) {
|
||||
func (r repository) GetSubCategoryById(ctx context.Context, id int, lang string) (users.SubCategoryDTO, error) {
|
||||
var sc users.SubCategoryDTO
|
||||
lang = users.NormalizeLang(lang)
|
||||
|
||||
var name users.Language
|
||||
var contentEn, contentTm, contentRu string
|
||||
|
||||
q := ` SELECT
|
||||
sc.id, sc.category_id,
|
||||
@@ -291,33 +320,41 @@ func (r repository) GetSubCategoryById(ctx context.Context, id int) (users.SubCa
|
||||
|
||||
err := r.client.QueryRow(ctx, q, id).Scan(
|
||||
&sc.Id, &sc.CategoryId,
|
||||
&sc.Name, &sc.Count,
|
||||
&sc.Content.En, &sc.Content.Tm, &sc.Content.Ru,
|
||||
&name, &sc.Count,
|
||||
&contentEn, &contentTm, &contentRu,
|
||||
)
|
||||
if err != nil {
|
||||
return sc, err
|
||||
}
|
||||
sc.Name = name.Pick(lang)
|
||||
sc.Content = users.PickContent(lang, contentTm, contentRu, contentEn)
|
||||
return sc, nil
|
||||
}
|
||||
|
||||
func (r repository) GetNewsById(ctx context.Context, id int) (users.NewsDTO, error) {
|
||||
func (r repository) GetNewsById(ctx context.Context, id int, lang string) (users.NewsDTO, error) {
|
||||
var n users.NewsDTO
|
||||
lang = users.NormalizeLang(lang)
|
||||
|
||||
var title users.Language
|
||||
var contentEn, contentTm, contentRu string
|
||||
|
||||
q := ` SELECT
|
||||
n.id, n.title,
|
||||
n.date_release, n.img,
|
||||
nc.en, nc.tm, nc.ru
|
||||
COALESCE(nc.en, ''), COALESCE(nc.tm, ''), COALESCE(nc.ru, '')
|
||||
FROM news n
|
||||
LEFT JOIN news_content nc ON n.id = nc.news_id
|
||||
WHERE n.id = $1;`
|
||||
|
||||
err := r.client.QueryRow(ctx, q, id).Scan(
|
||||
&n.Id, &n.Title,
|
||||
&n.Id, &title,
|
||||
&n.DataRelease, &n.Image,
|
||||
&n.Content.En, &n.Content.Tm, &n.Content.Ru,
|
||||
&contentEn, &contentTm, &contentRu,
|
||||
)
|
||||
if err != nil {
|
||||
return n, err
|
||||
}
|
||||
n.Title = title.Pick(lang)
|
||||
n.Content = users.PickContent(lang, contentTm, contentRu, contentEn)
|
||||
return n, nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package users
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type DataNewsDTO struct {
|
||||
News []NewsDTO `json:"news"`
|
||||
@@ -9,31 +12,81 @@ type DataNewsDTO struct {
|
||||
|
||||
type NewsDTO struct {
|
||||
Id int `json:"id"`
|
||||
Title Language `json:"title"`
|
||||
Content Language `json:"content"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content,omitempty"`
|
||||
Image string `json:"imagePath"`
|
||||
DataRelease time.Time `json:"dateRelease"`
|
||||
DataRelease time.Time `json:"dateRelease,omitzero"`
|
||||
}
|
||||
|
||||
// Language is used when scanning multilingual JSON from the database.
|
||||
type Language struct {
|
||||
En string `json:"en"`
|
||||
Ru string `json:"ru"`
|
||||
Tm string `json:"tm"`
|
||||
En string `json:"en,omitempty"`
|
||||
Ru string `json:"ru,omitempty"`
|
||||
Tm string `json:"tm,omitempty"`
|
||||
}
|
||||
|
||||
func NormalizeLang(lang string) string {
|
||||
switch strings.ToLower(strings.TrimSpace(lang)) {
|
||||
case "ru", "en", "tm":
|
||||
return strings.ToLower(strings.TrimSpace(lang))
|
||||
default:
|
||||
return "tm"
|
||||
}
|
||||
}
|
||||
|
||||
func (l Language) Pick(lang string) string {
|
||||
switch NormalizeLang(lang) {
|
||||
case "ru":
|
||||
if l.Ru != "" {
|
||||
return l.Ru
|
||||
}
|
||||
case "en":
|
||||
if l.En != "" {
|
||||
return l.En
|
||||
}
|
||||
}
|
||||
if l.Tm != "" {
|
||||
return l.Tm
|
||||
}
|
||||
if l.Ru != "" {
|
||||
return l.Ru
|
||||
}
|
||||
return l.En
|
||||
}
|
||||
|
||||
func PickContent(lang, tm, ru, en string) string {
|
||||
switch NormalizeLang(lang) {
|
||||
case "ru":
|
||||
if ru != "" {
|
||||
return ru
|
||||
}
|
||||
case "en":
|
||||
if en != "" {
|
||||
return en
|
||||
}
|
||||
}
|
||||
if tm != "" {
|
||||
return tm
|
||||
}
|
||||
if ru != "" {
|
||||
return ru
|
||||
}
|
||||
return en
|
||||
}
|
||||
|
||||
type CategoryDTO struct {
|
||||
Id int `json:"id"`
|
||||
Name Language `json:"name"`
|
||||
Image string `json:"imagePath"`
|
||||
Name string `json:"name"`
|
||||
Image string `json:"imagePath,omitempty"`
|
||||
SubCategories []SubCategoryDTO `json:"subCategories"`
|
||||
}
|
||||
|
||||
type SubCategoryDTO struct {
|
||||
Id int `json:"id"`
|
||||
CategoryId int `json:"categoryId"`
|
||||
Name Language `json:"name"`
|
||||
Content Language `json:"content"`
|
||||
Count int `json:"count"`
|
||||
Id int `json:"id"`
|
||||
CategoryId int `json:"categoryId"`
|
||||
Name string `json:"name"`
|
||||
Content string `json:"content,omitempty"`
|
||||
Count int `json:"count,omitempty"`
|
||||
}
|
||||
|
||||
type DataBannerDTO struct {
|
||||
@@ -48,12 +101,10 @@ type BannerListItemDTO struct {
|
||||
|
||||
type BannerDTO struct {
|
||||
Id int `json:"id"`
|
||||
Title Language `json:"title"`
|
||||
ContentTm string `json:"contentTm"`
|
||||
ContentRu string `json:"contentRu"`
|
||||
ContentEn string `json:"contentEn"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content,omitempty"`
|
||||
Image string `json:"imagePath"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
CreatedAt time.Time `json:"createdAt,omitzero"`
|
||||
}
|
||||
|
||||
type DataStaticDTO struct {
|
||||
@@ -64,26 +115,24 @@ type DataStaticDTO struct {
|
||||
type StaticDTO struct {
|
||||
Id int `json:"id"`
|
||||
Logo string `json:"logo"`
|
||||
Title Language `json:"title"`
|
||||
ContentTm string `json:"contentTm"`
|
||||
ContentRu string `json:"contentRu"`
|
||||
ContentEn string `json:"contentEn"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content,omitempty"`
|
||||
CreatedAt time.Time `json:"createdAt,omitzero"`
|
||||
}
|
||||
|
||||
type CurrencyDTO struct {
|
||||
Id int `json:"id"`
|
||||
Title Language `json:"title"`
|
||||
Content Language `json:"content"`
|
||||
Path string `json:"path"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content,omitempty"`
|
||||
Path string `json:"path,omitempty"`
|
||||
CreatedAt time.Time `json:"createdAt,omitzero"`
|
||||
}
|
||||
|
||||
type SettingDTO struct {
|
||||
UUID string `json:"UUID"`
|
||||
UUID string `json:"UUID,omitempty"`
|
||||
LogoR string `json:"logoR"`
|
||||
PhoneNumber string `json:"phoneNumber"`
|
||||
FaxNumber string `json:"faxNumber"`
|
||||
HelpNumber string `json:"helpNumber"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
CreatedAt time.Time `json:"createdAt,omitzero"`
|
||||
}
|
||||
|
||||
@@ -48,6 +48,10 @@ func (h *handler) Register(router *gin.RouterGroup) {
|
||||
router.GET(getSettingURL, h.GetSetting)
|
||||
}
|
||||
|
||||
func queryLang(c *gin.Context) string {
|
||||
return NormalizeLang(c.Query("lang"))
|
||||
}
|
||||
|
||||
// =================================================================================
|
||||
|
||||
// GetNews godoc
|
||||
@@ -55,8 +59,9 @@ func (h *handler) Register(router *gin.RouterGroup) {
|
||||
// @Tags news
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param limit query int false "limit"
|
||||
// @Param page query int false "page"
|
||||
// @Param limit query int false "limit"
|
||||
// @Param page query int false "page"
|
||||
// @Param lang query string false "tm|ru|en (default tm)"
|
||||
// @Success 200 {object} DataNewsDTO
|
||||
// @Router /client/users/news [get]
|
||||
func (h *handler) GetNews(c *gin.Context) {
|
||||
@@ -66,7 +71,7 @@ func (h *handler) GetNews(c *gin.Context) {
|
||||
limit, _ := strconv.Atoi(limitS)
|
||||
page, _ := strconv.Atoi(pageS)
|
||||
|
||||
result, err := h.repository.GetNews(c.Request.Context(), limit, page)
|
||||
result, err := h.repository.GetNews(c.Request.Context(), limit, page, queryLang(c))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
|
||||
return
|
||||
@@ -83,6 +88,7 @@ func (h *handler) GetNews(c *gin.Context) {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "news ID"
|
||||
// @Param lang query string false "tm|ru|en (default tm)"
|
||||
// @Success 200 {object} NewsDTO
|
||||
// @Router /client/users/news/{id} [get]
|
||||
func (h *handler) GetOneNews(c *gin.Context) {
|
||||
@@ -92,7 +98,7 @@ func (h *handler) GetOneNews(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
result, err := h.repository.GetNewsById(c.Request.Context(), id)
|
||||
result, err := h.repository.GetNewsById(c.Request.Context(), id, queryLang(c))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
|
||||
return
|
||||
@@ -109,6 +115,7 @@ func (h *handler) GetOneNews(c *gin.Context) {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "sub-category ID"
|
||||
// @Param lang query string false "tm|ru|en (default tm)"
|
||||
// @Success 200 {object} SubCategoryDTO
|
||||
// @Router /client/users/sub-categories/{id} [get]
|
||||
func (h *handler) GetSubCategory(c *gin.Context) {
|
||||
@@ -118,7 +125,7 @@ func (h *handler) GetSubCategory(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
result, err := h.repository.GetSubCategoryById(c.Request.Context(), id)
|
||||
result, err := h.repository.GetSubCategoryById(c.Request.Context(), id, queryLang(c))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
|
||||
return
|
||||
@@ -162,6 +169,7 @@ func (h *handler) GetBanners(c *gin.Context) {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "banner ID"
|
||||
// @Param lang query string false "tm|ru|en (default tm)"
|
||||
// @Success 200 {object} BannerDTO
|
||||
// @Router /client/users/banners/{id} [get]
|
||||
func (h *handler) GetOneBanner(c *gin.Context) {
|
||||
@@ -171,7 +179,7 @@ func (h *handler) GetOneBanner(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
result, err := h.repository.GetBannerById(c.Request.Context(), id)
|
||||
result, err := h.repository.GetBannerById(c.Request.Context(), id, queryLang(c))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
|
||||
return
|
||||
@@ -187,8 +195,9 @@ func (h *handler) GetOneBanner(c *gin.Context) {
|
||||
// @Tags statics
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param limit query int false "limit"
|
||||
// @Param page query int false "page"
|
||||
// @Param limit query int false "limit"
|
||||
// @Param page query int false "page"
|
||||
// @Param lang query string false "tm|ru|en (default tm)"
|
||||
// @Success 200 {object} DataStaticDTO
|
||||
// @Router /client/users/static [get]
|
||||
func (h *handler) GetStatics(c *gin.Context) {
|
||||
@@ -198,7 +207,7 @@ func (h *handler) GetStatics(c *gin.Context) {
|
||||
limit, _ := strconv.Atoi(limitS)
|
||||
page, _ := strconv.Atoi(pageS)
|
||||
|
||||
result, err := h.repository.GetStatics(c.Request.Context(), limit, page)
|
||||
result, err := h.repository.GetStatics(c.Request.Context(), limit, page, queryLang(c))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
|
||||
return
|
||||
@@ -215,6 +224,7 @@ func (h *handler) GetStatics(c *gin.Context) {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "static ID"
|
||||
// @Param lang query string false "tm|ru|en (default tm)"
|
||||
// @Success 200 {object} StaticDTO
|
||||
// @Router /client/users/static/{id} [get]
|
||||
func (h *handler) GetOneStatic(c *gin.Context) {
|
||||
@@ -224,7 +234,7 @@ func (h *handler) GetOneStatic(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
result, err := h.repository.GetStaticById(c.Request.Context(), id)
|
||||
result, err := h.repository.GetStaticById(c.Request.Context(), id, queryLang(c))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
|
||||
return
|
||||
@@ -236,14 +246,15 @@ func (h *handler) GetOneStatic(c *gin.Context) {
|
||||
}
|
||||
|
||||
// GetCurrency godoc
|
||||
// @Description latest currency content (title + HTML table per language)
|
||||
// @Description latest currency content (title + HTML table for requested language)
|
||||
// @Tags currency
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param lang query string false "tm|ru|en (default tm)"
|
||||
// @Success 200 {object} CurrencyDTO
|
||||
// @Router /client/users/currency [get]
|
||||
func (h *handler) GetCurrency(c *gin.Context) {
|
||||
result, err := h.repository.GetCurrency(c.Request.Context())
|
||||
result, err := h.repository.GetCurrency(c.Request.Context(), queryLang(c))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
|
||||
return
|
||||
@@ -278,10 +289,11 @@ func (h *handler) GetSetting(c *gin.Context) {
|
||||
// @Tags categories
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param lang query string false "tm|ru|en (default tm)"
|
||||
// @Success 200 {array} CategoryDTO
|
||||
// @Router /client/users/categories [get]
|
||||
func (h *handler) GetCategories(c *gin.Context) {
|
||||
result, err := h.repository.GetCategories(c.Request.Context())
|
||||
result, err := h.repository.GetCategories(c.Request.Context(), queryLang(c))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, appresult.ErrInternalServer)
|
||||
return
|
||||
|
||||
@@ -3,18 +3,18 @@ package users
|
||||
import "context"
|
||||
|
||||
type Repository interface {
|
||||
GetNews(ctx context.Context, limit, page int) (DataNewsDTO, error)
|
||||
GetNewsById(ctx context.Context, id int) (NewsDTO, error)
|
||||
GetNews(ctx context.Context, limit, page int, lang string) (DataNewsDTO, error)
|
||||
GetNewsById(ctx context.Context, id int, lang string) (NewsDTO, error)
|
||||
|
||||
GetCategories(ctx context.Context) ([]CategoryDTO, error)
|
||||
GetSubCategoryById(ctx context.Context, id int) (SubCategoryDTO, error)
|
||||
GetCategories(ctx context.Context, lang string) ([]CategoryDTO, error)
|
||||
GetSubCategoryById(ctx context.Context, id int, lang string) (SubCategoryDTO, error)
|
||||
|
||||
GetBanners(ctx context.Context, limit, page int) (DataBannerDTO, error)
|
||||
GetBannerById(ctx context.Context, id int) (BannerDTO, error)
|
||||
GetBannerById(ctx context.Context, id int, lang string) (BannerDTO, error)
|
||||
|
||||
GetStatics(ctx context.Context, limit, page int) (DataStaticDTO, error)
|
||||
GetStaticById(ctx context.Context, id int) (StaticDTO, error)
|
||||
GetStatics(ctx context.Context, limit, page int, lang string) (DataStaticDTO, error)
|
||||
GetStaticById(ctx context.Context, id int, lang string) (StaticDTO, error)
|
||||
|
||||
GetCurrency(ctx context.Context) (CurrencyDTO, error)
|
||||
GetCurrency(ctx context.Context, lang string) (CurrencyDTO, error)
|
||||
GetSetting(ctx context.Context) (SettingDTO, error)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user