Skip to content
Snippets Groups Projects
Commit 51517e17 authored by Pavel Antonov's avatar Pavel Antonov :asterisk:
Browse files

Merge branch 'feature/PRXS-2646-RevisionLocalesAPI' into 'master'

Обновлено API Locales для соответствия спецификации Proto

See merge request perxis/perxis-go!249
parents 95c4ff6b 92827f1d
No related branches found
No related tags found
No related merge requests found
......@@ -13,14 +13,36 @@ func PtrLocaleToProto(locale *service.Locale) (*pb.Locale, error) {
if locale == nil {
return nil, nil
}
return &pb.Locale{Id: locale.ID, Name: locale.Name, SpaceId: locale.SpaceID}, 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
}
func ProtoToPtrLocale(protoLocale *pb.Locale) (*service.Locale, error) {
if protoLocale == nil {
return nil, nil
}
return &service.Locale{ID: protoLocale.Id, Name: protoLocale.Name, SpaceID: protoLocale.SpaceId}, 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
}
func ListPtrLocaleToProto(locales []*service.Locale) ([]*pb.Locale, error) {
......
......@@ -12,6 +12,7 @@ func NewServer(svc locales.Locales, opts ...grpckit.ServerOption) pb.LocalesServ
eps := transport.Endpoints(svc)
eps = transport.EndpointsSet{
CreateEndpoint: grpcerr.ServerMiddleware(eps.CreateEndpoint),
UpdateEndpoint: grpcerr.ServerMiddleware(eps.UpdateEndpoint),
DeleteEndpoint: grpcerr.ServerMiddleware(eps.DeleteEndpoint),
ListEndpoint: grpcerr.ServerMiddleware(eps.ListEndpoint),
}
......
......@@ -13,6 +13,7 @@ import (
type localesServer struct {
create grpc.Handler
update grpc.Handler
list grpc.Handler
delete grpc.Handler
......@@ -27,6 +28,12 @@ func NewGRPCServer(endpoints *transport.EndpointsSet, opts ...grpc.ServerOption)
_Encode_Create_Response,
opts...,
),
update: grpc.NewServer(
endpoints.UpdateEndpoint,
_Decode_Update_Request,
_Encode_Update_Response,
opts...,
),
delete: grpc.NewServer(
endpoints.DeleteEndpoint,
_Decode_Delete_Request,
......@@ -50,6 +57,14 @@ func (S *localesServer) Create(ctx context.Context, req *pb.CreateRequest) (*pb.
return resp.(*pb.CreateResponse), nil
}
func (S *localesServer) Update(ctx context.Context, req *pb.UpdateRequest) (*empty.Empty, error) {
_, resp, err := S.update.ServeGRPC(ctx, req)
if err != nil {
return nil, err
}
return resp.(*empty.Empty), nil
}
func (S *localesServer) List(ctx context.Context, req *pb.ListRequest) (*pb.ListResponse, error) {
_, resp, err := S.list.ServeGRPC(ctx, req)
if err != nil {
......
......@@ -12,6 +12,7 @@ import (
func Endpoints(svc locales.Locales) EndpointsSet {
return EndpointsSet{
CreateEndpoint: CreateEndpoint(svc),
UpdateEndpoint: UpdateEndpoint(svc),
DeleteEndpoint: DeleteEndpoint(svc),
ListEndpoint: ListEndpoint(svc),
}
......@@ -25,6 +26,14 @@ func CreateEndpoint(svc locales.Locales) endpoint.Endpoint {
}
}
func UpdateEndpoint(svc locales.Locales) endpoint.Endpoint {
return func(arg0 context.Context, request interface{}) (interface{}, error) {
req := request.(*UpdateRequest)
res1 := svc.Update(arg0, req.Locale)
return &UpdateResponse{}, res1
}
}
func ListEndpoint(svc locales.Locales) endpoint.Endpoint {
return func(arg0 context.Context, request interface{}) (interface{}, error) {
req := request.(*ListRequest)
......@@ -36,7 +45,7 @@ func ListEndpoint(svc locales.Locales) endpoint.Endpoint {
func DeleteEndpoint(svc locales.Locales) endpoint.Endpoint {
return func(arg0 context.Context, request interface{}) (interface{}, error) {
req := request.(*DeleteRequest)
res0 := svc.Delete(arg0, req.SpaceId, req.LocaleId)
res0 := svc.Delete(arg0, req.SpaceId, req.Id)
return &DeleteResponse{}, res0
}
}
This diff is collapsed.
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
// versions:
// - protoc-gen-go-grpc v1.3.0
// - protoc v4.24.3
// - protoc-gen-go-grpc v1.4.0
// - protoc v5.26.1
// source: locales/locales.proto
package locales
......@@ -16,11 +16,12 @@ import (
// This is a compile-time assertion to ensure that this generated file
// is compatible with the grpc package it is being compiled against.
// Requires gRPC-Go v1.32.0 or later.
const _ = grpc.SupportPackageIsVersion7
// Requires gRPC-Go v1.62.0 or later.
const _ = grpc.SupportPackageIsVersion8
const (
Locales_Create_FullMethodName = "/content.locales.Locales/Create"
Locales_Update_FullMethodName = "/content.locales.Locales/Update"
Locales_List_FullMethodName = "/content.locales.Locales/List"
Locales_Delete_FullMethodName = "/content.locales.Locales/Delete"
)
......@@ -29,8 +30,13 @@ const (
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type LocalesClient interface {
// Создать локаль
Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error)
// Обновить локаль
Update(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
// Получить список локалей
List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error)
// Удалить локаль
Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
}
......@@ -43,8 +49,19 @@ func NewLocalesClient(cc grpc.ClientConnInterface) LocalesClient {
}
func (c *localesClient) Create(ctx context.Context, in *CreateRequest, opts ...grpc.CallOption) (*CreateResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(CreateResponse)
err := c.cc.Invoke(ctx, Locales_Create_FullMethodName, in, out, opts...)
err := c.cc.Invoke(ctx, Locales_Create_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *localesClient) Update(ctx context.Context, in *UpdateRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(emptypb.Empty)
err := c.cc.Invoke(ctx, Locales_Update_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
......@@ -52,8 +69,9 @@ func (c *localesClient) Create(ctx context.Context, in *CreateRequest, opts ...g
}
func (c *localesClient) List(ctx context.Context, in *ListRequest, opts ...grpc.CallOption) (*ListResponse, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(ListResponse)
err := c.cc.Invoke(ctx, Locales_List_FullMethodName, in, out, opts...)
err := c.cc.Invoke(ctx, Locales_List_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
......@@ -61,8 +79,9 @@ func (c *localesClient) List(ctx context.Context, in *ListRequest, opts ...grpc.
}
func (c *localesClient) Delete(ctx context.Context, in *DeleteRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(emptypb.Empty)
err := c.cc.Invoke(ctx, Locales_Delete_FullMethodName, in, out, opts...)
err := c.cc.Invoke(ctx, Locales_Delete_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
......@@ -73,8 +92,13 @@ func (c *localesClient) Delete(ctx context.Context, in *DeleteRequest, opts ...g
// All implementations must embed UnimplementedLocalesServer
// for forward compatibility
type LocalesServer interface {
// Создать локаль
Create(context.Context, *CreateRequest) (*CreateResponse, error)
// Обновить локаль
Update(context.Context, *UpdateRequest) (*emptypb.Empty, error)
// Получить список локалей
List(context.Context, *ListRequest) (*ListResponse, error)
// Удалить локаль
Delete(context.Context, *DeleteRequest) (*emptypb.Empty, error)
mustEmbedUnimplementedLocalesServer()
}
......@@ -86,6 +110,9 @@ type UnimplementedLocalesServer struct {
func (UnimplementedLocalesServer) Create(context.Context, *CreateRequest) (*CreateResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Create not implemented")
}
func (UnimplementedLocalesServer) Update(context.Context, *UpdateRequest) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method Update not implemented")
}
func (UnimplementedLocalesServer) List(context.Context, *ListRequest) (*ListResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method List not implemented")
}
......@@ -123,6 +150,24 @@ func _Locales_Create_Handler(srv interface{}, ctx context.Context, dec func(inte
return interceptor(ctx, in, info, handler)
}
func _Locales_Update_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpdateRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(LocalesServer).Update(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: Locales_Update_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(LocalesServer).Update(ctx, req.(*UpdateRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Locales_List_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ListRequest)
if err := dec(in); err != nil {
......@@ -170,6 +215,10 @@ var Locales_ServiceDesc = grpc.ServiceDesc{
MethodName: "Create",
Handler: _Locales_Create_Handler,
},
{
MethodName: "Update",
Handler: _Locales_Update_Handler,
},
{
MethodName: "List",
Handler: _Locales_List_Handler,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment