Files
main-tbbank/backend/internal/client/users/dto.go
GuwandykA ddd898078c 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>
2026-08-06 12:27:10 +05:00

139 lines
3.0 KiB
Go
Executable File

package users
import (
"strings"
"time"
)
type DataNewsDTO struct {
News []NewsDTO `json:"news"`
Count int `json:"count"`
}
type NewsDTO struct {
Id int `json:"id"`
Title string `json:"title"`
Content string `json:"content,omitempty"`
Image string `json:"imagePath"`
DataRelease time.Time `json:"dateRelease,omitzero"`
}
// Language is used when scanning multilingual JSON from the database.
type Language struct {
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 string `json:"name"`
Image string `json:"imagePath,omitempty"`
SubCategories []SubCategoryDTO `json:"subCategories"`
}
type SubCategoryDTO struct {
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 {
Banners []BannerListItemDTO `json:"banners"`
Count int `json:"count"`
}
type BannerListItemDTO struct {
Id int `json:"id"`
Image string `json:"imagePath"`
}
type BannerDTO struct {
Id int `json:"id"`
Title string `json:"title"`
Content string `json:"content,omitempty"`
Image string `json:"imagePath"`
CreatedAt time.Time `json:"createdAt,omitzero"`
}
type DataStaticDTO struct {
Statics []StaticDTO `json:"statics"`
Count int `json:"count"`
}
type StaticDTO struct {
Id int `json:"id"`
Logo string `json:"logo"`
Title string `json:"title"`
Content string `json:"content,omitempty"`
CreatedAt time.Time `json:"createdAt,omitzero"`
}
type CurrencyDTO struct {
Id int `json:"id"`
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,omitempty"`
LogoR string `json:"logoR"`
PhoneNumber string `json:"phoneNumber"`
FaxNumber string `json:"faxNumber"`
HelpNumber string `json:"helpNumber"`
CreatedAt time.Time `json:"createdAt,omitzero"`
}