From 0a92d3a6be24362fe5b3147a3eecf3aecd716d9e Mon Sep 17 00:00:00 2001 From: KranjQ Date: Mon, 16 Dec 2024 00:57:04 +0300 Subject: [PATCH] add and get product --- cmd/main/main.go | 14 +- docker/.env | 8 +- internal/models/user_easyjson.go | 135 ++++- .../payments/delivery/grpc/gen/payments.pb.go | 557 +++++++++++++++--- .../delivery/grpc/gen/payments_grpc.pb.go | 114 ++++ .../pkg/payments/delivery/grpc/handlers.go | 77 +++ .../delivery/http/addProduct/handler.go | 67 +++ .../delivery/http/buyproduct/handler.go | 147 ++--- .../http/buyproduct/handler_easyjson.go | 331 +---------- .../delivery/http/getProducts/handler.go | 80 +++ .../http/getProducts/handler_easyjson.go | 177 ++++++ .../delivery/http/topUpBalance/handler.go | 156 +++++ .../http/topUpBalance/handler_easyjson.go | 450 ++++++++++++++ internal/pkg/payments/repo/payments.go | 23 +- internal/pkg/payments/usecase/usecase.go | 25 + .../delivery/http/getuserlist/handler.go | 2 +- proto/payments.proto | 33 ++ 17 files changed, 1854 insertions(+), 542 deletions(-) create mode 100644 internal/pkg/payments/delivery/http/addProduct/handler.go create mode 100644 internal/pkg/payments/delivery/http/getProducts/handler.go create mode 100644 internal/pkg/payments/delivery/http/getProducts/handler_easyjson.go create mode 100644 internal/pkg/payments/delivery/http/topUpBalance/handler.go create mode 100644 internal/pkg/payments/delivery/http/topUpBalance/handler_easyjson.go diff --git a/cmd/main/main.go b/cmd/main/main.go index 1675d53..5d39985 100644 --- a/cmd/main/main.go +++ b/cmd/main/main.go @@ -30,8 +30,11 @@ import ( metricsmiddleware "github.com/go-park-mail-ru/2024_2_SaraFun/internal/pkg/middleware/httpMetricsMiddleware" grpcpayments "github.com/go-park-mail-ru/2024_2_SaraFun/internal/pkg/payments/delivery/grpc/gen" "github.com/go-park-mail-ru/2024_2_SaraFun/internal/pkg/payments/delivery/http/acceptpayment" + addproduct "github.com/go-park-mail-ru/2024_2_SaraFun/internal/pkg/payments/delivery/http/addProduct" "github.com/go-park-mail-ru/2024_2_SaraFun/internal/pkg/payments/delivery/http/buyproduct" + getproducts "github.com/go-park-mail-ru/2024_2_SaraFun/internal/pkg/payments/delivery/http/getProducts" "github.com/go-park-mail-ru/2024_2_SaraFun/internal/pkg/payments/delivery/http/getbalance" + "github.com/go-park-mail-ru/2024_2_SaraFun/internal/pkg/payments/delivery/http/topUpBalance" grpcpersonalities "github.com/go-park-mail-ru/2024_2_SaraFun/internal/pkg/personalities/delivery/grpc/gen" "github.com/go-park-mail-ru/2024_2_SaraFun/internal/pkg/personalities/delivery/http/getcurrentprofile" "github.com/go-park-mail-ru/2024_2_SaraFun/internal/pkg/personalities/delivery/http/getprofile" @@ -213,8 +216,11 @@ func main() { updateQuestion := updatequestion.NewHandler(authClient, surveyClient, logger) getQuestions := getquestions.NewHandler(authClient, surveyClient, logger) getBalance := getbalance.NewHandler(authClient, paymentsClient, logger) - buyProduct := buyproduct.NewHandler(authClient, logger) + topupBalance := topUpBalance.NewHandler(authClient, logger) + buyProduct := buyproduct.NewHandler(authClient, paymentsClient, logger) acceptPayment := acceptpayment.NewHandler(authClient, paymentsClient, logger) + addProduct := addproduct.NewHandler(authClient, paymentsClient, logger) + getProducts := getproducts.NewHandler(authClient, paymentsClient, logger) authMiddleware := authcheck.New(authClient, logger) accessLogMiddleware := middleware.NewAccessLogMiddleware(sugar) metricsMiddleware := metricsmiddleware.NewMiddleware(_metrics, logger) @@ -287,8 +293,12 @@ func main() { payments := router.PathPrefix("/payments").Subrouter() { payments.Handle("/balance", http.HandlerFunc(getBalance.Handle)).Methods("GET", http.MethodOptions) - payments.Handle("/buy", http.HandlerFunc(buyProduct.Handle)).Methods("POST", http.MethodOptions) + payments.Handle("/topup", http.HandlerFunc(topupBalance.Handle)).Methods("POST", http.MethodOptions) payments.Handle("/check", http.HandlerFunc(acceptPayment.Handle)).Methods("POST", http.MethodOptions) + payments.Handle("/buy", http.HandlerFunc(buyProduct.Handle)).Methods("POST", http.MethodOptions) + payments.Handle("/product", http.HandlerFunc(addProduct.Handle)).Methods("POST", http.MethodOptions) + payments.Handle("/products", http.HandlerFunc(getProducts.Handle)).Methods("GET", http.MethodOptions) + } // Создаем HTTP-сервер diff --git a/docker/.env b/docker/.env index 6f1ff23..f9c4b47 100644 --- a/docker/.env +++ b/docker/.env @@ -10,10 +10,10 @@ DB_USER=app_user DB_PASSWORD=test DB_NAME=sparkitDB DB_SSLMODE=disable -SERVER_CERT_PATH=/etc/letsencrypt/live/spark-it.site/fullchain.pem -SERVER_KEY_PATH=/etc/letsencrypt/live/spark-it.site/privkey.pem +# SERVER_CERT_PATH=/etc/letsencrypt/live/spark-it.site/fullchain.pem +# SERVER_KEY_PATH=/etc/letsencrypt/live/spark-it.site/privkey.pem SHOP_ID=999343 SECRET_SHOP_KEY=test_tg4qykklfcjLeOx-oMnv0jBUTKu6Cr7-FVqkG1-O1IY -# SERVER_CERT_PATH=../server.crt -# SERVER_KEY_PATH=../server.key +SERVER_CERT_PATH=../server.crt +SERVER_KEY_PATH=../server.key diff --git a/internal/models/user_easyjson.go b/internal/models/user_easyjson.go index f18e8ac..c9af54f 100644 --- a/internal/models/user_easyjson.go +++ b/internal/models/user_easyjson.go @@ -693,7 +693,94 @@ func (v *Profile) UnmarshalJSON(data []byte) error { func (v *Profile) UnmarshalEasyJSON(l *jlexer.Lexer) { easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels6(l, v) } -func easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels7(in *jlexer.Lexer, out *PersonCard) { +func easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels7(in *jlexer.Lexer, out *Product) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "title": + out.Title = string(in.String()) + case "description": + out.Description = string(in.String()) + case "image_link": + out.ImageLink = string(in.String()) + case "price": + out.Price = int(in.Int()) + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels7(out *jwriter.Writer, in Product) { + out.RawByte('{') + first := true + _ = first + { + const prefix string = ",\"title\":" + out.RawString(prefix[1:]) + out.String(string(in.Title)) + } + { + const prefix string = ",\"description\":" + out.RawString(prefix) + out.String(string(in.Description)) + } + { + const prefix string = ",\"image_link\":" + out.RawString(prefix) + out.String(string(in.ImageLink)) + } + { + const prefix string = ",\"price\":" + out.RawString(prefix) + out.Int(int(in.Price)) + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v Product) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels7(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v Product) MarshalEasyJSON(w *jwriter.Writer) { + easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels7(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *Product) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels7(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *Product) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels7(l, v) +} +func easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels8(in *jlexer.Lexer, out *PersonCard) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -751,7 +838,7 @@ func easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels7(in * in.Consumed() } } -func easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels7(out *jwriter.Writer, in PersonCard) { +func easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels8(out *jwriter.Writer, in PersonCard) { out.RawByte('{') first := true _ = first @@ -792,27 +879,27 @@ func easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels7(out // MarshalJSON supports json.Marshaler interface func (v PersonCard) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels7(&w, v) + easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels8(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v PersonCard) MarshalEasyJSON(w *jwriter.Writer) { - easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels7(w, v) + easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels8(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *PersonCard) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels7(&r, v) + easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels8(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *PersonCard) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels7(l, v) + easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels8(l, v) } -func easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels8(in *jlexer.Lexer, out *Message) { +func easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels9(in *jlexer.Lexer, out *Message) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -851,7 +938,7 @@ func easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels8(in * in.Consumed() } } -func easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels8(out *jwriter.Writer, in Message) { +func easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels9(out *jwriter.Writer, in Message) { out.RawByte('{') first := true _ = first @@ -886,27 +973,27 @@ func easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels8(out // MarshalJSON supports json.Marshaler interface func (v Message) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels8(&w, v) + easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels9(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v Message) MarshalEasyJSON(w *jwriter.Writer) { - easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels8(w, v) + easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels9(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *Message) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels8(&r, v) + easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels9(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *Message) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels8(l, v) + easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels9(l, v) } -func easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels9(in *jlexer.Lexer, out *Image) { +func easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels10(in *jlexer.Lexer, out *Image) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -941,7 +1028,7 @@ func easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels9(in * in.Consumed() } } -func easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels9(out *jwriter.Writer, in Image) { +func easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels10(out *jwriter.Writer, in Image) { out.RawByte('{') first := true _ = first @@ -966,27 +1053,27 @@ func easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels9(out // MarshalJSON supports json.Marshaler interface func (v Image) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels9(&w, v) + easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels10(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v Image) MarshalEasyJSON(w *jwriter.Writer) { - easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels9(w, v) + easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels10(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *Image) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels9(&r, v) + easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels10(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *Image) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels9(l, v) + easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels10(l, v) } -func easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels10(in *jlexer.Lexer, out *AdminQuestion) { +func easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels11(in *jlexer.Lexer, out *AdminQuestion) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -1019,7 +1106,7 @@ func easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels10(in in.Consumed() } } -func easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels10(out *jwriter.Writer, in AdminQuestion) { +func easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels11(out *jwriter.Writer, in AdminQuestion) { out.RawByte('{') first := true _ = first @@ -1039,23 +1126,23 @@ func easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels10(out // MarshalJSON supports json.Marshaler interface func (v AdminQuestion) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels10(&w, v) + easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels11(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v AdminQuestion) MarshalEasyJSON(w *jwriter.Writer) { - easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels10(w, v) + easyjson9e1087fdEncodeGithubComGoParkMailRu20242SaraFunInternalModels11(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *AdminQuestion) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels10(&r, v) + easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels11(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *AdminQuestion) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels10(l, v) + easyjson9e1087fdDecodeGithubComGoParkMailRu20242SaraFunInternalModels11(l, v) } diff --git a/internal/pkg/payments/delivery/grpc/gen/payments.pb.go b/internal/pkg/payments/delivery/grpc/gen/payments.pb.go index 67db76c..39ff9ef 100644 --- a/internal/pkg/payments/delivery/grpc/gen/payments.pb.go +++ b/internal/pkg/payments/delivery/grpc/gen/payments.pb.go @@ -816,6 +816,343 @@ func (*CreateBalancesResponse) Descriptor() ([]byte, []int) { return file_payments_proto_rawDescGZIP(), []int{17} } +type BuyLikesRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Title string `protobuf:"bytes,1,opt,name=Title,proto3" json:"Title,omitempty"` + Amount int32 `protobuf:"varint,2,opt,name=Amount,proto3" json:"Amount,omitempty"` + UserID int32 `protobuf:"varint,3,opt,name=UserID,proto3" json:"UserID,omitempty"` +} + +func (x *BuyLikesRequest) Reset() { + *x = BuyLikesRequest{} + mi := &file_payments_proto_msgTypes[18] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *BuyLikesRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BuyLikesRequest) ProtoMessage() {} + +func (x *BuyLikesRequest) ProtoReflect() protoreflect.Message { + mi := &file_payments_proto_msgTypes[18] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BuyLikesRequest.ProtoReflect.Descriptor instead. +func (*BuyLikesRequest) Descriptor() ([]byte, []int) { + return file_payments_proto_rawDescGZIP(), []int{18} +} + +func (x *BuyLikesRequest) GetTitle() string { + if x != nil { + return x.Title + } + return "" +} + +func (x *BuyLikesRequest) GetAmount() int32 { + if x != nil { + return x.Amount + } + return 0 +} + +func (x *BuyLikesRequest) GetUserID() int32 { + if x != nil { + return x.UserID + } + return 0 +} + +type BuyLikesResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *BuyLikesResponse) Reset() { + *x = BuyLikesResponse{} + mi := &file_payments_proto_msgTypes[19] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *BuyLikesResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BuyLikesResponse) ProtoMessage() {} + +func (x *BuyLikesResponse) ProtoReflect() protoreflect.Message { + mi := &file_payments_proto_msgTypes[19] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BuyLikesResponse.ProtoReflect.Descriptor instead. +func (*BuyLikesResponse) Descriptor() ([]byte, []int) { + return file_payments_proto_rawDescGZIP(), []int{19} +} + +type Product struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Title string `protobuf:"bytes,1,opt,name=Title,proto3" json:"Title,omitempty"` + Description string `protobuf:"bytes,2,opt,name=Description,proto3" json:"Description,omitempty"` + ImageLink string `protobuf:"bytes,3,opt,name=ImageLink,proto3" json:"ImageLink,omitempty"` + Price int32 `protobuf:"varint,4,opt,name=Price,proto3" json:"Price,omitempty"` +} + +func (x *Product) Reset() { + *x = Product{} + mi := &file_payments_proto_msgTypes[20] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *Product) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Product) ProtoMessage() {} + +func (x *Product) ProtoReflect() protoreflect.Message { + mi := &file_payments_proto_msgTypes[20] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Product.ProtoReflect.Descriptor instead. +func (*Product) Descriptor() ([]byte, []int) { + return file_payments_proto_rawDescGZIP(), []int{20} +} + +func (x *Product) GetTitle() string { + if x != nil { + return x.Title + } + return "" +} + +func (x *Product) GetDescription() string { + if x != nil { + return x.Description + } + return "" +} + +func (x *Product) GetImageLink() string { + if x != nil { + return x.ImageLink + } + return "" +} + +func (x *Product) GetPrice() int32 { + if x != nil { + return x.Price + } + return 0 +} + +type CreateProductRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Product *Product `protobuf:"bytes,1,opt,name=Product,proto3" json:"Product,omitempty"` +} + +func (x *CreateProductRequest) Reset() { + *x = CreateProductRequest{} + mi := &file_payments_proto_msgTypes[21] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *CreateProductRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateProductRequest) ProtoMessage() {} + +func (x *CreateProductRequest) ProtoReflect() protoreflect.Message { + mi := &file_payments_proto_msgTypes[21] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CreateProductRequest.ProtoReflect.Descriptor instead. +func (*CreateProductRequest) Descriptor() ([]byte, []int) { + return file_payments_proto_rawDescGZIP(), []int{21} +} + +func (x *CreateProductRequest) GetProduct() *Product { + if x != nil { + return x.Product + } + return nil +} + +type CreateProductResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ID int32 `protobuf:"varint,1,opt,name=ID,proto3" json:"ID,omitempty"` +} + +func (x *CreateProductResponse) Reset() { + *x = CreateProductResponse{} + mi := &file_payments_proto_msgTypes[22] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *CreateProductResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateProductResponse) ProtoMessage() {} + +func (x *CreateProductResponse) ProtoReflect() protoreflect.Message { + mi := &file_payments_proto_msgTypes[22] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CreateProductResponse.ProtoReflect.Descriptor instead. +func (*CreateProductResponse) Descriptor() ([]byte, []int) { + return file_payments_proto_rawDescGZIP(), []int{22} +} + +func (x *CreateProductResponse) GetID() int32 { + if x != nil { + return x.ID + } + return 0 +} + +type GetProductsRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *GetProductsRequest) Reset() { + *x = GetProductsRequest{} + mi := &file_payments_proto_msgTypes[23] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetProductsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetProductsRequest) ProtoMessage() {} + +func (x *GetProductsRequest) ProtoReflect() protoreflect.Message { + mi := &file_payments_proto_msgTypes[23] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetProductsRequest.ProtoReflect.Descriptor instead. +func (*GetProductsRequest) Descriptor() ([]byte, []int) { + return file_payments_proto_rawDescGZIP(), []int{23} +} + +type GetProductsResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Products []*Product `protobuf:"bytes,1,rep,name=Products,proto3" json:"Products,omitempty"` +} + +func (x *GetProductsResponse) Reset() { + *x = GetProductsResponse{} + mi := &file_payments_proto_msgTypes[24] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetProductsResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetProductsResponse) ProtoMessage() {} + +func (x *GetProductsResponse) ProtoReflect() protoreflect.Message { + mi := &file_payments_proto_msgTypes[24] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetProductsResponse.ProtoReflect.Descriptor instead. +func (*GetProductsResponse) Descriptor() ([]byte, []int) { + return file_payments_proto_rawDescGZIP(), []int{24} +} + +func (x *GetProductsResponse) GetProducts() []*Product { + if x != nil { + return x.Products + } + return nil +} + var File_payments_proto protoreflect.FileDescriptor var file_payments_proto_rawDesc = []byte{ @@ -883,65 +1220,106 @@ var file_payments_proto_rawDesc = []byte{ 0x12, 0x16, 0x0a, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x41, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x18, 0x0a, 0x16, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x32, 0xe9, 0x06, 0x0a, 0x07, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x62, - 0x0a, 0x13, 0x47, 0x65, 0x74, 0x44, 0x61, 0x69, 0x6c, 0x79, 0x4c, 0x69, 0x6b, 0x65, 0x42, 0x61, - 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x24, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, - 0x2e, 0x47, 0x65, 0x74, 0x44, 0x61, 0x69, 0x6c, 0x79, 0x4c, 0x69, 0x6b, 0x65, 0x42, 0x61, 0x6c, - 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x70, 0x61, - 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x61, 0x69, 0x6c, 0x79, 0x4c, - 0x69, 0x6b, 0x65, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x6e, 0x0a, 0x17, 0x47, 0x65, 0x74, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, - 0x65, 0x64, 0x4c, 0x69, 0x6b, 0x65, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x28, 0x2e, - 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x75, 0x72, 0x63, - 0x68, 0x61, 0x73, 0x65, 0x64, 0x4c, 0x69, 0x6b, 0x65, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, - 0x74, 0x73, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x64, 0x4c, - 0x69, 0x6b, 0x65, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x47, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, - 0x12, 0x1b, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x47, 0x65, 0x74, 0x42, - 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, - 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x61, 0x6c, 0x61, - 0x6e, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6e, 0x0a, 0x17, 0x52, - 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x44, 0x61, 0x69, 0x6c, 0x79, 0x4c, 0x69, 0x6b, 0x65, 0x42, - 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x28, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, - 0x73, 0x2e, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x44, 0x61, 0x69, 0x6c, 0x79, 0x4c, 0x69, - 0x6b, 0x65, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x29, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x52, 0x65, 0x66, 0x72, - 0x65, 0x73, 0x68, 0x44, 0x61, 0x69, 0x6c, 0x79, 0x4c, 0x69, 0x6b, 0x65, 0x42, 0x61, 0x6c, 0x61, - 0x6e, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x50, 0x0a, 0x0d, 0x43, - 0x68, 0x61, 0x6e, 0x67, 0x65, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x1e, 0x2e, 0x70, - 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x42, 0x61, - 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x70, - 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x42, 0x61, - 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5c, 0x0a, - 0x11, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x41, 0x6e, 0x64, 0x53, 0x70, 0x65, 0x6e, 0x64, 0x4c, 0x69, - 0x6b, 0x65, 0x12, 0x22, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x43, 0x68, - 0x65, 0x63, 0x6b, 0x41, 0x6e, 0x64, 0x53, 0x70, 0x65, 0x6e, 0x64, 0x4c, 0x69, 0x6b, 0x65, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, - 0x73, 0x2e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x41, 0x6e, 0x64, 0x53, 0x70, 0x65, 0x6e, 0x64, 0x4c, - 0x69, 0x6b, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x7a, 0x0a, 0x1b, 0x43, - 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x64, 0x4c, 0x69, - 0x6b, 0x65, 0x73, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x2c, 0x2e, 0x70, 0x61, 0x79, - 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x75, 0x72, 0x63, - 0x68, 0x61, 0x73, 0x65, 0x64, 0x4c, 0x69, 0x6b, 0x65, 0x73, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, - 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2d, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, + 0x73, 0x65, 0x22, 0x57, 0x0a, 0x0f, 0x42, 0x75, 0x79, 0x4c, 0x69, 0x6b, 0x65, 0x73, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x54, 0x69, 0x74, 0x6c, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x54, 0x69, 0x74, 0x6c, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x41, + 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x41, 0x6d, 0x6f, + 0x75, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x44, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x05, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x44, 0x22, 0x12, 0x0a, 0x10, 0x42, + 0x75, 0x79, 0x4c, 0x69, 0x6b, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x75, 0x0a, 0x07, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x54, 0x69, + 0x74, 0x6c, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x54, 0x69, 0x74, 0x6c, 0x65, + 0x12, 0x20, 0x0a, 0x0b, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, + 0x6f, 0x6e, 0x12, 0x1c, 0x0a, 0x09, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x4c, 0x69, 0x6e, 0x6b, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x4c, 0x69, 0x6e, 0x6b, + 0x12, 0x14, 0x0a, 0x05, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x05, 0x50, 0x72, 0x69, 0x63, 0x65, 0x22, 0x43, 0x0a, 0x14, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2b, + 0x0a, 0x07, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x11, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75, + 0x63, 0x74, 0x52, 0x07, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x22, 0x27, 0x0a, 0x15, 0x43, + 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x02, 0x49, 0x44, 0x22, 0x14, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x64, 0x75, + 0x63, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x44, 0x0a, 0x13, 0x47, 0x65, + 0x74, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x2d, 0x0a, 0x08, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x73, 0x18, 0x01, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x50, + 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x52, 0x08, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x73, + 0x32, 0xca, 0x08, 0x0a, 0x07, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x62, 0x0a, 0x13, + 0x47, 0x65, 0x74, 0x44, 0x61, 0x69, 0x6c, 0x79, 0x4c, 0x69, 0x6b, 0x65, 0x42, 0x61, 0x6c, 0x61, + 0x6e, 0x63, 0x65, 0x12, 0x24, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x47, + 0x65, 0x74, 0x44, 0x61, 0x69, 0x6c, 0x79, 0x4c, 0x69, 0x6b, 0x65, 0x42, 0x61, 0x6c, 0x61, 0x6e, + 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x70, 0x61, 0x79, 0x6d, + 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x47, 0x65, 0x74, 0x44, 0x61, 0x69, 0x6c, 0x79, 0x4c, 0x69, 0x6b, + 0x65, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x6e, 0x0a, 0x17, 0x47, 0x65, 0x74, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x64, + 0x4c, 0x69, 0x6b, 0x65, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x28, 0x2e, 0x70, 0x61, + 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, + 0x73, 0x65, 0x64, 0x4c, 0x69, 0x6b, 0x65, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, + 0x2e, 0x47, 0x65, 0x74, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x64, 0x4c, 0x69, 0x6b, + 0x65, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x47, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x1b, + 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x61, 0x6c, + 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1c, 0x2e, 0x70, 0x61, + 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x47, 0x65, 0x74, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, + 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6e, 0x0a, 0x17, 0x52, 0x65, 0x66, + 0x72, 0x65, 0x73, 0x68, 0x44, 0x61, 0x69, 0x6c, 0x79, 0x4c, 0x69, 0x6b, 0x65, 0x42, 0x61, 0x6c, + 0x61, 0x6e, 0x63, 0x65, 0x12, 0x28, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, + 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x44, 0x61, 0x69, 0x6c, 0x79, 0x4c, 0x69, 0x6b, 0x65, + 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, + 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, + 0x68, 0x44, 0x61, 0x69, 0x6c, 0x79, 0x4c, 0x69, 0x6b, 0x65, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, + 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x50, 0x0a, 0x0d, 0x43, 0x68, 0x61, + 0x6e, 0x67, 0x65, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x1e, 0x2e, 0x70, 0x61, 0x79, + 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x42, 0x61, 0x6c, 0x61, + 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x70, 0x61, 0x79, + 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x42, 0x61, 0x6c, 0x61, + 0x6e, 0x63, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5c, 0x0a, 0x11, 0x43, + 0x68, 0x65, 0x63, 0x6b, 0x41, 0x6e, 0x64, 0x53, 0x70, 0x65, 0x6e, 0x64, 0x4c, 0x69, 0x6b, 0x65, + 0x12, 0x22, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x43, 0x68, 0x65, 0x63, + 0x6b, 0x41, 0x6e, 0x64, 0x53, 0x70, 0x65, 0x6e, 0x64, 0x4c, 0x69, 0x6b, 0x65, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x23, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, + 0x43, 0x68, 0x65, 0x63, 0x6b, 0x41, 0x6e, 0x64, 0x53, 0x70, 0x65, 0x6e, 0x64, 0x4c, 0x69, 0x6b, + 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x7a, 0x0a, 0x1b, 0x43, 0x68, 0x61, + 0x6e, 0x67, 0x65, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x64, 0x4c, 0x69, 0x6b, 0x65, + 0x73, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x2c, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x64, 0x4c, 0x69, 0x6b, 0x65, 0x73, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x50, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x41, 0x6c, - 0x6c, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x1e, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, - 0x6e, 0x74, 0x73, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x6c, 0x6c, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, - 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, - 0x6e, 0x74, 0x73, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x6c, 0x6c, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, - 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x53, 0x0a, 0x0e, 0x43, 0x72, 0x65, - 0x61, 0x74, 0x65, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, 0x12, 0x1f, 0x2e, 0x70, 0x61, - 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x42, 0x61, 0x6c, - 0x61, 0x6e, 0x63, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x70, - 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x42, 0x61, - 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x31, - 0x5a, 0x2f, 0x2e, 0x2e, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6b, - 0x67, 0x2f, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x64, 0x65, 0x6c, 0x69, 0x76, - 0x65, 0x72, 0x79, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x3b, 0x67, 0x65, - 0x6e, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2d, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, + 0x73, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, + 0x64, 0x4c, 0x69, 0x6b, 0x65, 0x73, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x50, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x41, 0x6c, 0x6c, 0x42, + 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x1e, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, + 0x73, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x6c, 0x6c, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, + 0x73, 0x2e, 0x47, 0x65, 0x74, 0x41, 0x6c, 0x6c, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x53, 0x0a, 0x0e, 0x43, 0x72, 0x65, 0x61, 0x74, + 0x65, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x73, 0x12, 0x1f, 0x2e, 0x70, 0x61, 0x79, 0x6d, + 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x42, 0x61, 0x6c, 0x61, 0x6e, + 0x63, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x20, 0x2e, 0x70, 0x61, 0x79, + 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x42, 0x61, 0x6c, 0x61, + 0x6e, 0x63, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x41, 0x0a, 0x08, + 0x42, 0x75, 0x79, 0x4c, 0x69, 0x6b, 0x65, 0x73, 0x12, 0x19, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, + 0x6e, 0x74, 0x73, 0x2e, 0x42, 0x75, 0x79, 0x4c, 0x69, 0x6b, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x42, + 0x75, 0x79, 0x4c, 0x69, 0x6b, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, + 0x50, 0x0a, 0x0d, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, + 0x12, 0x1e, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x43, 0x72, 0x65, 0x61, + 0x74, 0x65, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x1f, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x43, 0x72, 0x65, 0x61, + 0x74, 0x65, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x4a, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x73, + 0x12, 0x1c, 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x47, 0x65, 0x74, 0x50, + 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, + 0x2e, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6f, + 0x64, 0x75, 0x63, 0x74, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x31, 0x5a, + 0x2f, 0x2e, 0x2e, 0x2f, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x70, 0x6b, 0x67, + 0x2f, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x64, 0x65, 0x6c, 0x69, 0x76, 0x65, + 0x72, 0x79, 0x2f, 0x67, 0x72, 0x70, 0x63, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x3b, 0x67, 0x65, 0x6e, + 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -956,7 +1334,7 @@ func file_payments_proto_rawDescGZIP() []byte { return file_payments_proto_rawDescData } -var file_payments_proto_msgTypes = make([]protoimpl.MessageInfo, 18) +var file_payments_proto_msgTypes = make([]protoimpl.MessageInfo, 25) var file_payments_proto_goTypes = []any{ (*GetDailyLikeBalanceRequest)(nil), // 0: payments.GetDailyLikeBalanceRequest (*GetDailyLikeBalanceResponse)(nil), // 1: payments.GetDailyLikeBalanceResponse @@ -976,31 +1354,46 @@ var file_payments_proto_goTypes = []any{ (*GetAllBalanceResponse)(nil), // 15: payments.GetAllBalanceResponse (*CreateBalancesRequest)(nil), // 16: payments.CreateBalancesRequest (*CreateBalancesResponse)(nil), // 17: payments.CreateBalancesResponse + (*BuyLikesRequest)(nil), // 18: payments.BuyLikesRequest + (*BuyLikesResponse)(nil), // 19: payments.BuyLikesResponse + (*Product)(nil), // 20: payments.Product + (*CreateProductRequest)(nil), // 21: payments.CreateProductRequest + (*CreateProductResponse)(nil), // 22: payments.CreateProductResponse + (*GetProductsRequest)(nil), // 23: payments.GetProductsRequest + (*GetProductsResponse)(nil), // 24: payments.GetProductsResponse } var file_payments_proto_depIdxs = []int32{ - 0, // 0: payments.Payment.GetDailyLikeBalance:input_type -> payments.GetDailyLikeBalanceRequest - 2, // 1: payments.Payment.GetPurchasedLikeBalance:input_type -> payments.GetPurchasedLikeBalanceRequest - 4, // 2: payments.Payment.GetBalance:input_type -> payments.GetBalanceRequest - 6, // 3: payments.Payment.RefreshDailyLikeBalance:input_type -> payments.RefreshDailyLikeBalanceRequest - 8, // 4: payments.Payment.ChangeBalance:input_type -> payments.ChangeBalanceRequest - 10, // 5: payments.Payment.CheckAndSpendLike:input_type -> payments.CheckAndSpendLikeRequest - 12, // 6: payments.Payment.ChangePurchasedLikesBalance:input_type -> payments.ChangePurchasedLikesBalanceRequest - 14, // 7: payments.Payment.GetAllBalance:input_type -> payments.GetAllBalanceRequest - 16, // 8: payments.Payment.CreateBalances:input_type -> payments.CreateBalancesRequest - 1, // 9: payments.Payment.GetDailyLikeBalance:output_type -> payments.GetDailyLikeBalanceResponse - 3, // 10: payments.Payment.GetPurchasedLikeBalance:output_type -> payments.GetPurchasedLikeBalanceResponse - 5, // 11: payments.Payment.GetBalance:output_type -> payments.GetBalanceResponse - 7, // 12: payments.Payment.RefreshDailyLikeBalance:output_type -> payments.RefreshDailyLikeBalanceResponse - 9, // 13: payments.Payment.ChangeBalance:output_type -> payments.ChangeBalanceResponse - 11, // 14: payments.Payment.CheckAndSpendLike:output_type -> payments.CheckAndSpendLikeResponse - 13, // 15: payments.Payment.ChangePurchasedLikesBalance:output_type -> payments.ChangePurchasedLikesBalanceResponse - 15, // 16: payments.Payment.GetAllBalance:output_type -> payments.GetAllBalanceResponse - 17, // 17: payments.Payment.CreateBalances:output_type -> payments.CreateBalancesResponse - 9, // [9:18] is the sub-list for method output_type - 0, // [0:9] is the sub-list for method input_type - 0, // [0:0] is the sub-list for extension type_name - 0, // [0:0] is the sub-list for extension extendee - 0, // [0:0] is the sub-list for field type_name + 20, // 0: payments.CreateProductRequest.Product:type_name -> payments.Product + 20, // 1: payments.GetProductsResponse.Products:type_name -> payments.Product + 0, // 2: payments.Payment.GetDailyLikeBalance:input_type -> payments.GetDailyLikeBalanceRequest + 2, // 3: payments.Payment.GetPurchasedLikeBalance:input_type -> payments.GetPurchasedLikeBalanceRequest + 4, // 4: payments.Payment.GetBalance:input_type -> payments.GetBalanceRequest + 6, // 5: payments.Payment.RefreshDailyLikeBalance:input_type -> payments.RefreshDailyLikeBalanceRequest + 8, // 6: payments.Payment.ChangeBalance:input_type -> payments.ChangeBalanceRequest + 10, // 7: payments.Payment.CheckAndSpendLike:input_type -> payments.CheckAndSpendLikeRequest + 12, // 8: payments.Payment.ChangePurchasedLikesBalance:input_type -> payments.ChangePurchasedLikesBalanceRequest + 14, // 9: payments.Payment.GetAllBalance:input_type -> payments.GetAllBalanceRequest + 16, // 10: payments.Payment.CreateBalances:input_type -> payments.CreateBalancesRequest + 18, // 11: payments.Payment.BuyLikes:input_type -> payments.BuyLikesRequest + 21, // 12: payments.Payment.CreateProduct:input_type -> payments.CreateProductRequest + 23, // 13: payments.Payment.GetProducts:input_type -> payments.GetProductsRequest + 1, // 14: payments.Payment.GetDailyLikeBalance:output_type -> payments.GetDailyLikeBalanceResponse + 3, // 15: payments.Payment.GetPurchasedLikeBalance:output_type -> payments.GetPurchasedLikeBalanceResponse + 5, // 16: payments.Payment.GetBalance:output_type -> payments.GetBalanceResponse + 7, // 17: payments.Payment.RefreshDailyLikeBalance:output_type -> payments.RefreshDailyLikeBalanceResponse + 9, // 18: payments.Payment.ChangeBalance:output_type -> payments.ChangeBalanceResponse + 11, // 19: payments.Payment.CheckAndSpendLike:output_type -> payments.CheckAndSpendLikeResponse + 13, // 20: payments.Payment.ChangePurchasedLikesBalance:output_type -> payments.ChangePurchasedLikesBalanceResponse + 15, // 21: payments.Payment.GetAllBalance:output_type -> payments.GetAllBalanceResponse + 17, // 22: payments.Payment.CreateBalances:output_type -> payments.CreateBalancesResponse + 19, // 23: payments.Payment.BuyLikes:output_type -> payments.BuyLikesResponse + 22, // 24: payments.Payment.CreateProduct:output_type -> payments.CreateProductResponse + 24, // 25: payments.Payment.GetProducts:output_type -> payments.GetProductsResponse + 14, // [14:26] is the sub-list for method output_type + 2, // [2:14] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name } func init() { file_payments_proto_init() } @@ -1014,7 +1407,7 @@ func file_payments_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_payments_proto_rawDesc, NumEnums: 0, - NumMessages: 18, + NumMessages: 25, NumExtensions: 0, NumServices: 1, }, diff --git a/internal/pkg/payments/delivery/grpc/gen/payments_grpc.pb.go b/internal/pkg/payments/delivery/grpc/gen/payments_grpc.pb.go index a3845fa..b2732f3 100644 --- a/internal/pkg/payments/delivery/grpc/gen/payments_grpc.pb.go +++ b/internal/pkg/payments/delivery/grpc/gen/payments_grpc.pb.go @@ -28,6 +28,9 @@ const ( Payment_ChangePurchasedLikesBalance_FullMethodName = "/payments.Payment/ChangePurchasedLikesBalance" Payment_GetAllBalance_FullMethodName = "/payments.Payment/GetAllBalance" Payment_CreateBalances_FullMethodName = "/payments.Payment/CreateBalances" + Payment_BuyLikes_FullMethodName = "/payments.Payment/BuyLikes" + Payment_CreateProduct_FullMethodName = "/payments.Payment/CreateProduct" + Payment_GetProducts_FullMethodName = "/payments.Payment/GetProducts" ) // PaymentClient is the client API for Payment service. @@ -43,6 +46,9 @@ type PaymentClient interface { ChangePurchasedLikesBalance(ctx context.Context, in *ChangePurchasedLikesBalanceRequest, opts ...grpc.CallOption) (*ChangePurchasedLikesBalanceResponse, error) GetAllBalance(ctx context.Context, in *GetAllBalanceRequest, opts ...grpc.CallOption) (*GetAllBalanceResponse, error) CreateBalances(ctx context.Context, in *CreateBalancesRequest, opts ...grpc.CallOption) (*CreateBalancesResponse, error) + BuyLikes(ctx context.Context, in *BuyLikesRequest, opts ...grpc.CallOption) (*BuyLikesResponse, error) + CreateProduct(ctx context.Context, in *CreateProductRequest, opts ...grpc.CallOption) (*CreateProductResponse, error) + GetProducts(ctx context.Context, in *GetProductsRequest, opts ...grpc.CallOption) (*GetProductsResponse, error) } type paymentClient struct { @@ -143,6 +149,36 @@ func (c *paymentClient) CreateBalances(ctx context.Context, in *CreateBalancesRe return out, nil } +func (c *paymentClient) BuyLikes(ctx context.Context, in *BuyLikesRequest, opts ...grpc.CallOption) (*BuyLikesResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(BuyLikesResponse) + err := c.cc.Invoke(ctx, Payment_BuyLikes_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *paymentClient) CreateProduct(ctx context.Context, in *CreateProductRequest, opts ...grpc.CallOption) (*CreateProductResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(CreateProductResponse) + err := c.cc.Invoke(ctx, Payment_CreateProduct_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *paymentClient) GetProducts(ctx context.Context, in *GetProductsRequest, opts ...grpc.CallOption) (*GetProductsResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetProductsResponse) + err := c.cc.Invoke(ctx, Payment_GetProducts_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + // PaymentServer is the server API for Payment service. // All implementations must embed UnimplementedPaymentServer // for forward compatibility. @@ -156,6 +192,9 @@ type PaymentServer interface { ChangePurchasedLikesBalance(context.Context, *ChangePurchasedLikesBalanceRequest) (*ChangePurchasedLikesBalanceResponse, error) GetAllBalance(context.Context, *GetAllBalanceRequest) (*GetAllBalanceResponse, error) CreateBalances(context.Context, *CreateBalancesRequest) (*CreateBalancesResponse, error) + BuyLikes(context.Context, *BuyLikesRequest) (*BuyLikesResponse, error) + CreateProduct(context.Context, *CreateProductRequest) (*CreateProductResponse, error) + GetProducts(context.Context, *GetProductsRequest) (*GetProductsResponse, error) mustEmbedUnimplementedPaymentServer() } @@ -193,6 +232,15 @@ func (UnimplementedPaymentServer) GetAllBalance(context.Context, *GetAllBalanceR func (UnimplementedPaymentServer) CreateBalances(context.Context, *CreateBalancesRequest) (*CreateBalancesResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method CreateBalances not implemented") } +func (UnimplementedPaymentServer) BuyLikes(context.Context, *BuyLikesRequest) (*BuyLikesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method BuyLikes not implemented") +} +func (UnimplementedPaymentServer) CreateProduct(context.Context, *CreateProductRequest) (*CreateProductResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreateProduct not implemented") +} +func (UnimplementedPaymentServer) GetProducts(context.Context, *GetProductsRequest) (*GetProductsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetProducts not implemented") +} func (UnimplementedPaymentServer) mustEmbedUnimplementedPaymentServer() {} func (UnimplementedPaymentServer) testEmbeddedByValue() {} @@ -376,6 +424,60 @@ func _Payment_CreateBalances_Handler(srv interface{}, ctx context.Context, dec f return interceptor(ctx, in, info, handler) } +func _Payment_BuyLikes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BuyLikesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PaymentServer).BuyLikes(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Payment_BuyLikes_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PaymentServer).BuyLikes(ctx, req.(*BuyLikesRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Payment_CreateProduct_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateProductRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PaymentServer).CreateProduct(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Payment_CreateProduct_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PaymentServer).CreateProduct(ctx, req.(*CreateProductRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Payment_GetProducts_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetProductsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PaymentServer).GetProducts(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Payment_GetProducts_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PaymentServer).GetProducts(ctx, req.(*GetProductsRequest)) + } + return interceptor(ctx, in, info, handler) +} + // Payment_ServiceDesc is the grpc.ServiceDesc for Payment service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -419,6 +521,18 @@ var Payment_ServiceDesc = grpc.ServiceDesc{ MethodName: "CreateBalances", Handler: _Payment_CreateBalances_Handler, }, + { + MethodName: "BuyLikes", + Handler: _Payment_BuyLikes_Handler, + }, + { + MethodName: "CreateProduct", + Handler: _Payment_CreateProduct_Handler, + }, + { + MethodName: "GetProducts", + Handler: _Payment_GetProducts_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "payments.proto", diff --git a/internal/pkg/payments/delivery/grpc/handlers.go b/internal/pkg/payments/delivery/grpc/handlers.go index b880ae1..ea47be8 100644 --- a/internal/pkg/payments/delivery/grpc/handlers.go +++ b/internal/pkg/payments/delivery/grpc/handlers.go @@ -3,9 +3,12 @@ package grpc import ( "context" "fmt" + "github.com/go-park-mail-ru/2024_2_SaraFun/internal/models" generatedPayments "github.com/go-park-mail-ru/2024_2_SaraFun/internal/pkg/payments/delivery/grpc/gen" "github.com/go-park-mail-ru/2024_2_SaraFun/internal/utils/consts" "go.uber.org/zap" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" ) type UseCase interface { @@ -19,6 +22,10 @@ type UseCase interface { AddBalance(ctx context.Context, userID int, amount int) error AddDailyLikesCount(ctx context.Context, userID int, amount int) error AddPurchasedLikesCount(ctx context.Context, userID int, amount int) error + GetProduct(ctx context.Context, title string) (models.Product, error) + CheckBalance(ctx context.Context, userID int, amount int) error + CreateProduct(ctx context.Context, product models.Product) (int, error) + GetProducts(ctx context.Context) ([]models.Product, error) } type GRPCHandler struct { @@ -186,3 +193,73 @@ func (h *GRPCHandler) CreateBalances(ctx context.Context, } return &generatedPayments.CreateBalancesResponse{}, nil } + +func (h *GRPCHandler) BuyLikes(ctx context.Context, + in *generatedPayments.BuyLikesRequest) (*generatedPayments.BuyLikesResponse, error) { + title := in.Title + amount := int(in.Amount) + userID := int(in.UserID) + spend := amount * (-1) + product, err := h.uc.GetProduct(ctx, title) + if err != nil { + h.logger.Error("grpc get balance error", zap.Error(err)) + return nil, fmt.Errorf("grpc get balance error: %w", err) + } + err = h.uc.CheckBalance(ctx, userID, amount) + if err != nil { + h.logger.Error("grpc check balance error", zap.Error(err)) + return nil, status.Error(codes.InvalidArgument, "Недостаточно средств") + } + + count := amount / product.Price + err = h.uc.ChangeBalance(ctx, userID, spend) + if err != nil { + h.logger.Error("grpc change balance error", zap.Error(err)) + return nil, fmt.Errorf("grpc change balance error: %w", err) + } + err = h.uc.ChangePurchasedLikeCount(ctx, userID, count) + if err != nil { + h.logger.Error("grpc change balance error", zap.Error(err)) + return nil, fmt.Errorf("grpc change balance error: %w", err) + } + response := &generatedPayments.BuyLikesResponse{} + return response, nil +} + +func (h *GRPCHandler) CreateProduct(ctx context.Context, + in *generatedPayments.CreateProductRequest) (*generatedPayments.CreateProductResponse, error) { + product := models.Product{ + Title: in.Product.Title, + Description: in.Product.Description, + ImageLink: in.Product.ImageLink, + Price: int(in.Product.Price), + } + id, err := h.uc.CreateProduct(ctx, product) + if err != nil { + h.logger.Error("grpc create product error", zap.Error(err)) + return nil, fmt.Errorf("grpc create product error: %w", err) + } + response := &generatedPayments.CreateProductResponse{ID: int32(id)} + return response, nil +} + +func (h *GRPCHandler) GetProducts(ctx context.Context, + in *generatedPayments.GetProductsRequest) (*generatedPayments.GetProductsResponse, error) { + products, err := h.uc.GetProducts(ctx) + if err != nil { + return nil, fmt.Errorf("grpc get products error: %w", err) + } + var grpcProducts []*generatedPayments.Product + for _, product := range products { + grpcProducts = append(grpcProducts, &generatedPayments.Product{ + Title: product.Title, + Description: product.Description, + ImageLink: product.ImageLink, + Price: int32(product.Price), + }) + } + response := &generatedPayments.GetProductsResponse{ + Products: grpcProducts, + } + return response, nil +} diff --git a/internal/pkg/payments/delivery/http/addProduct/handler.go b/internal/pkg/payments/delivery/http/addProduct/handler.go new file mode 100644 index 0000000..f9ef69e --- /dev/null +++ b/internal/pkg/payments/delivery/http/addProduct/handler.go @@ -0,0 +1,67 @@ +package addProduct + +import ( + "fmt" + "github.com/go-park-mail-ru/2024_2_SaraFun/internal/models" + generatedAuth "github.com/go-park-mail-ru/2024_2_SaraFun/internal/pkg/auth/delivery/grpc/gen" + generatedPayments "github.com/go-park-mail-ru/2024_2_SaraFun/internal/pkg/payments/delivery/grpc/gen" + "github.com/go-park-mail-ru/2024_2_SaraFun/internal/utils/consts" + "github.com/mailru/easyjson" + "go.uber.org/zap" + "net/http" +) + +type Handler struct { + authClient generatedAuth.AuthClient + paymentsClient generatedPayments.PaymentClient + logger *zap.Logger +} + +func NewHandler(authClient generatedAuth.AuthClient, paymentsClient generatedPayments.PaymentClient, + logger *zap.Logger) *Handler { + return &Handler{ + authClient: authClient, + paymentsClient: paymentsClient, + logger: logger, + } +} + +func (h *Handler) Handle(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + cookie, err := r.Cookie(consts.SessionCookie) + if err != nil { + h.logger.Error("bad cookie", zap.Error(err)) + http.Error(w, "bad cookie", http.StatusUnauthorized) + return + } + getUserIDReq := &generatedAuth.GetUserIDBySessionIDRequest{SessionID: cookie.Value} + _, err = h.authClient.GetUserIDBySessionID(ctx, getUserIDReq) + if err != nil { + h.logger.Error("get user id by session id", zap.Error(err)) + http.Error(w, "get user id by session id", http.StatusUnauthorized) + return + } + var data models.Product + err = easyjson.UnmarshalFromReader(r.Body, &data) + if err != nil { + h.logger.Error("unmarshal data", zap.Error(err)) + http.Error(w, "unmarshal data", http.StatusBadRequest) + return + } + + reqProduct := &generatedPayments.Product{ + Title: data.Title, + Description: data.Description, + ImageLink: data.ImageLink, + Price: int32(data.Price), + } + createProductReq := &generatedPayments.CreateProductRequest{Product: reqProduct} + _, err = h.paymentsClient.CreateProduct(ctx, createProductReq) + if err != nil { + h.logger.Error("create product error", zap.Error(err)) + http.Error(w, "create product", http.StatusInternalServerError) + return + } + h.logger.Info("add product success") + fmt.Fprintf(w, "ok") +} diff --git a/internal/pkg/payments/delivery/http/buyproduct/handler.go b/internal/pkg/payments/delivery/http/buyproduct/handler.go index abfc22e..7a2eb87 100644 --- a/internal/pkg/payments/delivery/http/buyproduct/handler.go +++ b/internal/pkg/payments/delivery/http/buyproduct/handler.go @@ -1,57 +1,35 @@ package buyproduct import ( - "bytes" - "encoding/json" + "fmt" generatedAuth "github.com/go-park-mail-ru/2024_2_SaraFun/internal/pkg/auth/delivery/grpc/gen" + generatedPayments "github.com/go-park-mail-ru/2024_2_SaraFun/internal/pkg/payments/delivery/grpc/gen" "github.com/go-park-mail-ru/2024_2_SaraFun/internal/utils/consts" - "github.com/google/uuid" "github.com/mailru/easyjson" "go.uber.org/zap" - "io" + "google.golang.org/grpc/status" "net/http" - "os" - "strconv" ) -type Handler struct { - authClient generatedAuth.AuthClient - logger *zap.Logger -} - -func NewHandler(authClient generatedAuth.AuthClient, logger *zap.Logger) *Handler { - return &Handler{ - authClient: authClient, - logger: logger, - } -} - //go:generate easyjson -all handler.go -type Amount struct { - Value string `json:"value"` - Currency string `json:"currency"` -} - -type Confirmation struct { - Type string `json:"type"` - ReturnUrl string `json:"return_url"` -} - type Request struct { - Title string `json:"title"` - Price string `json:"price"` + Title string `json:"type"` + Price int `json:"price"` } -type Response struct { - RedirectLink string `json:"redirect_link"` +type Handler struct { + authClient generatedAuth.AuthClient + paymentsClient generatedPayments.PaymentClient + logger *zap.Logger } -type APIRequest struct { - Amount Amount `json:"amount"` - Capture string `json:"capture"` - Confirmation Confirmation `json:"confirmation"` - Description string `json:"description"` +func NewHandler(authClient generatedAuth.AuthClient, paymentsClient generatedPayments.PaymentClient, logger *zap.Logger) *Handler { + return &Handler{ + authClient: authClient, + paymentsClient: paymentsClient, + logger: logger, + } } func (h *Handler) Handle(w http.ResponseWriter, r *http.Request) { @@ -69,88 +47,31 @@ func (h *Handler) Handle(w http.ResponseWriter, r *http.Request) { http.Error(w, "get user id by session id", http.StatusUnauthorized) return } - - var requestData Request - if err := easyjson.UnmarshalFromReader(r.Body, &requestData); err != nil { - h.logger.Error("unmarshal request", zap.Error(err)) - http.Error(w, "unmarshal request", http.StatusBadRequest) - return - } - - url := "https://api.yookassa.ru/v3/payments" - returnUrl := "https://spark-it.site/feed" - - apiRequest := &APIRequest{ - Amount: Amount{ - Value: requestData.Price, - Currency: "RUB", - }, - Capture: "true", - Confirmation: Confirmation{ - Type: "redirect", - ReturnUrl: returnUrl, - }, - Description: strconv.Itoa(int(userID.UserId)), - } - apiData, err := easyjson.Marshal(apiRequest) - if err != nil { - h.logger.Error("marshal api request", zap.Error(err)) - http.Error(w, "marshal api request", http.StatusInternalServerError) - return - } - - req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewBuffer(apiData)) + var data Request + err = easyjson.UnmarshalFromReader(r.Body, &data) if err != nil { - h.logger.Error("bad create api request", zap.Error(err)) - http.Error(w, "bad create api request", http.StatusInternalServerError) + h.logger.Error("json unmarshal", zap.Error(err)) + http.Error(w, "json unmarshal error", http.StatusBadRequest) return } - req.Header.Set("Content-Type", "application/json") - req.Header.Set("Idempotence-Key", uuid.New().String()) - shopID := os.Getenv("SHOP_ID") - secretKey := os.Getenv("SECRET_SHOP_KEY") - h.logger.Info("create api request", zap.String("shop_id", shopID)) - h.logger.Info("create api request", zap.String("secret_key", secretKey)) - req.SetBasicAuth(shopID, secretKey) - - client := &http.Client{} - resp, err := client.Do(req) - if err != nil { - h.logger.Error("bad api request", zap.Error(err)) - http.Error(w, "bad api request", http.StatusInternalServerError) - } - defer resp.Body.Close() - - body, err := io.ReadAll(resp.Body) - if err != nil { - h.logger.Error("bad api response reading body", zap.Error(err)) - http.Error(w, "bad api response reading body", http.StatusInternalServerError) - return - } - var apiResponse map[string]interface{} - - err = json.Unmarshal(body, &apiResponse) - if err != nil { - h.logger.Error("unmarshal api response body", zap.Error(err)) - http.Error(w, "unmarshal api response body", http.StatusInternalServerError) - return - } - - h.logger.Info("api response", zap.Any("apiResponse", apiResponse)) - confirmation := apiResponse["confirmation"].(map[string]interface{}) - response := Response{RedirectLink: confirmation["confirmation_url"].(string)} - jsonData, err := easyjson.Marshal(response) - if err != nil { - h.logger.Error("marshal json", zap.Error(err)) - http.Error(w, "marshal json", http.StatusInternalServerError) - return + buyLikesReq := &generatedPayments.BuyLikesRequest{ + Title: data.Title, + Amount: int32(data.Price), + UserID: userID.UserId, } - w.Header().Set("Content-Type", "application/json") - _, err = w.Write(jsonData) + _, err = h.paymentsClient.BuyLikes(ctx, buyLikesReq) if err != nil { - h.logger.Error("write response", zap.Error(err)) - http.Error(w, "write response", http.StatusInternalServerError) + st, ok := status.FromError(err) + if ok && st.String() == "Недостаточно средств" { + h.logger.Error("buy likes failed", zap.Error(err)) + http.Error(w, "У вас недостаточно средств. Срочно пополните его!", http.StatusBadRequest) + return + } + h.logger.Error("buy likes", zap.Error(err)) + http.Error(w, "buy likes", http.StatusInternalServerError) return } + h.logger.Info("buy product success") + fmt.Fprintf(w, "ok") } diff --git a/internal/pkg/payments/delivery/http/buyproduct/handler_easyjson.go b/internal/pkg/payments/delivery/http/buyproduct/handler_easyjson.go index 9d1a672..aefe372 100644 --- a/internal/pkg/payments/delivery/http/buyproduct/handler_easyjson.go +++ b/internal/pkg/payments/delivery/http/buyproduct/handler_easyjson.go @@ -17,7 +17,7 @@ var ( _ easyjson.Marshaler ) -func easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct(in *jlexer.Lexer, out *Response) { +func easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct(in *jlexer.Lexer, out *Request) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -36,76 +36,10 @@ func easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsD continue } switch key { - case "redirect_link": - out.RedirectLink = string(in.String()) - default: - in.SkipRecursive() - } - in.WantComma() - } - in.Delim('}') - if isTopLevel { - in.Consumed() - } -} -func easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct(out *jwriter.Writer, in Response) { - out.RawByte('{') - first := true - _ = first - { - const prefix string = ",\"redirect_link\":" - out.RawString(prefix[1:]) - out.String(string(in.RedirectLink)) - } - out.RawByte('}') -} - -// MarshalJSON supports json.Marshaler interface -func (v Response) MarshalJSON() ([]byte, error) { - w := jwriter.Writer{} - easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct(&w, v) - return w.Buffer.BuildBytes(), w.Error -} - -// MarshalEasyJSON supports easyjson.Marshaler interface -func (v Response) MarshalEasyJSON(w *jwriter.Writer) { - easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct(w, v) -} - -// UnmarshalJSON supports json.Unmarshaler interface -func (v *Response) UnmarshalJSON(data []byte) error { - r := jlexer.Lexer{Data: data} - easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct(&r, v) - return r.Error() -} - -// UnmarshalEasyJSON supports easyjson.Unmarshaler interface -func (v *Response) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct(l, v) -} -func easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct1(in *jlexer.Lexer, out *Request) { - isTopLevel := in.IsStart() - if in.IsNull() { - if isTopLevel { - in.Consumed() - } - in.Skip() - return - } - in.Delim('{') - for !in.IsDelim('}') { - key := in.UnsafeFieldName(false) - in.WantColon() - if in.IsNull() { - in.Skip() - in.WantComma() - continue - } - switch key { - case "title": + case "type": out.Title = string(in.String()) case "price": - out.Price = string(in.String()) + out.Price = int(in.Int()) default: in.SkipRecursive() } @@ -116,19 +50,19 @@ func easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsD in.Consumed() } } -func easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct1(out *jwriter.Writer, in Request) { +func easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct(out *jwriter.Writer, in Request) { out.RawByte('{') first := true _ = first { - const prefix string = ",\"title\":" + const prefix string = ",\"type\":" out.RawString(prefix[1:]) out.String(string(in.Title)) } { const prefix string = ",\"price\":" out.RawString(prefix) - out.String(string(in.Price)) + out.Int(int(in.Price)) } out.RawByte('}') } @@ -136,27 +70,27 @@ func easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsD // MarshalJSON supports json.Marshaler interface func (v Request) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct1(&w, v) + easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v Request) MarshalEasyJSON(w *jwriter.Writer) { - easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct1(w, v) + easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *Request) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct1(&r, v) + easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *Request) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct1(l, v) + easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct(l, v) } -func easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct2(in *jlexer.Lexer, out *Handler) { +func easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct1(in *jlexer.Lexer, out *Handler) { isTopLevel := in.IsStart() if in.IsNull() { if isTopLevel { @@ -185,7 +119,7 @@ func easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsD in.Consumed() } } -func easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct2(out *jwriter.Writer, in Handler) { +func easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct1(out *jwriter.Writer, in Handler) { out.RawByte('{') first := true _ = first @@ -195,256 +129,23 @@ func easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsD // MarshalJSON supports json.Marshaler interface func (v Handler) MarshalJSON() ([]byte, error) { w := jwriter.Writer{} - easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct2(&w, v) + easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct1(&w, v) return w.Buffer.BuildBytes(), w.Error } // MarshalEasyJSON supports easyjson.Marshaler interface func (v Handler) MarshalEasyJSON(w *jwriter.Writer) { - easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct2(w, v) + easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct1(w, v) } // UnmarshalJSON supports json.Unmarshaler interface func (v *Handler) UnmarshalJSON(data []byte) error { r := jlexer.Lexer{Data: data} - easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct2(&r, v) + easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct1(&r, v) return r.Error() } // UnmarshalEasyJSON supports easyjson.Unmarshaler interface func (v *Handler) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct2(l, v) -} -func easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct3(in *jlexer.Lexer, out *Confirmation) { - isTopLevel := in.IsStart() - if in.IsNull() { - if isTopLevel { - in.Consumed() - } - in.Skip() - return - } - in.Delim('{') - for !in.IsDelim('}') { - key := in.UnsafeFieldName(false) - in.WantColon() - if in.IsNull() { - in.Skip() - in.WantComma() - continue - } - switch key { - case "type": - out.Type = string(in.String()) - case "return_url": - out.ReturnUrl = string(in.String()) - default: - in.SkipRecursive() - } - in.WantComma() - } - in.Delim('}') - if isTopLevel { - in.Consumed() - } -} -func easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct3(out *jwriter.Writer, in Confirmation) { - out.RawByte('{') - first := true - _ = first - { - const prefix string = ",\"type\":" - out.RawString(prefix[1:]) - out.String(string(in.Type)) - } - { - const prefix string = ",\"return_url\":" - out.RawString(prefix) - out.String(string(in.ReturnUrl)) - } - out.RawByte('}') -} - -// MarshalJSON supports json.Marshaler interface -func (v Confirmation) MarshalJSON() ([]byte, error) { - w := jwriter.Writer{} - easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct3(&w, v) - return w.Buffer.BuildBytes(), w.Error -} - -// MarshalEasyJSON supports easyjson.Marshaler interface -func (v Confirmation) MarshalEasyJSON(w *jwriter.Writer) { - easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct3(w, v) -} - -// UnmarshalJSON supports json.Unmarshaler interface -func (v *Confirmation) UnmarshalJSON(data []byte) error { - r := jlexer.Lexer{Data: data} - easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct3(&r, v) - return r.Error() -} - -// UnmarshalEasyJSON supports easyjson.Unmarshaler interface -func (v *Confirmation) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct3(l, v) -} -func easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct4(in *jlexer.Lexer, out *Amount) { - isTopLevel := in.IsStart() - if in.IsNull() { - if isTopLevel { - in.Consumed() - } - in.Skip() - return - } - in.Delim('{') - for !in.IsDelim('}') { - key := in.UnsafeFieldName(false) - in.WantColon() - if in.IsNull() { - in.Skip() - in.WantComma() - continue - } - switch key { - case "value": - out.Value = string(in.String()) - case "currency": - out.Currency = string(in.String()) - default: - in.SkipRecursive() - } - in.WantComma() - } - in.Delim('}') - if isTopLevel { - in.Consumed() - } -} -func easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct4(out *jwriter.Writer, in Amount) { - out.RawByte('{') - first := true - _ = first - { - const prefix string = ",\"value\":" - out.RawString(prefix[1:]) - out.String(string(in.Value)) - } - { - const prefix string = ",\"currency\":" - out.RawString(prefix) - out.String(string(in.Currency)) - } - out.RawByte('}') -} - -// MarshalJSON supports json.Marshaler interface -func (v Amount) MarshalJSON() ([]byte, error) { - w := jwriter.Writer{} - easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct4(&w, v) - return w.Buffer.BuildBytes(), w.Error -} - -// MarshalEasyJSON supports easyjson.Marshaler interface -func (v Amount) MarshalEasyJSON(w *jwriter.Writer) { - easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct4(w, v) -} - -// UnmarshalJSON supports json.Unmarshaler interface -func (v *Amount) UnmarshalJSON(data []byte) error { - r := jlexer.Lexer{Data: data} - easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct4(&r, v) - return r.Error() -} - -// UnmarshalEasyJSON supports easyjson.Unmarshaler interface -func (v *Amount) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct4(l, v) -} -func easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct5(in *jlexer.Lexer, out *APIRequest) { - isTopLevel := in.IsStart() - if in.IsNull() { - if isTopLevel { - in.Consumed() - } - in.Skip() - return - } - in.Delim('{') - for !in.IsDelim('}') { - key := in.UnsafeFieldName(false) - in.WantColon() - if in.IsNull() { - in.Skip() - in.WantComma() - continue - } - switch key { - case "amount": - (out.Amount).UnmarshalEasyJSON(in) - case "capture": - out.Capture = string(in.String()) - case "confirmation": - (out.Confirmation).UnmarshalEasyJSON(in) - case "description": - out.Description = string(in.String()) - default: - in.SkipRecursive() - } - in.WantComma() - } - in.Delim('}') - if isTopLevel { - in.Consumed() - } -} -func easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct5(out *jwriter.Writer, in APIRequest) { - out.RawByte('{') - first := true - _ = first - { - const prefix string = ",\"amount\":" - out.RawString(prefix[1:]) - (in.Amount).MarshalEasyJSON(out) - } - { - const prefix string = ",\"capture\":" - out.RawString(prefix) - out.String(string(in.Capture)) - } - { - const prefix string = ",\"confirmation\":" - out.RawString(prefix) - (in.Confirmation).MarshalEasyJSON(out) - } - { - const prefix string = ",\"description\":" - out.RawString(prefix) - out.String(string(in.Description)) - } - out.RawByte('}') -} - -// MarshalJSON supports json.Marshaler interface -func (v APIRequest) MarshalJSON() ([]byte, error) { - w := jwriter.Writer{} - easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct5(&w, v) - return w.Buffer.BuildBytes(), w.Error -} - -// MarshalEasyJSON supports easyjson.Marshaler interface -func (v APIRequest) MarshalEasyJSON(w *jwriter.Writer) { - easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct5(w, v) -} - -// UnmarshalJSON supports json.Unmarshaler interface -func (v *APIRequest) UnmarshalJSON(data []byte) error { - r := jlexer.Lexer{Data: data} - easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct5(&r, v) - return r.Error() -} - -// UnmarshalEasyJSON supports easyjson.Unmarshaler interface -func (v *APIRequest) UnmarshalEasyJSON(l *jlexer.Lexer) { - easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct5(l, v) + easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct1(l, v) } diff --git a/internal/pkg/payments/delivery/http/getProducts/handler.go b/internal/pkg/payments/delivery/http/getProducts/handler.go new file mode 100644 index 0000000..b752d18 --- /dev/null +++ b/internal/pkg/payments/delivery/http/getProducts/handler.go @@ -0,0 +1,80 @@ +package getProducts + +import ( + "github.com/go-park-mail-ru/2024_2_SaraFun/internal/models" + generatedAuth "github.com/go-park-mail-ru/2024_2_SaraFun/internal/pkg/auth/delivery/grpc/gen" + generatedPayments "github.com/go-park-mail-ru/2024_2_SaraFun/internal/pkg/payments/delivery/grpc/gen" + "github.com/go-park-mail-ru/2024_2_SaraFun/internal/utils/consts" + "github.com/mailru/easyjson" + "go.uber.org/zap" + "net/http" +) + +//go:generate easyjson -all handler.go + +type Response struct { + Responses []models.Product `json:"responses"` +} + +type Handler struct { + authClient generatedAuth.AuthClient + paymentsClient generatedPayments.PaymentClient + logger *zap.Logger +} + +func NewHandler(authClient generatedAuth.AuthClient, paymentClient generatedPayments.PaymentClient, logger *zap.Logger) *Handler { + return &Handler{ + authClient: authClient, + paymentsClient: paymentClient, + logger: logger, + } +} + +func (h *Handler) Handle(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + cookie, err := r.Cookie(consts.SessionCookie) + if err != nil { + h.logger.Error("bad cookie", zap.Error(err)) + http.Error(w, "bad cookie", http.StatusUnauthorized) + return + } + getUserIDReq := &generatedAuth.GetUserIDBySessionIDRequest{SessionID: cookie.Value} + _, err = h.authClient.GetUserIDBySessionID(ctx, getUserIDReq) + if err != nil { + h.logger.Error("get user id by session id", zap.Error(err)) + http.Error(w, "get user id by session id", http.StatusUnauthorized) + return + } + getProductsReq := &generatedPayments.GetProductsRequest{} + products, err := h.paymentsClient.GetProducts(ctx, getProductsReq) + if err != nil { + h.logger.Error("get products", zap.Error(err)) + http.Error(w, "get products error", http.StatusInternalServerError) + return + } + + var prs []models.Product + for _, product := range products.Products { + pr := models.Product{ + Title: product.Title, + Description: product.Description, + ImageLink: product.ImageLink, + Price: int(product.Price), + } + prs = append(prs, pr) + } + + w.Header().Set("Content-Type", "application/json") + response := Response{Responses: prs} + jsonData, err := easyjson.Marshal(response) + if err != nil { + h.logger.Error("GetProducts Handler: bad marshalling json", zap.Error(err)) + http.Error(w, "bad marshalling json", http.StatusInternalServerError) + } + _, err = w.Write(jsonData) + if err != nil { + h.logger.Error("GetProducts Handler: error writing response", zap.Error(err)) + http.Error(w, "error writing json response", http.StatusInternalServerError) + } + h.logger.Info("GetProducts Handler: success") +} diff --git a/internal/pkg/payments/delivery/http/getProducts/handler_easyjson.go b/internal/pkg/payments/delivery/http/getProducts/handler_easyjson.go new file mode 100644 index 0000000..668e3af --- /dev/null +++ b/internal/pkg/payments/delivery/http/getProducts/handler_easyjson.go @@ -0,0 +1,177 @@ +// Code generated by easyjson for marshaling/unmarshaling. DO NOT EDIT. + +package getProducts + +import ( + json "encoding/json" + models "github.com/go-park-mail-ru/2024_2_SaraFun/internal/models" + easyjson "github.com/mailru/easyjson" + jlexer "github.com/mailru/easyjson/jlexer" + jwriter "github.com/mailru/easyjson/jwriter" +) + +// suppress unused package warning +var ( + _ *json.RawMessage + _ *jlexer.Lexer + _ *jwriter.Writer + _ easyjson.Marshaler +) + +func easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpGetProducts(in *jlexer.Lexer, out *Response) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "responses": + if in.IsNull() { + in.Skip() + out.Responses = nil + } else { + in.Delim('[') + if out.Responses == nil { + if !in.IsDelim(']') { + out.Responses = make([]models.Product, 0, 1) + } else { + out.Responses = []models.Product{} + } + } else { + out.Responses = (out.Responses)[:0] + } + for !in.IsDelim(']') { + var v1 models.Product + (v1).UnmarshalEasyJSON(in) + out.Responses = append(out.Responses, v1) + in.WantComma() + } + in.Delim(']') + } + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpGetProducts(out *jwriter.Writer, in Response) { + out.RawByte('{') + first := true + _ = first + { + const prefix string = ",\"responses\":" + out.RawString(prefix[1:]) + if in.Responses == nil && (out.Flags&jwriter.NilSliceAsEmpty) == 0 { + out.RawString("null") + } else { + out.RawByte('[') + for v2, v3 := range in.Responses { + if v2 > 0 { + out.RawByte(',') + } + (v3).MarshalEasyJSON(out) + } + out.RawByte(']') + } + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v Response) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpGetProducts(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v Response) MarshalEasyJSON(w *jwriter.Writer) { + easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpGetProducts(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *Response) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpGetProducts(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *Response) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpGetProducts(l, v) +} +func easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpGetProducts1(in *jlexer.Lexer, out *Handler) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpGetProducts1(out *jwriter.Writer, in Handler) { + out.RawByte('{') + first := true + _ = first + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v Handler) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpGetProducts1(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v Handler) MarshalEasyJSON(w *jwriter.Writer) { + easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpGetProducts1(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *Handler) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpGetProducts1(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *Handler) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpGetProducts1(l, v) +} diff --git a/internal/pkg/payments/delivery/http/topUpBalance/handler.go b/internal/pkg/payments/delivery/http/topUpBalance/handler.go new file mode 100644 index 0000000..bdcb35d --- /dev/null +++ b/internal/pkg/payments/delivery/http/topUpBalance/handler.go @@ -0,0 +1,156 @@ +package topUpBalance + +import ( + "bytes" + "encoding/json" + generatedAuth "github.com/go-park-mail-ru/2024_2_SaraFun/internal/pkg/auth/delivery/grpc/gen" + "github.com/go-park-mail-ru/2024_2_SaraFun/internal/utils/consts" + "github.com/google/uuid" + "github.com/mailru/easyjson" + "go.uber.org/zap" + "io" + "net/http" + "os" + "strconv" +) + +type Handler struct { + authClient generatedAuth.AuthClient + logger *zap.Logger +} + +func NewHandler(authClient generatedAuth.AuthClient, logger *zap.Logger) *Handler { + return &Handler{ + authClient: authClient, + logger: logger, + } +} + +//go:generate easyjson -all handler.go + +type Amount struct { + Value string `json:"value"` + Currency string `json:"currency"` +} + +type Confirmation struct { + Type string `json:"type"` + ReturnUrl string `json:"return_url"` +} + +type Request struct { + Title string `json:"title"` + Price string `json:"price"` +} + +type Response struct { + RedirectLink string `json:"redirect_link"` +} + +type APIRequest struct { + Amount Amount `json:"amount"` + Capture string `json:"capture"` + Confirmation Confirmation `json:"confirmation"` + Description string `json:"description"` +} + +func (h *Handler) Handle(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() + cookie, err := r.Cookie(consts.SessionCookie) + if err != nil { + h.logger.Error("bad cookie", zap.Error(err)) + http.Error(w, "bad cookie", http.StatusUnauthorized) + return + } + getUserIDReq := &generatedAuth.GetUserIDBySessionIDRequest{SessionID: cookie.Value} + userID, err := h.authClient.GetUserIDBySessionID(ctx, getUserIDReq) + if err != nil { + h.logger.Error("get user id by session id", zap.Error(err)) + http.Error(w, "get user id by session id", http.StatusUnauthorized) + return + } + + var requestData Request + if err := easyjson.UnmarshalFromReader(r.Body, &requestData); err != nil { + h.logger.Error("unmarshal request", zap.Error(err)) + http.Error(w, "unmarshal request", http.StatusBadRequest) + return + } + + url := "https://api.yookassa.ru/v3/payments" + returnUrl := "https://spark-it.site/feed" + + apiRequest := &APIRequest{ + Amount: Amount{ + Value: requestData.Price, + Currency: "RUB", + }, + Capture: "true", + Confirmation: Confirmation{ + Type: "redirect", + ReturnUrl: returnUrl, + }, + Description: strconv.Itoa(int(userID.UserId)), + } + apiData, err := easyjson.Marshal(apiRequest) + if err != nil { + h.logger.Error("marshal api request", zap.Error(err)) + http.Error(w, "marshal api request", http.StatusInternalServerError) + return + } + + req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewBuffer(apiData)) + if err != nil { + h.logger.Error("bad create api request", zap.Error(err)) + http.Error(w, "bad create api request", http.StatusInternalServerError) + return + } + req.Header.Set("Content-Type", "application/json") + req.Header.Set("Idempotence-Key", uuid.New().String()) + + shopID := os.Getenv("SHOP_ID") + secretKey := os.Getenv("SECRET_SHOP_KEY") + h.logger.Info("create api request", zap.String("shop_id", shopID)) + h.logger.Info("create api request", zap.String("secret_key", secretKey)) + req.SetBasicAuth(shopID, secretKey) + + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + h.logger.Error("bad api request", zap.Error(err)) + http.Error(w, "bad api request", http.StatusInternalServerError) + } + defer resp.Body.Close() + + body, err := io.ReadAll(resp.Body) + if err != nil { + h.logger.Error("bad api response reading body", zap.Error(err)) + http.Error(w, "bad api response reading body", http.StatusInternalServerError) + return + } + var apiResponse map[string]interface{} + + err = json.Unmarshal(body, &apiResponse) + if err != nil { + h.logger.Error("unmarshal api response body", zap.Error(err)) + http.Error(w, "unmarshal api response body", http.StatusInternalServerError) + return + } + + h.logger.Info("api response", zap.Any("apiResponse", apiResponse)) + confirmation := apiResponse["confirmation"].(map[string]interface{}) + response := Response{RedirectLink: confirmation["confirmation_url"].(string)} + jsonData, err := easyjson.Marshal(response) + if err != nil { + h.logger.Error("marshal json", zap.Error(err)) + http.Error(w, "marshal json", http.StatusInternalServerError) + return + } + w.Header().Set("Content-Type", "application/json") + _, err = w.Write(jsonData) + if err != nil { + h.logger.Error("write response", zap.Error(err)) + http.Error(w, "write response", http.StatusInternalServerError) + return + } +} diff --git a/internal/pkg/payments/delivery/http/topUpBalance/handler_easyjson.go b/internal/pkg/payments/delivery/http/topUpBalance/handler_easyjson.go new file mode 100644 index 0000000..f7b96d9 --- /dev/null +++ b/internal/pkg/payments/delivery/http/topUpBalance/handler_easyjson.go @@ -0,0 +1,450 @@ +// Code generated by easyjson for marshaling/unmarshaling. DO NOT EDIT. + +package topUpBalance + +import ( + json "encoding/json" + easyjson "github.com/mailru/easyjson" + jlexer "github.com/mailru/easyjson/jlexer" + jwriter "github.com/mailru/easyjson/jwriter" +) + +// suppress unused package warning +var ( + _ *json.RawMessage + _ *jlexer.Lexer + _ *jwriter.Writer + _ easyjson.Marshaler +) + +func easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct(in *jlexer.Lexer, out *Response) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "redirect_link": + out.RedirectLink = string(in.String()) + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct(out *jwriter.Writer, in Response) { + out.RawByte('{') + first := true + _ = first + { + const prefix string = ",\"redirect_link\":" + out.RawString(prefix[1:]) + out.String(string(in.RedirectLink)) + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v Response) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v Response) MarshalEasyJSON(w *jwriter.Writer) { + easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *Response) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *Response) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct(l, v) +} +func easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct1(in *jlexer.Lexer, out *Request) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "title": + out.Title = string(in.String()) + case "price": + out.Price = string(in.String()) + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct1(out *jwriter.Writer, in Request) { + out.RawByte('{') + first := true + _ = first + { + const prefix string = ",\"title\":" + out.RawString(prefix[1:]) + out.String(string(in.Title)) + } + { + const prefix string = ",\"price\":" + out.RawString(prefix) + out.String(string(in.Price)) + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v Request) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct1(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v Request) MarshalEasyJSON(w *jwriter.Writer) { + easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct1(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *Request) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct1(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *Request) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct1(l, v) +} +func easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct2(in *jlexer.Lexer, out *Handler) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct2(out *jwriter.Writer, in Handler) { + out.RawByte('{') + first := true + _ = first + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v Handler) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct2(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v Handler) MarshalEasyJSON(w *jwriter.Writer) { + easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct2(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *Handler) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct2(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *Handler) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct2(l, v) +} +func easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct3(in *jlexer.Lexer, out *Confirmation) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "type": + out.Type = string(in.String()) + case "return_url": + out.ReturnUrl = string(in.String()) + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct3(out *jwriter.Writer, in Confirmation) { + out.RawByte('{') + first := true + _ = first + { + const prefix string = ",\"type\":" + out.RawString(prefix[1:]) + out.String(string(in.Type)) + } + { + const prefix string = ",\"return_url\":" + out.RawString(prefix) + out.String(string(in.ReturnUrl)) + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v Confirmation) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct3(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v Confirmation) MarshalEasyJSON(w *jwriter.Writer) { + easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct3(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *Confirmation) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct3(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *Confirmation) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct3(l, v) +} +func easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct4(in *jlexer.Lexer, out *Amount) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "value": + out.Value = string(in.String()) + case "currency": + out.Currency = string(in.String()) + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct4(out *jwriter.Writer, in Amount) { + out.RawByte('{') + first := true + _ = first + { + const prefix string = ",\"value\":" + out.RawString(prefix[1:]) + out.String(string(in.Value)) + } + { + const prefix string = ",\"currency\":" + out.RawString(prefix) + out.String(string(in.Currency)) + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v Amount) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct4(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v Amount) MarshalEasyJSON(w *jwriter.Writer) { + easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct4(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *Amount) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct4(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *Amount) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct4(l, v) +} +func easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct5(in *jlexer.Lexer, out *APIRequest) { + isTopLevel := in.IsStart() + if in.IsNull() { + if isTopLevel { + in.Consumed() + } + in.Skip() + return + } + in.Delim('{') + for !in.IsDelim('}') { + key := in.UnsafeFieldName(false) + in.WantColon() + if in.IsNull() { + in.Skip() + in.WantComma() + continue + } + switch key { + case "amount": + (out.Amount).UnmarshalEasyJSON(in) + case "capture": + out.Capture = string(in.String()) + case "confirmation": + (out.Confirmation).UnmarshalEasyJSON(in) + case "description": + out.Description = string(in.String()) + default: + in.SkipRecursive() + } + in.WantComma() + } + in.Delim('}') + if isTopLevel { + in.Consumed() + } +} +func easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct5(out *jwriter.Writer, in APIRequest) { + out.RawByte('{') + first := true + _ = first + { + const prefix string = ",\"amount\":" + out.RawString(prefix[1:]) + (in.Amount).MarshalEasyJSON(out) + } + { + const prefix string = ",\"capture\":" + out.RawString(prefix) + out.String(string(in.Capture)) + } + { + const prefix string = ",\"confirmation\":" + out.RawString(prefix) + (in.Confirmation).MarshalEasyJSON(out) + } + { + const prefix string = ",\"description\":" + out.RawString(prefix) + out.String(string(in.Description)) + } + out.RawByte('}') +} + +// MarshalJSON supports json.Marshaler interface +func (v APIRequest) MarshalJSON() ([]byte, error) { + w := jwriter.Writer{} + easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct5(&w, v) + return w.Buffer.BuildBytes(), w.Error +} + +// MarshalEasyJSON supports easyjson.Marshaler interface +func (v APIRequest) MarshalEasyJSON(w *jwriter.Writer) { + easyjson888c126aEncodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct5(w, v) +} + +// UnmarshalJSON supports json.Unmarshaler interface +func (v *APIRequest) UnmarshalJSON(data []byte) error { + r := jlexer.Lexer{Data: data} + easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct5(&r, v) + return r.Error() +} + +// UnmarshalEasyJSON supports easyjson.Unmarshaler interface +func (v *APIRequest) UnmarshalEasyJSON(l *jlexer.Lexer) { + easyjson888c126aDecodeGithubComGoParkMailRu20242SaraFunInternalPkgPaymentsDeliveryHttpBuyproduct5(l, v) +} diff --git a/internal/pkg/payments/repo/payments.go b/internal/pkg/payments/repo/payments.go index b494f4d..b8d3562 100644 --- a/internal/pkg/payments/repo/payments.go +++ b/internal/pkg/payments/repo/payments.go @@ -151,7 +151,7 @@ func (repo *Storage) GetPurchasedLikesCount(ctx context.Context, userID int) (in } func (repo *Storage) CreateProduct(ctx context.Context, product models.Product) (int, error) { - query := `INSERT INTO product (title, description, imagelink, price) VALUES ($1, $2, $3, $4)` + query := `INSERT INTO product (title, description, imagelink, price) VALUES ($1, $2, $3, $4) RETURNING id` var id int err := repo.DB.QueryRowContext(ctx, query, product.Title, product.Description, product.ImageLink, product.Price).Scan(&id) if err != nil { @@ -181,3 +181,24 @@ func (repo *Storage) UpdateProduct(ctx context.Context, title string, product mo } return nil } + +func (repo *Storage) GetProducts(ctx context.Context) ([]models.Product, error) { + query := `SELECT title, description, imagelink, price FROM product` + var products []models.Product + rows, err := repo.DB.QueryContext(ctx, query) + if err != nil { + repo.logger.Error("GetProducts db query error", zap.Error(err)) + return products, fmt.Errorf("GetProducts db query error: %w", err) + } + defer rows.Close() + for rows.Next() { + var product models.Product + err := rows.Scan(&product.Title, &product.Description, &product.ImageLink, &product.Price) + if err != nil { + repo.logger.Error("GetProducts row scan error", zap.Error(err)) + return products, fmt.Errorf("GetProducts row scan error: %w", err) + } + products = append(products, product) + } + return products, nil +} diff --git a/internal/pkg/payments/usecase/usecase.go b/internal/pkg/payments/usecase/usecase.go index ff1553f..0ef6b93 100644 --- a/internal/pkg/payments/usecase/usecase.go +++ b/internal/pkg/payments/usecase/usecase.go @@ -2,6 +2,7 @@ package usecase import ( "context" + "errors" "fmt" "github.com/go-park-mail-ru/2024_2_SaraFun/internal/models" "go.uber.org/zap" @@ -25,6 +26,7 @@ type Repository interface { CreateProduct(ctx context.Context, product models.Product) (int, error) GetProduct(ctx context.Context, title string) (models.Product, error) UpdateProduct(ctx context.Context, title string, product models.Product) error + GetProducts(ctx context.Context) ([]models.Product, error) } type UseCase struct { @@ -161,6 +163,7 @@ func (u *UseCase) CreateProduct(ctx context.Context, product models.Product) (in u.logger.Error("usecase create product bad price", zap.Int("price", product.Price)) return -1, fmt.Errorf("invalid price") } + product.ImageLink = "" id, err := u.repo.CreateProduct(ctx, product) if err != nil { u.logger.Error("usecase create product error", zap.Error(err)) @@ -190,3 +193,25 @@ func (u *UseCase) UpdateProduct(ctx context.Context, title string, product model } return nil } + +func (u *UseCase) CheckBalance(ctx context.Context, userID int, needMoney int) error { + amount, err := u.repo.GetBalance(ctx, userID) + if err != nil { + u.logger.Error("usecase get balance error", zap.Error(err)) + return fmt.Errorf("failed to get balance: %w", err) + } + if amount < needMoney { + u.logger.Error("usecase get balance error", zap.Int("amount", amount)) + return errors.New("Недостаточно средств") + } + return err +} + +func (u *UseCase) GetProducts(ctx context.Context) ([]models.Product, error) { + profiles, err := u.repo.GetProducts(ctx) + if err != nil { + u.logger.Error("usecase create product error", zap.Error(err)) + return []models.Product{}, fmt.Errorf("failed to create product: %w", err) + } + return profiles, err +} diff --git a/internal/pkg/personalities/delivery/http/getuserlist/handler.go b/internal/pkg/personalities/delivery/http/getuserlist/handler.go index 1cfeb86..2be957d 100644 --- a/internal/pkg/personalities/delivery/http/getuserlist/handler.go +++ b/internal/pkg/personalities/delivery/http/getuserlist/handler.go @@ -152,7 +152,7 @@ func (h *Handler) Handle(w http.ResponseWriter, r *http.Request) { _, err = w.Write(jsonData) if err != nil { h.logger.Error("GetMatches Handler: error writing response", zap.Error(err)) - http.Error(w, "error writing json response", http.StatusUnauthorized) + http.Error(w, "error writing json response", http.StatusInternalServerError) } h.logger.Info("GetMatches Handler: success") diff --git a/proto/payments.proto b/proto/payments.proto index cb7555f..3e35904 100644 --- a/proto/payments.proto +++ b/proto/payments.proto @@ -12,6 +12,9 @@ service Payment { rpc ChangePurchasedLikesBalance(ChangePurchasedLikesBalanceRequest) returns (ChangePurchasedLikesBalanceResponse); rpc GetAllBalance(GetAllBalanceRequest) returns (GetAllBalanceResponse); rpc CreateBalances(CreateBalancesRequest) returns (CreateBalancesResponse); + rpc BuyLikes(BuyLikesRequest) returns (BuyLikesResponse); + rpc CreateProduct(CreateProductRequest) returns (CreateProductResponse); + rpc GetProducts(GetProductsRequest) returns (GetProductsResponse); } message GetDailyLikeBalanceRequest { @@ -77,4 +80,34 @@ message CreateBalancesRequest { } message CreateBalancesResponse { +} + +message BuyLikesRequest { + string Title = 1; + int32 Amount = 2; + int32 UserID = 3; +} + +message BuyLikesResponse {} + +message Product { + string Title = 1; + string Description = 2; + string ImageLink = 3; + int32 Price = 4; +} + +message CreateProductRequest { + Product Product = 1; +} + +message CreateProductResponse { + int32 ID = 1; +} + +message GetProductsRequest { +} + +message GetProductsResponse { + repeated Product Products = 1; } \ No newline at end of file