Compare commits

...

29 Commits

Author SHA1 Message Date
Владимир Фёдоров 236dd66cd0 fix
continuous-integration/drone/push Build is passing Details
2024-10-05 00:49:48 +07:00
Владимир Фёдоров fda5a8d5b4 update requests
continuous-integration/drone/push Build is passing Details
2024-09-05 03:59:03 +07:00
Владимир Фёдоров 3e9ce8a653 update .gitignore
continuous-integration/drone/push Build is passing Details
2024-09-05 03:56:51 +07:00
Владимир Фёдоров 797bf40fdc add discount
continuous-integration/drone/push Build is passing Details
2024-09-05 03:54:59 +07:00
Владимир Фёдоров 5ecaa0f09b Merge branch 'master' of https://git.3crabs.ru/cake/cake_crm
continuous-integration/drone/push Build is passing Details
2024-09-05 03:46:03 +07:00
Владимир Фёдоров bd29ac242d add ua check 2024-09-05 03:45:18 +07:00
Владимир Фёдоров b9b6979fbf add photo
continuous-integration/drone/push Build is passing Details
2024-09-01 00:41:15 +07:00
Владимир Фёдоров f40e4bf2e1 update
continuous-integration/drone/push Build is passing Details
2024-08-11 18:41:30 +07:00
Владимир Фёдоров 0a22e69ea4 update
continuous-integration/drone/push Build is failing Details
2024-08-11 18:37:25 +07:00
Владимир Фёдоров 85fa79e5bf add characteristics 2024-08-08 14:57:16 +07:00
Владимир Фёдоров 8992bb0e9d add cache
continuous-integration/drone/push Build is passing Details
2024-05-30 04:32:28 +07:00
Владимир Фёдоров 8be5d0b831 add search
continuous-integration/drone/push Build is passing Details
2024-05-30 04:17:13 +07:00
Владимир Фёдоров 073a7e6d8c update cart
continuous-integration/drone/push Build is passing Details
2024-05-30 03:54:12 +07:00
Владимир Фёдоров 323f50fb43 update request.http
continuous-integration/drone/push Build is passing Details
2024-05-30 03:34:04 +07:00
Владимир Фёдоров 4917ca90fc enrich card
continuous-integration/drone/push Build is passing Details
2024-05-30 03:24:20 +07:00
Владимир Фёдоров 4335d14090 add labels
continuous-integration/drone/push Build is passing Details
2024-05-30 03:03:39 +07:00
Владимир Фёдоров 59e60c4be1 update get breadcrumbs method
continuous-integration/drone/push Build is passing Details
2024-05-30 02:47:24 +07:00
Владимир Фёдоров ccaaddf938 add images
continuous-integration/drone/push Build is passing Details
2024-05-28 03:15:15 +07:00
Владимир Фёдоров 3822d4b23e add images
continuous-integration/drone/push Build is failing Details
2024-05-28 03:11:47 +07:00
Владимир Фёдоров 820306f654 add order service
continuous-integration/drone/push Build is passing Details
2024-05-27 03:21:47 +07:00
Владимир Фёдоров f2aedd7a98 update db
continuous-integration/drone/push Build is passing Details
2024-05-27 02:42:22 +07:00
Владимир Фёдоров 20a2f975fd fix parse files
continuous-integration/drone/push Build is passing Details
2024-05-24 02:15:00 +07:00
Владимир Фёдоров e4741d5de2 fix
continuous-integration/drone/push Build is passing Details
2024-05-24 02:10:08 +07:00
Владимир Фёдоров 9743060604 clear
continuous-integration/drone/push Build is passing Details
2024-05-24 02:07:14 +07:00
Владимир Фёдоров 733691523b Merge remote-tracking branch 'origin/master'
continuous-integration/drone/push Build is passing Details
2024-05-24 02:02:55 +07:00
Владимир Фёдоров 02e18e1618 clear 2024-05-24 02:02:31 +07:00
user-penguin c98ee10f9e Merge remote-tracking branch 'origin/master'
continuous-integration/drone/push Build is passing Details
2024-05-24 01:47:13 +07:00
user-penguin 7f7d2757fb fix 2024-05-24 01:46:08 +07:00
Владимир Фёдоров 40dcee97ea Merge pull request 'add book order' (#1) from orders into master
continuous-integration/drone/push Build is passing Details
Reviewed-on: #1
2024-05-23 18:34:46 +00:00
22 changed files with 2730 additions and 600 deletions

View File

@ -37,6 +37,9 @@ steps:
- deploys/cake_crm - deploys/cake_crm
source: source:
- resources - resources
- resources/images
- telegram_order_chat_id.txt
- order_bot_token.txt
- cake_crm - cake_crm
- docker-compose.yml - docker-compose.yml
- Dockerfile - Dockerfile
@ -56,6 +59,8 @@ steps:
command_timeout: 10s command_timeout: 10s
script: script:
- cd deploys/cake_crm - cd deploys/cake_crm
- mv order_bot_token.txt resources
- mv telegram_order_chat_id.txt resources
- docker-compose up -d --build --force-recreate - docker-compose up -d --build --force-recreate
trigger: trigger:

2
.gitignore vendored
View File

@ -1,4 +1,6 @@
.idea .idea
.vscode
.DS_Store
bin bin

View File

@ -1,5 +1,7 @@
# cake_crm # cake_crm
Маленький магазин
Генерация контракта Генерация контракта
```shell ```shell

View File

@ -3,6 +3,7 @@ syntax = "proto3";
package crabs.crm; package crabs.crm;
import "google/api/annotations.proto"; import "google/api/annotations.proto";
import "google/api/httpbody.proto";
import "protoc-gen-openapiv2/options/annotations.proto"; import "protoc-gen-openapiv2/options/annotations.proto";
option go_package = "pkg/proto"; option go_package = "pkg/proto";
@ -27,7 +28,7 @@ service CRM {
} }
rpc GetBreadcrumbs(GetBreadcrumbsReq) returns (BreadcrumbsRsp) { rpc GetBreadcrumbs(GetBreadcrumbsReq) returns (BreadcrumbsRsp) {
option (google.api.http) = { option (google.api.http) = {
get: "/breadcrumbs/{id}" get: "/products/{id}/breadcrumbs"
}; };
} }
rpc Order(OrderReq) returns (OrderRsp) { rpc Order(OrderReq) returns (OrderRsp) {
@ -36,12 +37,22 @@ service CRM {
body: "order" body: "order"
}; };
} }
rpc GetCard(CardReq) returns (CardRsp) { rpc GetCart(CartReq) returns (CartRsp) {
option (google.api.http) = { option (google.api.http) = {
post: "/card" post: "/cart"
body: "items" body: "items"
}; };
} }
rpc GetImage(GetImageReq) returns (google.api.HttpBody) {
option (google.api.http) = {
get: "/images/{name}"
};
}
rpc Search(SearchReq) returns (PositionsRsp) {
option (google.api.http) = {
get: "/search"
};
}
} }
message GetCatalogReq {} message GetCatalogReq {}
@ -78,6 +89,7 @@ message Product {
repeated Variant variants = 10; repeated Variant variants = 10;
repeated Characteristic characteristics = 11; repeated Characteristic characteristics = 11;
int64 category = 12; int64 category = 12;
repeated Label labels = 13;
} }
message GroupedProduct { message GroupedProduct {
@ -89,6 +101,7 @@ message GroupedProduct {
message Variant { message Variant {
int64 price = 1; int64 price = 1;
repeated Property properties = 2; repeated Property properties = 2;
bool active = 3;
} }
message Property { message Property {
@ -101,6 +114,10 @@ message Characteristic {
string value = 2; string value = 2;
} }
message Label {
string name = 1;
}
message GetProductReq { message GetProductReq {
int64 id = 1; int64 id = 1;
} }
@ -119,13 +136,13 @@ message BreadcrumbsRsp {
message OrderReq { message OrderReq {
Order order = 1; Order order = 1;
string name = 2;
string phone = 3;
} }
message OrderRsp {} message OrderRsp {}
message Order { message Order {
string name = 2;
string phone = 3;
repeated OrderItem items = 1; repeated OrderItem items = 1;
} }
@ -134,7 +151,7 @@ message OrderItem {
int64 count = 2; int64 count = 2;
} }
message CardItem { message CartItem {
int64 id = 1; int64 id = 1;
string article = 2; string article = 2;
string name = 3; string name = 3;
@ -144,12 +161,27 @@ message CardItem {
double inventory = 9; double inventory = 9;
int64 count = 10; int64 count = 10;
int64 amount = 11; int64 amount = 11;
int64 amountOld = 12;
int64 discount = 13;
repeated Variant variants = 14;
repeated Label labels = 15;
} }
message CardReq { message CartReq {
repeated OrderItem items = 1; repeated OrderItem items = 1;
} }
message CardRsp { message CartRsp {
repeated CardItem items = 1; repeated CartItem items = 1;
int64 amount = 2;
int64 amountOld = 3;
int64 discount = 4;
}
message GetImageReq {
string name = 1;
}
message SearchReq {
string text = 1;
} }

56
api/request.http Normal file
View File

@ -0,0 +1,56 @@
GET http://localhost:8090/catalog
User-Agent: crabs/1.0.0
###
# prod
GET http://cake-api.3crabs.ru/catalog
User-Agent: crabs/1.0.0
###
GET http://localhost:8090/products/1
User-Agent: crabs/1.0.0
###
POST http://localhost:8090/cart
User-Agent: crabs/1.0.0
Content-Type: application/json
[
{
"product_id": 1,
"count": 7
},
{
"product_id": 20,
"count": 15
}
]
###
POST http://localhost:8090/orders
User-Agent: crabs/1.0.0
Content-Type: application/json
{
"name": "Иванов Иван",
"phone": "+7-000-000-00-00",
"items": [
{
"product_id": 1,
"count": 7
},
{
"product_id": 20,
"count": 15
}
]
}
###
GET http://localhost:8090/search?text=Лимон
User-Agent: crabs/1.0.0

View File

@ -1,40 +1,52 @@
package main package main
import ( import (
"cake_crm/internal/app"
"cake_crm/internal/modules/messenger/telegram"
"cake_crm/internal/modules/storage/storage_file"
"cake_crm/internal/services/card"
proto "cake_crm/proto"
"context" "context"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"log" "log"
"net" "net"
"net/http" "net/http"
"os" "os"
"strconv" "strconv"
"strings"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"cake_crm/internal/app"
"cake_crm/internal/modules/messenger/telegram"
"cake_crm/internal/modules/storage/storage_file"
"cake_crm/internal/services/cart"
"cake_crm/internal/services/order"
proto "cake_crm/proto"
) )
func main() { func main() {
storage := storage_file.NewStorageFile() storage := storage_file.NewStorageFile()
cardService := card.NewService(storage) cartService := cart.NewService(storage)
orderService := order.NewService()
tokenData, err := os.ReadFile("resources/order_bot_token.txt") tokenData, err := os.ReadFile("resources/order_bot_token.txt")
if err != nil { if err != nil {
panic(err) panic(err)
} }
token := string(tokenData) token := strings.TrimSpace(string(tokenData))
chatIdData, err := os.ReadFile("resources/telegram_order_chat_id.txt") chatIdData, err := os.ReadFile("resources/telegram_order_chat_id.txt")
if err != nil { if err != nil {
panic(err) panic(err)
} }
chatID, err := strconv.ParseInt(string(chatIdData), 10, 64) chatID, err := strconv.ParseInt(strings.TrimSpace(string(chatIdData)), 10, 64)
if err != nil {
panic(err)
}
messenger, err := telegram.NewMessenger(chatID, token) messenger, err := telegram.NewMessenger(chatID, token)
if err != nil {
panic(err)
}
// Create a listener on TCP port // Create a listener on TCP port
lis, err := net.Listen("tcp", ":8080") lis, err := net.Listen("tcp", ":8080")
@ -45,7 +57,7 @@ func main() {
// Create a gRPC server object // Create a gRPC server object
s := grpc.NewServer() s := grpc.NewServer()
// Attach the Greeter service to the server // Attach the Greeter service to the server
proto.RegisterCRMServer(s, app.NewServer(storage, messenger, cardService)) proto.RegisterCRMServer(s, app.NewServer(storage, messenger, cartService, orderService))
// Serve gRPC server // Serve gRPC server
log.Println("Serving gRPC on 0.0.0.0:8080") log.Println("Serving gRPC on 0.0.0.0:8080")
go func() { go func() {
@ -92,6 +104,12 @@ func main() {
func cors(h http.Handler) http.Handler { func cors(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// ua := r.Header.Get("User-Agent")
// if !strings.HasPrefix(ua, "crabs") {
// w.WriteHeader(403)
// return
// }
w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PATCH, DELETE") w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PATCH, DELETE")
w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, Authorization, ResponseType") w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, Authorization, ResponseType")

1
go.mod
View File

@ -5,6 +5,7 @@ go 1.22
require ( require (
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1 github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0
github.com/patrickmn/go-cache v2.1.0+incompatible
google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8 google.golang.org/genproto/googleapis/api v0.0.0-20240513163218-0867130af1f8
google.golang.org/grpc v1.64.0 google.golang.org/grpc v1.64.0
google.golang.org/protobuf v1.34.1 google.golang.org/protobuf v1.34.1

2
go.sum
View File

@ -4,6 +4,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0= github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k= github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k=
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=

View File

@ -1,28 +1,36 @@
package app package app
import ( import (
"bytes"
"cake_crm/internal/modules/messenger" "cake_crm/internal/modules/messenger"
"cake_crm/internal/modules/storage" "cake_crm/internal/modules/storage"
"cake_crm/internal/services/card" "cake_crm/internal/services/cart"
"cake_crm/internal/services/order"
proto "cake_crm/proto" proto "cake_crm/proto"
"context" "context"
"errors"
"fmt" "fmt"
"google.golang.org/genproto/googleapis/api/httpbody"
"os"
) )
type Server struct { type Server struct {
proto.UnsafeCRMServer proto.UnsafeCRMServer
storage storage.IStorage storage storage.IStorage
messenger messenger.IMessenger messenger messenger.IMessenger
cardService *card.Service cartService *cart.Service
orderService *order.Service
} }
func NewServer(storage storage.IStorage, messenger messenger.IMessenger, cardService *card.Service) proto.CRMServer { func NewServer(
storage storage.IStorage,
messenger messenger.IMessenger,
cartService *cart.Service,
orderService *order.Service,
) proto.CRMServer {
return &Server{ return &Server{
storage: storage, storage: storage,
messenger: messenger, messenger: messenger,
cardService: cardService, cartService: cartService,
orderService: orderService,
} }
} }
@ -59,53 +67,40 @@ func (s *Server) GetBreadcrumbs(ctx context.Context, req *proto.GetBreadcrumbsRe
} }
func (s *Server) Order(ctx context.Context, req *proto.OrderReq) (*proto.OrderRsp, error) { func (s *Server) Order(ctx context.Context, req *proto.OrderReq) (*proto.OrderRsp, error) {
enrichItems, err := s.cardService.GetCard(ctx, req.Order.Items) enrichItems, err := s.cartService.GetCart(ctx, req.Order.Items)
if err != nil { if err != nil {
return nil, err return nil, err
} }
text, err := createOrderText(req, enrichItems) text, err := s.orderService.CreateOrderText(req, enrichItems)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &proto.OrderRsp{}, s.messenger.SendMessage(text) return &proto.OrderRsp{}, s.messenger.SendMessage(text)
} }
func createOrderText(req *proto.OrderReq, items []*proto.CardItem) (string, error) { func (s *Server) GetCart(ctx context.Context, req *proto.CartReq) (*proto.CartRsp, error) {
buffer := bytes.Buffer{} resp, err := s.cartService.GetCart(ctx, req.Items)
var orderAmount int64
buffer.WriteString(fmt.Sprintf("Заказ от:\n%s\n%s\n", req.Name, req.Phone))
buffer.WriteString("\n")
for _, item := range items {
buffer.WriteString(item.Name)
buffer.WriteString("\n")
unit, err := unitToText(item.Unit)
if err != nil {
return "", err
}
buffer.WriteString(fmt.Sprintf("Количество: %d%s\n", item.Count, unit))
orderAmount += item.Amount
buffer.WriteString(fmt.Sprintf("Сумма: %.00fр\n", float64(item.Amount)/100))
buffer.WriteString("\n")
}
buffer.WriteString("\n")
buffer.WriteString(fmt.Sprintf("ИТОГО: %.00fр\n", float64(orderAmount)/100))
return buffer.String(), nil
}
func unitToText(unit string) (string, error) {
switch unit {
case "kg":
return "кг", nil
case "piece":
return "шт", nil
}
return "", errors.New("unit not found")
}
func (s *Server) GetCard(ctx context.Context, req *proto.CardReq) (*proto.CardRsp, error) {
enrichItems, err := s.cardService.GetCard(ctx, req.Items)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &proto.CardRsp{Items: enrichItems}, nil return resp, nil
}
func (s *Server) GetImage(_ context.Context, req *proto.GetImageReq) (*httpbody.HttpBody, error) {
data, err := os.ReadFile(fmt.Sprintf("resources/images/%s", req.Name))
if err != nil {
return nil, err
}
return &httpbody.HttpBody{
ContentType: "image/jpeg",
Data: data,
}, nil
}
func (s *Server) Search(ctx context.Context, req *proto.SearchReq) (*proto.PositionsRsp, error) {
products, err := s.storage.GetPositionsByText(ctx, req.Text)
if err != nil {
return nil, err
}
return &proto.PositionsRsp{Products: products}, nil
} }

View File

@ -10,4 +10,5 @@ type IStorage interface {
GetPositions(ctx context.Context, id int64) ([]*crm.Product, error) GetPositions(ctx context.Context, id int64) ([]*crm.Product, error)
GetProduct(ctx context.Context, id int64) (*crm.Product, error) GetProduct(ctx context.Context, id int64) (*crm.Product, error)
GetBreadcrumbs(ctx context.Context, id int64) ([]*crm.Category, error) GetBreadcrumbs(ctx context.Context, id int64) ([]*crm.Category, error)
GetPositionsByText(ctx context.Context, text string) ([]*crm.Product, error)
} }

View File

@ -6,21 +6,45 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"github.com/patrickmn/go-cache"
"os" "os"
"strings"
"time"
) )
type Product struct {
Id int64 `json:"id"`
Article string `json:"article"`
Name string `json:"name"`
Uri string `json:"uri"`
Images []string `json:"images"`
Description string `json:"description"`
Group int64 `json:"group"`
Unit string `json:"unit"`
Inventory float64 `json:"inventory"`
Variants []*crm.Variant `json:"variants"`
Characteristics []*crm.Characteristic `json:"characteristics"`
Category int64 `json:"category"`
Labels []*crm.Label `json:"labels"`
}
var ( var (
ErrProductNotFound = errors.New("product not found") ErrProductNotFound = errors.New("product not found")
) )
type storageFile struct{} type storageFile struct {
cache *cache.Cache
}
func NewStorageFile() storage.IStorage { func NewStorageFile() storage.IStorage {
return &storageFile{} return &storageFile{
cache: cache.New(24*time.Hour, time.Hour),
}
} }
func (s *storageFile) GetCatalog(_ context.Context) ([]*crm.Category, error) { func (s *storageFile) GetCatalog(_ context.Context) ([]*crm.Category, error) {
data, err := os.ReadFile("resources/catalog.json") data, err := s.readFile("catalog")
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -32,7 +56,7 @@ func (s *storageFile) GetCatalog(_ context.Context) ([]*crm.Category, error) {
} }
func (s *storageFile) GetPositions(_ context.Context, id int64) ([]*crm.Product, error) { func (s *storageFile) GetPositions(_ context.Context, id int64) ([]*crm.Product, error) {
data, err := os.ReadFile("resources/products.json") data, err := s.readFile("products")
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -43,6 +67,7 @@ func (s *storageFile) GetPositions(_ context.Context, id int64) ([]*crm.Product,
res := make([]*crm.Product, 0, len(products)) res := make([]*crm.Product, 0, len(products))
for _, product := range products { for _, product := range products {
if id == 0 || product.Category == id { if id == 0 || product.Category == id {
s.enrichedProduct(product)
res = append(res, product) res = append(res, product)
} }
} }
@ -50,24 +75,62 @@ func (s *storageFile) GetPositions(_ context.Context, id int64) ([]*crm.Product,
} }
func (s *storageFile) GetProduct(_ context.Context, id int64) (*crm.Product, error) { func (s *storageFile) GetProduct(_ context.Context, id int64) (*crm.Product, error) {
data, err := os.ReadFile("resources/products.json") data, err := s.readFile("products")
if err != nil { if err != nil {
return nil, err return nil, err
} }
var products []*crm.Product var products []*Product
if err := json.Unmarshal(data, &products); err != nil { if err := json.Unmarshal(data, &products); err != nil {
return nil, err return nil, err
} }
for _, product := range products { var product *Product
if product.Id == id { for _, p := range products {
return product, nil if p.Id == id {
product = p
break
} }
} }
return nil, ErrProductNotFound if product == nil {
return nil, ErrProductNotFound
}
res := &crm.Product{
Id: product.Id,
Article: product.Article,
Name: product.Name,
Uri: product.Uri,
Images: product.Images,
Description: product.Description,
GroupedProducts: nil,
Unit: product.Unit,
Inventory: product.Inventory,
Variants: product.Variants,
Characteristics: product.Characteristics,
Category: product.Category,
Labels: product.Labels,
}
s.enrichedProduct(res)
for _, p := range products {
if p.Group == product.Group {
image := ""
if len(product.Images) > 0 {
image = p.Images[0]
}
res.GroupedProducts = append(res.GroupedProducts, &crm.GroupedProduct{
Name: p.Name,
Uri: p.Uri,
Image: image,
})
}
}
return res, nil
} }
func (s *storageFile) GetBreadcrumbs(_ context.Context, id int64) ([]*crm.Category, error) { func (s *storageFile) GetBreadcrumbs(ctx context.Context, id int64) ([]*crm.Category, error) {
data, err := os.ReadFile("resources/catalog.json") product, err := s.GetProduct(ctx, id)
if err != nil {
return nil, err
}
data, err := s.readFile("catalog")
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -75,7 +138,17 @@ func (s *storageFile) GetBreadcrumbs(_ context.Context, id int64) ([]*crm.Catego
if err := json.Unmarshal(data, &categories); err != nil { if err := json.Unmarshal(data, &categories); err != nil {
return nil, err return nil, err
} }
return getBreadcrumbs(categories, id), nil breadcrumbs := getBreadcrumbs(categories, product.Id)
breadcrumbs = append(breadcrumbs, &crm.Category{
Name: product.Name,
})
return breadcrumbs, nil
}
func (s *storageFile) enrichedProduct(product *crm.Product) {
if len(product.Variants) > 1 {
product.Labels = append(product.Labels, &crm.Label{Name: "Оптом дешевле"})
}
} }
func getBreadcrumbs(categories []*crm.Category, id int64) []*crm.Category { func getBreadcrumbs(categories []*crm.Category, id int64) []*crm.Category {
@ -95,3 +168,37 @@ func getBreadcrumbs(categories []*crm.Category, id int64) []*crm.Category {
} }
return nil return nil
} }
func (s *storageFile) GetPositionsByText(_ context.Context, text string) ([]*crm.Product, error) {
data, err := s.readFile("products")
if err != nil {
return nil, err
}
var products []*crm.Product
if err := json.Unmarshal(data, &products); err != nil {
return nil, err
}
res := make([]*crm.Product, 0, len(products))
searchText := strings.TrimSpace(strings.ToLower(text))
for _, product := range products {
name := strings.ToLower(product.Name)
if strings.Contains(name, searchText) {
s.enrichedProduct(product)
res = append(res, product)
}
}
return res, nil
}
func (s *storageFile) readFile(name string) ([]byte, error) {
cacheData, found := s.cache.Get(name)
if found {
return cacheData.([]byte), nil
}
data, err := os.ReadFile(fmt.Sprintf("resources/%s.json", name))
if err != nil {
return nil, err
}
s.cache.Set(name, data, cache.DefaultExpiration)
return data, nil
}

View File

@ -1,11 +1,12 @@
package card package cart
import ( import (
"cake_crm/internal/modules/storage"
"cake_crm/proto"
"context" "context"
"errors" "errors"
"strconv" "strconv"
"cake_crm/internal/modules/storage"
"cake_crm/proto"
) )
type ProductAndCount struct { type ProductAndCount struct {
@ -23,14 +24,16 @@ func NewService(storage storage.IStorage) *Service {
} }
} }
func (s *Service) GetCard(ctx context.Context, items []*proto.OrderItem) ([]*proto.CardItem, error) { func (s *Service) GetCart(ctx context.Context, items []*proto.OrderItem) (*proto.CartRsp, error) {
res := make([]*proto.CardItem, 0, len(items)) var cartAmount int64
var cartAmountOld int64
res := make([]*proto.CartItem, 0, len(items))
for _, item := range items { for _, item := range items {
product, err := s.storage.GetProduct(ctx, item.ProductId) product, err := s.storage.GetProduct(ctx, item.ProductId)
if err != nil { if err != nil {
return nil, err return nil, err
} }
amount, err := calcItemAmount( amount, amountOld, err := calcItemAmount(
&ProductAndCount{ &ProductAndCount{
product: product, product: product,
count: item.Count, count: item.Count,
@ -41,7 +44,7 @@ func (s *Service) GetCard(ctx context.Context, items []*proto.OrderItem) ([]*pro
} }
res = append( res = append(
res, res,
&proto.CardItem{ &proto.CartItem{
Id: product.Id, Id: product.Id,
Article: product.Article, Article: product.Article,
Name: product.Name, Name: product.Name,
@ -51,13 +54,25 @@ func (s *Service) GetCard(ctx context.Context, items []*proto.OrderItem) ([]*pro
Inventory: product.Inventory, Inventory: product.Inventory,
Count: item.Count, Count: item.Count,
Amount: amount, Amount: amount,
AmountOld: amountOld,
Discount: amountOld - amount,
Variants: product.Variants,
Labels: product.Labels,
}, },
) )
cartAmount += amount
cartAmountOld += amountOld
} }
return res, nil return &proto.CartRsp{
Items: res,
Amount: cartAmount,
AmountOld: cartAmountOld,
Discount: cartAmountOld - cartAmount,
}, nil
} }
func calcItemAmount(item *ProductAndCount) (int64, error) { func calcItemAmount(item *ProductAndCount) (int64, int64, error) {
variantOld := item.product.Variants[0]
var variant *proto.Variant var variant *proto.Variant
for _, v := range item.product.Variants { for _, v := range item.product.Variants {
check := true check := true
@ -65,7 +80,7 @@ func calcItemAmount(item *ProductAndCount) (int64, error) {
if property.Name == "min" { if property.Name == "min" {
minBorder, err := strconv.ParseInt(property.Value, 10, 64) minBorder, err := strconv.ParseInt(property.Value, 10, 64)
if err != nil { if err != nil {
return 0, err return 0, 0, err
} }
if item.count < minBorder { if item.count < minBorder {
check = false check = false
@ -74,7 +89,7 @@ func calcItemAmount(item *ProductAndCount) (int64, error) {
if property.Name == "max" { if property.Name == "max" {
maxBorder, err := strconv.ParseInt(property.Value, 10, 64) maxBorder, err := strconv.ParseInt(property.Value, 10, 64)
if err != nil { if err != nil {
return 0, err return 0, 0, err
} }
if item.count > maxBorder { if item.count > maxBorder {
check = false check = false
@ -86,8 +101,9 @@ func calcItemAmount(item *ProductAndCount) (int64, error) {
} }
} }
} }
variant.Active = true
if variant == nil { if variant == nil {
return 0, errors.New("variant not found") return 0, 0, errors.New("variant not found")
} }
return variant.Price * item.count, nil return variant.Price * item.count, variantOld.Price * item.count, nil
} }

View File

@ -0,0 +1,44 @@
package order
import (
"bytes"
"cake_crm/proto"
"errors"
"fmt"
)
type Service struct{}
func NewService() *Service {
return &Service{}
}
func (s *Service) CreateOrderText(req *proto.OrderReq, cart *proto.CartRsp) (string, error) {
buffer := bytes.Buffer{}
buffer.WriteString(fmt.Sprintf("Заказ от:\n%s\n%s\n", req.Order.Name, req.Order.Phone))
buffer.WriteString("\n")
for _, item := range cart.Items {
buffer.WriteString(item.Name)
buffer.WriteString("\n")
unit, err := unitToText(item.Unit)
if err != nil {
return "", err
}
buffer.WriteString(fmt.Sprintf("Количество: %d%s\n", item.Count, unit))
buffer.WriteString(fmt.Sprintf("Сумма: %.00fр\n", float64(item.Amount)/100))
buffer.WriteString("\n")
}
buffer.WriteString("\n")
buffer.WriteString(fmt.Sprintf("ИТОГО: %.00fр\n", float64(cart.Amount)/100))
return buffer.String(), nil
}
func unitToText(unit string) (string, error) {
switch unit {
case "kg":
return "кг", nil
case "piece":
return "шт", nil
}
return "", errors.New("unit not found")
}

File diff suppressed because it is too large Load Diff

View File

@ -205,10 +205,6 @@ func local_request_CRM_GetBreadcrumbs_0(ctx context.Context, marshaler runtime.M
} }
var (
filter_CRM_Order_0 = &utilities.DoubleArray{Encoding: map[string]int{"order": 0}, Base: []int{1, 1, 0}, Check: []int{0, 1, 2}}
)
func request_CRM_Order_0(ctx context.Context, marshaler runtime.Marshaler, client CRMClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { func request_CRM_Order_0(ctx context.Context, marshaler runtime.Marshaler, client CRMClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq OrderReq var protoReq OrderReq
var metadata runtime.ServerMetadata var metadata runtime.ServerMetadata
@ -217,13 +213,6 @@ func request_CRM_Order_0(ctx context.Context, marshaler runtime.Marshaler, clien
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
} }
if err := req.ParseForm(); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_CRM_Order_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.Order(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) msg, err := client.Order(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err return msg, metadata, err
@ -237,40 +226,121 @@ func local_request_CRM_Order_0(ctx context.Context, marshaler runtime.Marshaler,
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
} }
if err := req.ParseForm(); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_CRM_Order_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.Order(ctx, &protoReq) msg, err := server.Order(ctx, &protoReq)
return msg, metadata, err return msg, metadata, err
} }
func request_CRM_GetCard_0(ctx context.Context, marshaler runtime.Marshaler, client CRMClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { func request_CRM_GetCart_0(ctx context.Context, marshaler runtime.Marshaler, client CRMClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq CardReq var protoReq CartReq
var metadata runtime.ServerMetadata var metadata runtime.ServerMetadata
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.Items); err != nil && err != io.EOF { if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.Items); err != nil && err != io.EOF {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
} }
msg, err := client.GetCard(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) msg, err := client.GetCart(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err return msg, metadata, err
} }
func local_request_CRM_GetCard_0(ctx context.Context, marshaler runtime.Marshaler, server CRMServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { func local_request_CRM_GetCart_0(ctx context.Context, marshaler runtime.Marshaler, server CRMServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq CardReq var protoReq CartReq
var metadata runtime.ServerMetadata var metadata runtime.ServerMetadata
if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.Items); err != nil && err != io.EOF { if err := marshaler.NewDecoder(req.Body).Decode(&protoReq.Items); err != nil && err != io.EOF {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
} }
msg, err := server.GetCard(ctx, &protoReq) msg, err := server.GetCart(ctx, &protoReq)
return msg, metadata, err
}
func request_CRM_GetImage_0(ctx context.Context, marshaler runtime.Marshaler, client CRMClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq GetImageReq
var metadata runtime.ServerMetadata
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["name"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name")
}
protoReq.Name, err = runtime.String(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err)
}
msg, err := client.GetImage(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_CRM_GetImage_0(ctx context.Context, marshaler runtime.Marshaler, server CRMServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq GetImageReq
var metadata runtime.ServerMetadata
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["name"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name")
}
protoReq.Name, err = runtime.String(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err)
}
msg, err := server.GetImage(ctx, &protoReq)
return msg, metadata, err
}
var (
filter_CRM_Search_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
)
func request_CRM_Search_0(ctx context.Context, marshaler runtime.Marshaler, client CRMClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq SearchReq
var metadata runtime.ServerMetadata
if err := req.ParseForm(); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_CRM_Search_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.Search(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_CRM_Search_0(ctx context.Context, marshaler runtime.Marshaler, server CRMServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq SearchReq
var metadata runtime.ServerMetadata
if err := req.ParseForm(); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_CRM_Search_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.Search(ctx, &protoReq)
return msg, metadata, err return msg, metadata, err
} }
@ -364,7 +434,7 @@ func RegisterCRMHandlerServer(ctx context.Context, mux *runtime.ServeMux, server
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error var err error
var annotatedContext context.Context var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/crabs.crm.CRM/GetBreadcrumbs", runtime.WithHTTPPathPattern("/breadcrumbs/{id}")) annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/crabs.crm.CRM/GetBreadcrumbs", runtime.WithHTTPPathPattern("/products/{id}/breadcrumbs"))
if err != nil { if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return return
@ -406,7 +476,7 @@ func RegisterCRMHandlerServer(ctx context.Context, mux *runtime.ServeMux, server
}) })
mux.Handle("POST", pattern_CRM_GetCard_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { mux.Handle("POST", pattern_CRM_GetCart_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context()) ctx, cancel := context.WithCancel(req.Context())
defer cancel() defer cancel()
var stream runtime.ServerTransportStream var stream runtime.ServerTransportStream
@ -414,12 +484,12 @@ func RegisterCRMHandlerServer(ctx context.Context, mux *runtime.ServeMux, server
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error var err error
var annotatedContext context.Context var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/crabs.crm.CRM/GetCard", runtime.WithHTTPPathPattern("/card")) annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/crabs.crm.CRM/GetCart", runtime.WithHTTPPathPattern("/cart"))
if err != nil { if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return return
} }
resp, md, err := local_request_CRM_GetCard_0(annotatedContext, inboundMarshaler, server, req, pathParams) resp, md, err := local_request_CRM_GetCart_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil { if err != nil {
@ -427,7 +497,57 @@ func RegisterCRMHandlerServer(ctx context.Context, mux *runtime.ServeMux, server
return return
} }
forward_CRM_GetCard_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) forward_CRM_GetCart_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("GET", pattern_CRM_GetImage_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error
var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/crabs.crm.CRM/GetImage", runtime.WithHTTPPathPattern("/images/{name}"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_CRM_GetImage_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_CRM_GetImage_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("GET", pattern_CRM_Search_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error
var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/crabs.crm.CRM/Search", runtime.WithHTTPPathPattern("/search"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_CRM_Search_0(annotatedContext, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_CRM_Search_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
}) })
@ -544,7 +664,7 @@ func RegisterCRMHandlerClient(ctx context.Context, mux *runtime.ServeMux, client
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error var err error
var annotatedContext context.Context var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/crabs.crm.CRM/GetBreadcrumbs", runtime.WithHTTPPathPattern("/breadcrumbs/{id}")) annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/crabs.crm.CRM/GetBreadcrumbs", runtime.WithHTTPPathPattern("/products/{id}/breadcrumbs"))
if err != nil { if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return return
@ -582,25 +702,69 @@ func RegisterCRMHandlerClient(ctx context.Context, mux *runtime.ServeMux, client
}) })
mux.Handle("POST", pattern_CRM_GetCard_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { mux.Handle("POST", pattern_CRM_GetCart_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context()) ctx, cancel := context.WithCancel(req.Context())
defer cancel() defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error var err error
var annotatedContext context.Context var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/crabs.crm.CRM/GetCard", runtime.WithHTTPPathPattern("/card")) annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/crabs.crm.CRM/GetCart", runtime.WithHTTPPathPattern("/cart"))
if err != nil { if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return return
} }
resp, md, err := request_CRM_GetCard_0(annotatedContext, inboundMarshaler, client, req, pathParams) resp, md, err := request_CRM_GetCart_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil { if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return return
} }
forward_CRM_GetCard_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) forward_CRM_GetCart_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("GET", pattern_CRM_GetImage_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error
var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/crabs.crm.CRM/GetImage", runtime.WithHTTPPathPattern("/images/{name}"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_CRM_GetImage_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_CRM_GetImage_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("GET", pattern_CRM_Search_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error
var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/crabs.crm.CRM/Search", runtime.WithHTTPPathPattern("/search"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_CRM_Search_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_CRM_Search_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
}) })
@ -614,11 +778,15 @@ var (
pattern_CRM_GetProduct_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"products", "id"}, "")) pattern_CRM_GetProduct_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"products", "id"}, ""))
pattern_CRM_GetBreadcrumbs_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"breadcrumbs", "id"}, "")) pattern_CRM_GetBreadcrumbs_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1, 2, 2}, []string{"products", "id", "breadcrumbs"}, ""))
pattern_CRM_Order_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"orders"}, "")) pattern_CRM_Order_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"orders"}, ""))
pattern_CRM_GetCard_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"card"}, "")) pattern_CRM_GetCart_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"cart"}, ""))
pattern_CRM_GetImage_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 1, 0, 4, 1, 5, 1}, []string{"images", "name"}, ""))
pattern_CRM_Search_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0}, []string{"search"}, ""))
) )
var ( var (
@ -632,5 +800,9 @@ var (
forward_CRM_Order_0 = runtime.ForwardResponseMessage forward_CRM_Order_0 = runtime.ForwardResponseMessage
forward_CRM_GetCard_0 = runtime.ForwardResponseMessage forward_CRM_GetCart_0 = runtime.ForwardResponseMessage
forward_CRM_GetImage_0 = runtime.ForwardResponseMessage
forward_CRM_Search_0 = runtime.ForwardResponseMessage
) )

View File

@ -8,6 +8,7 @@ package proto
import ( import (
context "context" context "context"
httpbody "google.golang.org/genproto/googleapis/api/httpbody"
grpc "google.golang.org/grpc" grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes" codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status" status "google.golang.org/grpc/status"
@ -24,7 +25,9 @@ const (
CRM_GetProduct_FullMethodName = "/crabs.crm.CRM/GetProduct" CRM_GetProduct_FullMethodName = "/crabs.crm.CRM/GetProduct"
CRM_GetBreadcrumbs_FullMethodName = "/crabs.crm.CRM/GetBreadcrumbs" CRM_GetBreadcrumbs_FullMethodName = "/crabs.crm.CRM/GetBreadcrumbs"
CRM_Order_FullMethodName = "/crabs.crm.CRM/Order" CRM_Order_FullMethodName = "/crabs.crm.CRM/Order"
CRM_GetCard_FullMethodName = "/crabs.crm.CRM/GetCard" CRM_GetCart_FullMethodName = "/crabs.crm.CRM/GetCart"
CRM_GetImage_FullMethodName = "/crabs.crm.CRM/GetImage"
CRM_Search_FullMethodName = "/crabs.crm.CRM/Search"
) )
// CRMClient is the client API for CRM service. // CRMClient is the client API for CRM service.
@ -36,7 +39,9 @@ type CRMClient interface {
GetProduct(ctx context.Context, in *GetProductReq, opts ...grpc.CallOption) (*ProductRsp, error) GetProduct(ctx context.Context, in *GetProductReq, opts ...grpc.CallOption) (*ProductRsp, error)
GetBreadcrumbs(ctx context.Context, in *GetBreadcrumbsReq, opts ...grpc.CallOption) (*BreadcrumbsRsp, error) GetBreadcrumbs(ctx context.Context, in *GetBreadcrumbsReq, opts ...grpc.CallOption) (*BreadcrumbsRsp, error)
Order(ctx context.Context, in *OrderReq, opts ...grpc.CallOption) (*OrderRsp, error) Order(ctx context.Context, in *OrderReq, opts ...grpc.CallOption) (*OrderRsp, error)
GetCard(ctx context.Context, in *CardReq, opts ...grpc.CallOption) (*CardRsp, error) GetCart(ctx context.Context, in *CartReq, opts ...grpc.CallOption) (*CartRsp, error)
GetImage(ctx context.Context, in *GetImageReq, opts ...grpc.CallOption) (*httpbody.HttpBody, error)
Search(ctx context.Context, in *SearchReq, opts ...grpc.CallOption) (*PositionsRsp, error)
} }
type cRMClient struct { type cRMClient struct {
@ -92,9 +97,27 @@ func (c *cRMClient) Order(ctx context.Context, in *OrderReq, opts ...grpc.CallOp
return out, nil return out, nil
} }
func (c *cRMClient) GetCard(ctx context.Context, in *CardReq, opts ...grpc.CallOption) (*CardRsp, error) { func (c *cRMClient) GetCart(ctx context.Context, in *CartReq, opts ...grpc.CallOption) (*CartRsp, error) {
out := new(CardRsp) out := new(CartRsp)
err := c.cc.Invoke(ctx, CRM_GetCard_FullMethodName, in, out, opts...) err := c.cc.Invoke(ctx, CRM_GetCart_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *cRMClient) GetImage(ctx context.Context, in *GetImageReq, opts ...grpc.CallOption) (*httpbody.HttpBody, error) {
out := new(httpbody.HttpBody)
err := c.cc.Invoke(ctx, CRM_GetImage_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *cRMClient) Search(ctx context.Context, in *SearchReq, opts ...grpc.CallOption) (*PositionsRsp, error) {
out := new(PositionsRsp)
err := c.cc.Invoke(ctx, CRM_Search_FullMethodName, in, out, opts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -110,7 +133,9 @@ type CRMServer interface {
GetProduct(context.Context, *GetProductReq) (*ProductRsp, error) GetProduct(context.Context, *GetProductReq) (*ProductRsp, error)
GetBreadcrumbs(context.Context, *GetBreadcrumbsReq) (*BreadcrumbsRsp, error) GetBreadcrumbs(context.Context, *GetBreadcrumbsReq) (*BreadcrumbsRsp, error)
Order(context.Context, *OrderReq) (*OrderRsp, error) Order(context.Context, *OrderReq) (*OrderRsp, error)
GetCard(context.Context, *CardReq) (*CardRsp, error) GetCart(context.Context, *CartReq) (*CartRsp, error)
GetImage(context.Context, *GetImageReq) (*httpbody.HttpBody, error)
Search(context.Context, *SearchReq) (*PositionsRsp, error)
mustEmbedUnimplementedCRMServer() mustEmbedUnimplementedCRMServer()
} }
@ -133,8 +158,14 @@ func (UnimplementedCRMServer) GetBreadcrumbs(context.Context, *GetBreadcrumbsReq
func (UnimplementedCRMServer) Order(context.Context, *OrderReq) (*OrderRsp, error) { func (UnimplementedCRMServer) Order(context.Context, *OrderReq) (*OrderRsp, error) {
return nil, status.Errorf(codes.Unimplemented, "method Order not implemented") return nil, status.Errorf(codes.Unimplemented, "method Order not implemented")
} }
func (UnimplementedCRMServer) GetCard(context.Context, *CardReq) (*CardRsp, error) { func (UnimplementedCRMServer) GetCart(context.Context, *CartReq) (*CartRsp, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetCard not implemented") return nil, status.Errorf(codes.Unimplemented, "method GetCart not implemented")
}
func (UnimplementedCRMServer) GetImage(context.Context, *GetImageReq) (*httpbody.HttpBody, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetImage not implemented")
}
func (UnimplementedCRMServer) Search(context.Context, *SearchReq) (*PositionsRsp, error) {
return nil, status.Errorf(codes.Unimplemented, "method Search not implemented")
} }
func (UnimplementedCRMServer) mustEmbedUnimplementedCRMServer() {} func (UnimplementedCRMServer) mustEmbedUnimplementedCRMServer() {}
@ -239,20 +270,56 @@ func _CRM_Order_Handler(srv interface{}, ctx context.Context, dec func(interface
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
func _CRM_GetCard_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { func _CRM_GetCart_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(CardReq) in := new(CartReq)
if err := dec(in); err != nil { if err := dec(in); err != nil {
return nil, err return nil, err
} }
if interceptor == nil { if interceptor == nil {
return srv.(CRMServer).GetCard(ctx, in) return srv.(CRMServer).GetCart(ctx, in)
} }
info := &grpc.UnaryServerInfo{ info := &grpc.UnaryServerInfo{
Server: srv, Server: srv,
FullMethod: CRM_GetCard_FullMethodName, FullMethod: CRM_GetCart_FullMethodName,
} }
handler := func(ctx context.Context, req interface{}) (interface{}, error) { handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CRMServer).GetCard(ctx, req.(*CardReq)) return srv.(CRMServer).GetCart(ctx, req.(*CartReq))
}
return interceptor(ctx, in, info, handler)
}
func _CRM_GetImage_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetImageReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CRMServer).GetImage(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CRM_GetImage_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CRMServer).GetImage(ctx, req.(*GetImageReq))
}
return interceptor(ctx, in, info, handler)
}
func _CRM_Search_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(SearchReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CRMServer).Search(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: CRM_Search_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CRMServer).Search(ctx, req.(*SearchReq))
} }
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
@ -285,8 +352,16 @@ var CRM_ServiceDesc = grpc.ServiceDesc{
Handler: _CRM_Order_Handler, Handler: _CRM_Order_Handler,
}, },
{ {
MethodName: "GetCard", MethodName: "GetCart",
Handler: _CRM_GetCard_Handler, Handler: _CRM_GetCart_Handler,
},
{
MethodName: "GetImage",
Handler: _CRM_GetImage_Handler,
},
{
MethodName: "Search",
Handler: _CRM_Search_Handler,
}, },
}, },
Streams: []grpc.StreamDesc{}, Streams: []grpc.StreamDesc{},

View File

@ -2,18 +2,30 @@
{ {
"id": 0, "id": 0,
"name": "Главная", "name": "Главная",
"uri": "/categories/0", "uri": "/positions/0",
"children": [ "children": [
{ {
"id": 1, "id": 1,
"name": "Пряники", "name": "Пряники",
"uri": "/categories/1", "uri": "/positions/1",
"children": [] "children": []
}, },
{ {
"id": 2, "id": 2,
"name": "Пахлава", "name": "Печенье бисквитное",
"uri": "/categories/2", "uri": "/positions/2",
"children": []
},
{
"id": 3,
"name": "Печенье песочное",
"uri": "/positions/3",
"children": []
},
{
"id": 4,
"name": "Восточные сладости",
"uri": "/positions/4",
"children": [] "children": []
} }
] ]

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 KiB

View File

@ -16,45 +16,14 @@
"application/json" "application/json"
], ],
"paths": { "paths": {
"/breadcrumbs/{id}": { "/cart": {
"get": {
"operationId": "CRM_GetBreadcrumbs",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/crmBreadcrumbsRsp"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string",
"format": "int64"
}
],
"tags": [
"CRM"
]
}
},
"/card": {
"post": { "post": {
"operationId": "CRM_GetCard", "operationId": "CRM_GetCart",
"responses": { "responses": {
"200": { "200": {
"description": "A successful response.", "description": "A successful response.",
"schema": { "schema": {
"$ref": "#/definitions/crmCardRsp" "$ref": "#/definitions/crmCartRsp"
} }
}, },
"default": { "default": {
@ -105,6 +74,36 @@
] ]
} }
}, },
"/images/{name}": {
"get": {
"operationId": "CRM_GetImage",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/apiHttpBody"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "name",
"in": "path",
"required": true,
"type": "string"
}
],
"tags": [
"CRM"
]
}
},
"/orders": { "/orders": {
"post": { "post": {
"operationId": "CRM_Order", "operationId": "CRM_Order",
@ -130,18 +129,6 @@
"schema": { "schema": {
"$ref": "#/definitions/crabscrmOrder" "$ref": "#/definitions/crabscrmOrder"
} }
},
{
"name": "name",
"in": "query",
"required": false,
"type": "string"
},
{
"name": "phone",
"in": "query",
"required": false,
"type": "string"
} }
], ],
"tags": [ "tags": [
@ -210,12 +197,110 @@
"CRM" "CRM"
] ]
} }
},
"/products/{id}/breadcrumbs": {
"get": {
"operationId": "CRM_GetBreadcrumbs",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/crmBreadcrumbsRsp"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string",
"format": "int64"
}
],
"tags": [
"CRM"
]
}
},
"/search": {
"get": {
"operationId": "CRM_Search",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/crmPositionsRsp"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"parameters": [
{
"name": "text",
"in": "query",
"required": false,
"type": "string"
}
],
"tags": [
"CRM"
]
}
} }
}, },
"definitions": { "definitions": {
"apiHttpBody": {
"type": "object",
"properties": {
"contentType": {
"type": "string",
"description": "The HTTP Content-Type header value specifying the content type of the body."
},
"data": {
"type": "string",
"format": "byte",
"description": "The HTTP request/response body as raw binary."
},
"extensions": {
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/protobufAny"
},
"description": "Application specific response metadata. Must be set in the first response\nfor streaming APIs."
}
},
"description": "Message that represents an arbitrary HTTP body. It should only be used for\npayload formats that can't be represented as JSON, such as raw binary or\nan HTML page.\n\n\nThis message can be used both in streaming and non-streaming API methods in\nthe request as well as the response.\n\nIt can be used as a top-level request field, which is convenient if one\nwants to extract parameters from either the URL or HTTP template into the\nrequest fields and also want access to the raw HTTP body.\n\nExample:\n\n message GetResourceRequest {\n // A unique request id.\n string request_id = 1;\n\n // The raw HTTP body is bound to this field.\n google.api.HttpBody http_body = 2;\n\n }\n\n service ResourceService {\n rpc GetResource(GetResourceRequest)\n returns (google.api.HttpBody);\n rpc UpdateResource(google.api.HttpBody)\n returns (google.protobuf.Empty);\n\n }\n\nExample with streaming methods:\n\n service CaldavService {\n rpc GetCalendar(stream google.api.HttpBody)\n returns (stream google.api.HttpBody);\n rpc UpdateCalendar(stream google.api.HttpBody)\n returns (stream google.api.HttpBody);\n\n }\n\nUse of this type only changes how the request and response bodies are\nhandled, all other features will continue to work unchanged."
},
"crabscrmLabel": {
"type": "object",
"properties": {
"name": {
"type": "string"
}
}
},
"crabscrmOrder": { "crabscrmOrder": {
"type": "object", "type": "object",
"properties": { "properties": {
"name": {
"type": "string"
},
"phone": {
"type": "string"
},
"items": { "items": {
"type": "array", "type": "array",
"items": { "items": {
@ -237,7 +322,7 @@
} }
} }
}, },
"crmCardItem": { "crmCartItem": {
"type": "object", "type": "object",
"properties": { "properties": {
"id": { "id": {
@ -273,18 +358,52 @@
"amount": { "amount": {
"type": "string", "type": "string",
"format": "int64" "format": "int64"
},
"amountOld": {
"type": "string",
"format": "int64"
},
"discount": {
"type": "string",
"format": "int64"
},
"variants": {
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/crmVariant"
}
},
"labels": {
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/crabscrmLabel"
}
} }
} }
}, },
"crmCardRsp": { "crmCartRsp": {
"type": "object", "type": "object",
"properties": { "properties": {
"items": { "items": {
"type": "array", "type": "array",
"items": { "items": {
"type": "object", "type": "object",
"$ref": "#/definitions/crmCardItem" "$ref": "#/definitions/crmCartItem"
} }
},
"amount": {
"type": "string",
"format": "int64"
},
"amountOld": {
"type": "string",
"format": "int64"
},
"discount": {
"type": "string",
"format": "int64"
} }
} }
}, },
@ -431,6 +550,13 @@
"category": { "category": {
"type": "string", "type": "string",
"format": "int64" "format": "int64"
},
"labels": {
"type": "array",
"items": {
"type": "object",
"$ref": "#/definitions/crabscrmLabel"
}
} }
} }
}, },
@ -466,6 +592,9 @@
"type": "object", "type": "object",
"$ref": "#/definitions/crmProperty" "$ref": "#/definitions/crmProperty"
} }
},
"active": {
"type": "boolean"
} }
} }
}, },
@ -473,10 +602,12 @@
"type": "object", "type": "object",
"properties": { "properties": {
"@type": { "@type": {
"type": "string" "type": "string",
"description": "A URL/resource name that uniquely identifies the type of the serialized\nprotocol buffer message. This string must contain at least\none \"/\" character. The last segment of the URL's path must represent\nthe fully qualified name of the type (as in\n`path/google.protobuf.Duration`). The name should be in a canonical form\n(e.g., leading \".\" is not accepted).\n\nIn practice, teams usually precompile into the binary all types that they\nexpect it to use in the context of Any. However, for URLs which use the\nscheme `http`, `https`, or no scheme, one can optionally set up a type\nserver that maps type URLs to message definitions as follows:\n\n* If no scheme is provided, `https` is assumed.\n* An HTTP GET on the URL must yield a [google.protobuf.Type][]\n value in binary format, or produce an error.\n* Applications are allowed to cache lookup results based on the\n URL, or have them precompiled into a binary to avoid any\n lookup. Therefore, binary compatibility needs to be preserved\n on changes to types. (Use versioned type names to manage\n breaking changes.)\n\nNote: this functionality is not currently available in the official\nprotobuf release, and it is not used for type URLs beginning with\ntype.googleapis.com. As of May 2023, there are no widely used type server\nimplementations and no plans to implement one.\n\nSchemes other than `http`, `https` (or the empty scheme) might be\nused with implementation specific semantics."
} }
}, },
"additionalProperties": {} "additionalProperties": {},
"description": "`Any` contains an arbitrary serialized protocol buffer message along with a\nURL that describes the type of the serialized message.\n\nProtobuf library provides support to pack/unpack Any values in the form\nof utility functions or additional generated methods of the Any type.\n\nExample 1: Pack and unpack a message in C++.\n\n Foo foo = ...;\n Any any;\n any.PackFrom(foo);\n ...\n if (any.UnpackTo(\u0026foo)) {\n ...\n }\n\nExample 2: Pack and unpack a message in Java.\n\n Foo foo = ...;\n Any any = Any.pack(foo);\n ...\n if (any.is(Foo.class)) {\n foo = any.unpack(Foo.class);\n }\n // or ...\n if (any.isSameTypeAs(Foo.getDefaultInstance())) {\n foo = any.unpack(Foo.getDefaultInstance());\n }\n\n Example 3: Pack and unpack a message in Python.\n\n foo = Foo(...)\n any = Any()\n any.Pack(foo)\n ...\n if any.Is(Foo.DESCRIPTOR):\n any.Unpack(foo)\n ...\n\n Example 4: Pack and unpack a message in Go\n\n foo := \u0026pb.Foo{...}\n any, err := anypb.New(foo)\n if err != nil {\n ...\n }\n ...\n foo := \u0026pb.Foo{}\n if err := any.UnmarshalTo(foo); err != nil {\n ...\n }\n\nThe pack methods provided by protobuf library will by default use\n'type.googleapis.com/full.type.name' as the type URL and the unpack\nmethods only use the fully qualified type name after the last '/'\nin the type URL, for example \"foo.bar.com/x/y.z\" will yield type\nname \"y.z\".\n\nJSON\n====\nThe JSON representation of an `Any` value uses the regular\nrepresentation of the deserialized, embedded message, with an\nadditional field `@type` which contains the type URL. Example:\n\n package google.profile;\n message Person {\n string first_name = 1;\n string last_name = 2;\n }\n\n {\n \"@type\": \"type.googleapis.com/google.profile.Person\",\n \"firstName\": \u003cstring\u003e,\n \"lastName\": \u003cstring\u003e\n }\n\nIf the embedded message type is well-known and has a custom JSON\nrepresentation, that representation will be embedded adding a field\n`value` which holds the custom JSON in addition to the `@type`\nfield. Example (for message [google.protobuf.Duration][]):\n\n {\n \"@type\": \"type.googleapis.com/google.protobuf.Duration\",\n \"value\": \"1.212s\"\n }"
}, },
"rpcStatus": { "rpcStatus": {
"type": "object", "type": "object",

File diff suppressed because it is too large Load Diff

81
third_party/google/api/httpbody.proto vendored Normal file
View File

@ -0,0 +1,81 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
syntax = "proto3";
package google.api;
import "google/protobuf/any.proto";
option cc_enable_arenas = true;
option go_package = "google.golang.org/genproto/googleapis/api/httpbody;httpbody";
option java_multiple_files = true;
option java_outer_classname = "HttpBodyProto";
option java_package = "com.google.api";
option objc_class_prefix = "GAPI";
// Message that represents an arbitrary HTTP body. It should only be used for
// payload formats that can't be represented as JSON, such as raw binary or
// an HTML page.
//
//
// This message can be used both in streaming and non-streaming API methods in
// the request as well as the response.
//
// It can be used as a top-level request field, which is convenient if one
// wants to extract parameters from either the URL or HTTP template into the
// request fields and also want access to the raw HTTP body.
//
// Example:
//
// message GetResourceRequest {
// // A unique request id.
// string request_id = 1;
//
// // The raw HTTP body is bound to this field.
// google.api.HttpBody http_body = 2;
//
// }
//
// service ResourceService {
// rpc GetResource(GetResourceRequest)
// returns (google.api.HttpBody);
// rpc UpdateResource(google.api.HttpBody)
// returns (google.protobuf.Empty);
//
// }
//
// Example with streaming methods:
//
// service CaldavService {
// rpc GetCalendar(stream google.api.HttpBody)
// returns (stream google.api.HttpBody);
// rpc UpdateCalendar(stream google.api.HttpBody)
// returns (stream google.api.HttpBody);
//
// }
//
// Use of this type only changes how the request and response bodies are
// handled, all other features will continue to work unchanged.
message HttpBody {
// The HTTP Content-Type header value specifying the content type of the body.
string content_type = 1;
// The HTTP request/response body as raw binary.
bytes data = 2;
// Application specific response metadata. Must be set in the first response
// for streaming APIs.
repeated google.protobuf.Any extensions = 3;
}