Skip to content
Snippets Groups Projects
Commit 8b9bbb90 authored by Alex Petraky's avatar Alex Petraky :basketball_player_tone1: Committed by Pavel Antonov
Browse files

Внесены изменения в Delivery после обновлений для работы с локалями в сервисе Items

parent 088ea4d5
No related branches found
No related tags found
No related merge requests found
......@@ -24,10 +24,10 @@ import (
"google.golang.org/protobuf/types/known/timestamppb"
)
func ListPtrLocalesLocaleToProto(locales []*locales.Locale) ([]*localespb.Locale, error) {
protoLocales := make([]*localespb.Locale, 0, len(locales))
for _, l := range locales {
protoLocales = append(protoLocales, &localespb.Locale{Id: l.ID, Name: l.Name, SpaceId: l.SpaceID})
func ListPtrLocalesLocaleToProto(ls []*locales.Locale) ([]*localespb.Locale, error) {
protoLocales := make([]*localespb.Locale, 0, len(ls))
for _, l := range ls {
protoLocales = append(protoLocales, locales.LocaleToProto(l))
}
return protoLocales, nil
}
......@@ -35,7 +35,7 @@ func ListPtrLocalesLocaleToProto(locales []*locales.Locale) ([]*localespb.Locale
func ProtoToListPtrLocalesLocale(protoLocales []*localespb.Locale) ([]*locales.Locale, error) {
ls := make([]*locales.Locale, 0, len(protoLocales))
for _, pl := range protoLocales {
ls = append(ls, &locales.Locale{ID: pl.Id, Name: pl.Name, SpaceID: pl.SpaceId})
ls = append(ls, locales.LocaleFromProto(pl))
}
return ls, nil
}
......@@ -190,33 +190,11 @@ func PtrItemsItemToProto(item *items.Item) (*itemspb.Item, error) {
return nil, nil
}
protoItem := &itemspb.Item{
Id: item.ID,
SpaceId: item.SpaceID,
EnvId: item.EnvID,
CollectionId: item.CollectionID,
State: itemspb.Item_State(item.State),
CreatedBy: item.CreatedBy,
UpdatedBy: item.UpdatedBy,
RevisionId: item.RevisionID,
LocaleId: item.LocaleID,
//Hidden, Template, Deleted - не передается для delivery
}
var err error
protoItem.Data, err = MapStringInterfaceToProto(item.Data)
if err != nil {
return nil, err
}
protoItem.Translations, err = MapStringMapStringInterfaceToProto(item.Translations)
if err != nil {
return nil, err
}
//protoItem.Permissions - не передается для delivery
protoItem.CreatedRevAt = timestamppb.New(item.CreatedRevAt)
protoItem.CreatedAt = timestamppb.New(item.CreatedAt)
protoItem.UpdatedAt = timestamppb.New(item.UpdatedAt)
protoItem := items.ItemToProto(item)
protoItem.Permissions = nil
protoItem.Hidden = false
protoItem.Template = false
protoItem.Deleted = false
return protoItem, nil
}
......@@ -226,26 +204,11 @@ func ProtoToPtrItemsItem(protoItem *itemspb.Item) (*items.Item, error) {
return nil, nil
}
item := &items.Item{
ID: protoItem.Id,
SpaceID: protoItem.SpaceId,
EnvID: protoItem.EnvId,
CollectionID: protoItem.CollectionId,
State: items.State(protoItem.State),
CreatedBy: protoItem.CreatedBy,
UpdatedBy: protoItem.UpdatedBy,
RevisionID: protoItem.RevisionId,
LocaleID: protoItem.LocaleId,
//Hidden, Template, Deleted - не передается для delivery
}
item.Data, _ = ProtoToMapStringInterface(protoItem.Data)
item.Translations, _ = ProtoToMapStringMapStringInterface(protoItem.Translations)
//item.Permissions - не передается для delivery
item.CreatedRevAt = protoItem.CreatedRevAt.AsTime()
item.CreatedAt = protoItem.CreatedAt.AsTime()
item.UpdatedAt = protoItem.UpdatedAt.AsTime()
item := items.ItemFromProto(protoItem)
item.Permissions = nil
item.Hidden = false
item.Template = false
item.Deleted = false
return item, nil
}
......
package locales
import "golang.org/x/text/language"
import (
pb "git.perx.ru/perxis/perxis-go/proto/locales"
"golang.org/x/text/language"
)
const (
DefaultID = "default" // DefaultID идентификатор локали по умолчанию
......@@ -42,3 +45,41 @@ func GetIDs(locales []*Locale) []string {
}
return result
}
func LocaleToProto(locale *Locale) *pb.Locale {
if locale == nil {
return nil
}
protoLocale := &pb.Locale{
Id: locale.ID,
SpaceId: locale.SpaceID,
Name: locale.Name,
NativeName: locale.NativeName,
Code: locale.Code,
Fallback: locale.Fallback,
Direction: locale.Direction,
Weight: int64(locale.Weight),
NoPublish: locale.NoPublish,
Disabled: locale.Disabled,
}
return protoLocale
}
func LocaleFromProto(protoLocale *pb.Locale) *Locale {
if protoLocale == nil {
return nil
}
locale := &Locale{
ID: protoLocale.Id,
SpaceID: protoLocale.SpaceId,
Name: protoLocale.Name,
NativeName: protoLocale.NativeName,
Code: protoLocale.Code,
Fallback: protoLocale.Fallback,
Direction: protoLocale.Direction,
Weight: int(protoLocale.Weight),
NoPublish: protoLocale.NoPublish,
Disabled: protoLocale.Disabled,
}
return locale
}
......@@ -13,36 +13,14 @@ func PtrLocaleToProto(locale *service.Locale) (*pb.Locale, error) {
if locale == nil {
return nil, nil
}
return &pb.Locale{
Id: locale.ID,
SpaceId: locale.SpaceID,
Name: locale.Name,
NativeName: locale.NativeName,
Code: locale.Code,
Fallback: locale.Fallback,
Direction: locale.Direction,
Weight: int64(locale.Weight),
NoPublish: locale.NoPublish,
Disabled: locale.Disabled,
}, nil
return service.LocaleToProto(locale), nil
}
func ProtoToPtrLocale(protoLocale *pb.Locale) (*service.Locale, error) {
if protoLocale == nil {
return nil, nil
}
return &service.Locale{
ID: protoLocale.Id,
SpaceID: protoLocale.SpaceId,
Name: protoLocale.Name,
NativeName: protoLocale.NativeName,
Code: protoLocale.Code,
Fallback: protoLocale.Fallback,
Direction: protoLocale.Direction,
Weight: int(protoLocale.Weight),
NoPublish: protoLocale.NoPublish,
Disabled: protoLocale.Disabled,
}, nil
return service.LocaleFromProto(protoLocale), nil
}
func ListPtrLocaleToProto(locales []*service.Locale) ([]*pb.Locale, error) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment