diff --git a/cmd/main/main.go b/cmd/main/main.go index 4fb6566..680c8cd 100644 --- a/cmd/main/main.go +++ b/cmd/main/main.go @@ -187,7 +187,7 @@ func main() { paymentsClient := grpcpayments.NewPaymentClient(paymentsConn) cors := corsMiddleware.New(logger) - signUp := signup.NewHandler(personalitiesClient, authClient, logger) + signUp := signup.NewHandler(personalitiesClient, authClient, paymentsClient, logger) signIn := signin.NewHandler(personalitiesClient, authClient, logger) getUsers := getuserlist.NewHandler(authClient, personalitiesClient, imageUseCase, communicationsClient, logger) checkAuth := checkauth.NewHandler(authClient, logger) diff --git a/internal/pkg/auth/delivery/http/signup/handler.go b/internal/pkg/auth/delivery/http/signup/handler.go index ed1ee69..1ef41c5 100644 --- a/internal/pkg/auth/delivery/http/signup/handler.go +++ b/internal/pkg/auth/delivery/http/signup/handler.go @@ -5,6 +5,7 @@ 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" generatedPersonalities "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/utils/consts" "github.com/go-park-mail-ru/2024_2_SaraFun/internal/utils/hashing" @@ -39,6 +40,7 @@ type PersonalitiesClient interface { type Handler struct { personalitiesClient generatedPersonalities.PersonalitiesClient sessionClient generatedAuth.AuthClient + paymentsClient generatedPayments.PaymentClient logger *zap.Logger } @@ -54,10 +56,13 @@ type Request struct { Gender string `json:"gender"` } -func NewHandler(personalitiesClient generatedPersonalities.PersonalitiesClient, sessionsClient generatedAuth.AuthClient, logger *zap.Logger) *Handler { +func NewHandler(personalitiesClient generatedPersonalities.PersonalitiesClient, + sessionsClient generatedAuth.AuthClient, paymentsClient generatedPayments.PaymentClient, + logger *zap.Logger) *Handler { return &Handler{ personalitiesClient: personalitiesClient, sessionClient: sessionsClient, + paymentsClient: paymentsClient, logger: logger, } } @@ -154,6 +159,17 @@ func (h *Handler) Handle(w http.ResponseWriter, r *http.Request) { } user.ID = int(id.UserId) + createBalancesRequest := &generatedPayments.CreateBalancesRequest{ + UserID: id.UserId, + Amount: 3, + } + _, err = h.paymentsClient.CreateBalances(ctx, createBalancesRequest) + if err != nil { + h.logger.Error("failed to create balances", zap.Error(err)) + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + //auth grpc sessUser := &generatedAuth.User{ ID: int32(user.ID), diff --git a/internal/pkg/payments/delivery/grpc/gen/payments.pb.go b/internal/pkg/payments/delivery/grpc/gen/payments.pb.go index bd20e48..67db76c 100644 --- a/internal/pkg/payments/delivery/grpc/gen/payments.pb.go +++ b/internal/pkg/payments/delivery/grpc/gen/payments.pb.go @@ -727,6 +727,95 @@ func (x *GetAllBalanceResponse) GetMoneyBalance() int32 { return 0 } +type CreateBalancesRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + UserID int32 `protobuf:"varint,1,opt,name=UserID,proto3" json:"UserID,omitempty"` + Amount int32 `protobuf:"varint,2,opt,name=Amount,proto3" json:"Amount,omitempty"` +} + +func (x *CreateBalancesRequest) Reset() { + *x = CreateBalancesRequest{} + mi := &file_payments_proto_msgTypes[16] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *CreateBalancesRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateBalancesRequest) ProtoMessage() {} + +func (x *CreateBalancesRequest) ProtoReflect() protoreflect.Message { + mi := &file_payments_proto_msgTypes[16] + 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 CreateBalancesRequest.ProtoReflect.Descriptor instead. +func (*CreateBalancesRequest) Descriptor() ([]byte, []int) { + return file_payments_proto_rawDescGZIP(), []int{16} +} + +func (x *CreateBalancesRequest) GetUserID() int32 { + if x != nil { + return x.UserID + } + return 0 +} + +func (x *CreateBalancesRequest) GetAmount() int32 { + if x != nil { + return x.Amount + } + return 0 +} + +type CreateBalancesResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *CreateBalancesResponse) Reset() { + *x = CreateBalancesResponse{} + mi := &file_payments_proto_msgTypes[17] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *CreateBalancesResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateBalancesResponse) ProtoMessage() {} + +func (x *CreateBalancesResponse) ProtoReflect() protoreflect.Message { + mi := &file_payments_proto_msgTypes[17] + 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 CreateBalancesResponse.ProtoReflect.Descriptor instead. +func (*CreateBalancesResponse) Descriptor() ([]byte, []int) { + return file_payments_proto_rawDescGZIP(), []int{17} +} + var File_payments_proto protoreflect.FileDescriptor var file_payments_proto_rawDesc = []byte{ @@ -787,61 +876,72 @@ var file_payments_proto_rawDesc = []byte{ 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x14, 0x50, 0x75, 0x72, 0x63, 0x68, 0x61, 0x73, 0x65, 0x64, 0x4c, 0x69, 0x6b, 0x65, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, - 0x05, 0x52, 0x0c, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x32, - 0x94, 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, + 0x05, 0x52, 0x0c, 0x4d, 0x6f, 0x6e, 0x65, 0x79, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x22, + 0x47, 0x0a, 0x15, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x42, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, + 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, + 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x44, + 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, 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, + 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, 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, 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, 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, + 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, + 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, } var ( @@ -856,7 +956,7 @@ func file_payments_proto_rawDescGZIP() []byte { return file_payments_proto_rawDescData } -var file_payments_proto_msgTypes = make([]protoimpl.MessageInfo, 16) +var file_payments_proto_msgTypes = make([]protoimpl.MessageInfo, 18) var file_payments_proto_goTypes = []any{ (*GetDailyLikeBalanceRequest)(nil), // 0: payments.GetDailyLikeBalanceRequest (*GetDailyLikeBalanceResponse)(nil), // 1: payments.GetDailyLikeBalanceResponse @@ -874,6 +974,8 @@ var file_payments_proto_goTypes = []any{ (*ChangePurchasedLikesBalanceResponse)(nil), // 13: payments.ChangePurchasedLikesBalanceResponse (*GetAllBalanceRequest)(nil), // 14: payments.GetAllBalanceRequest (*GetAllBalanceResponse)(nil), // 15: payments.GetAllBalanceResponse + (*CreateBalancesRequest)(nil), // 16: payments.CreateBalancesRequest + (*CreateBalancesResponse)(nil), // 17: payments.CreateBalancesResponse } var file_payments_proto_depIdxs = []int32{ 0, // 0: payments.Payment.GetDailyLikeBalance:input_type -> payments.GetDailyLikeBalanceRequest @@ -884,16 +986,18 @@ var file_payments_proto_depIdxs = []int32{ 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 - 1, // 8: payments.Payment.GetDailyLikeBalance:output_type -> payments.GetDailyLikeBalanceResponse - 3, // 9: payments.Payment.GetPurchasedLikeBalance:output_type -> payments.GetPurchasedLikeBalanceResponse - 5, // 10: payments.Payment.GetBalance:output_type -> payments.GetBalanceResponse - 7, // 11: payments.Payment.RefreshDailyLikeBalance:output_type -> payments.RefreshDailyLikeBalanceResponse - 9, // 12: payments.Payment.ChangeBalance:output_type -> payments.ChangeBalanceResponse - 11, // 13: payments.Payment.CheckAndSpendLike:output_type -> payments.CheckAndSpendLikeResponse - 13, // 14: payments.Payment.ChangePurchasedLikesBalance:output_type -> payments.ChangePurchasedLikesBalanceResponse - 15, // 15: payments.Payment.GetAllBalance:output_type -> payments.GetAllBalanceResponse - 8, // [8:16] is the sub-list for method output_type - 0, // [0:8] is the sub-list for method input_type + 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 @@ -910,7 +1014,7 @@ func file_payments_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_payments_proto_rawDesc, NumEnums: 0, - NumMessages: 16, + NumMessages: 18, 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 06ac65d..a3845fa 100644 --- a/internal/pkg/payments/delivery/grpc/gen/payments_grpc.pb.go +++ b/internal/pkg/payments/delivery/grpc/gen/payments_grpc.pb.go @@ -27,6 +27,7 @@ const ( Payment_CheckAndSpendLike_FullMethodName = "/payments.Payment/CheckAndSpendLike" Payment_ChangePurchasedLikesBalance_FullMethodName = "/payments.Payment/ChangePurchasedLikesBalance" Payment_GetAllBalance_FullMethodName = "/payments.Payment/GetAllBalance" + Payment_CreateBalances_FullMethodName = "/payments.Payment/CreateBalances" ) // PaymentClient is the client API for Payment service. @@ -41,6 +42,7 @@ type PaymentClient interface { CheckAndSpendLike(ctx context.Context, in *CheckAndSpendLikeRequest, opts ...grpc.CallOption) (*CheckAndSpendLikeResponse, error) 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) } type paymentClient struct { @@ -131,6 +133,16 @@ func (c *paymentClient) GetAllBalance(ctx context.Context, in *GetAllBalanceRequ return out, nil } +func (c *paymentClient) CreateBalances(ctx context.Context, in *CreateBalancesRequest, opts ...grpc.CallOption) (*CreateBalancesResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(CreateBalancesResponse) + err := c.cc.Invoke(ctx, Payment_CreateBalances_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. @@ -143,6 +155,7 @@ type PaymentServer interface { CheckAndSpendLike(context.Context, *CheckAndSpendLikeRequest) (*CheckAndSpendLikeResponse, error) ChangePurchasedLikesBalance(context.Context, *ChangePurchasedLikesBalanceRequest) (*ChangePurchasedLikesBalanceResponse, error) GetAllBalance(context.Context, *GetAllBalanceRequest) (*GetAllBalanceResponse, error) + CreateBalances(context.Context, *CreateBalancesRequest) (*CreateBalancesResponse, error) mustEmbedUnimplementedPaymentServer() } @@ -177,6 +190,9 @@ func (UnimplementedPaymentServer) ChangePurchasedLikesBalance(context.Context, * func (UnimplementedPaymentServer) GetAllBalance(context.Context, *GetAllBalanceRequest) (*GetAllBalanceResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetAllBalance not implemented") } +func (UnimplementedPaymentServer) CreateBalances(context.Context, *CreateBalancesRequest) (*CreateBalancesResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreateBalances not implemented") +} func (UnimplementedPaymentServer) mustEmbedUnimplementedPaymentServer() {} func (UnimplementedPaymentServer) testEmbeddedByValue() {} @@ -342,6 +358,24 @@ func _Payment_GetAllBalance_Handler(srv interface{}, ctx context.Context, dec fu return interceptor(ctx, in, info, handler) } +func _Payment_CreateBalances_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateBalancesRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PaymentServer).CreateBalances(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Payment_CreateBalances_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PaymentServer).CreateBalances(ctx, req.(*CreateBalancesRequest)) + } + 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) @@ -381,6 +415,10 @@ var Payment_ServiceDesc = grpc.ServiceDesc{ MethodName: "GetAllBalance", Handler: _Payment_GetAllBalance_Handler, }, + { + MethodName: "CreateBalances", + Handler: _Payment_CreateBalances_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 c660bbe..b880ae1 100644 --- a/internal/pkg/payments/delivery/grpc/handlers.go +++ b/internal/pkg/payments/delivery/grpc/handlers.go @@ -16,6 +16,9 @@ type UseCase interface { ChangeBalance(ctx context.Context, userID int, amount int) error ChangeDailyLikeCount(ctx context.Context, userID int, amount int) error ChangePurchasedLikeCount(ctx context.Context, userID int, amount int) error + 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 } type GRPCHandler struct { @@ -163,3 +166,23 @@ func (h *GRPCHandler) GetAllBalance(ctx context.Context, } return response, nil } + +func (h *GRPCHandler) CreateBalances(ctx context.Context, + in *generatedPayments.CreateBalancesRequest) (*generatedPayments.CreateBalancesResponse, error) { + userID := int(in.UserID) + amount := int(in.Amount) + + err := h.uc.AddBalance(ctx, userID, amount) + if err != nil { + return nil, fmt.Errorf("bad add balance error: %w", err) + } + err = h.uc.AddDailyLikesCount(ctx, userID, amount) + if err != nil { + return nil, fmt.Errorf("bad daily likes count error: %w", err) + } + err = h.uc.AddPurchasedLikesCount(ctx, userID, amount) + if err != nil { + return nil, fmt.Errorf("bad purchase count error: %w", err) + } + return &generatedPayments.CreateBalancesResponse{}, nil +} diff --git a/proto/payments.proto b/proto/payments.proto index 4ba2cdd..cb7555f 100644 --- a/proto/payments.proto +++ b/proto/payments.proto @@ -11,6 +11,7 @@ service Payment { rpc CheckAndSpendLike(CheckAndSpendLikeRequest) returns (CheckAndSpendLikeResponse); rpc ChangePurchasedLikesBalance(ChangePurchasedLikesBalanceRequest) returns (ChangePurchasedLikesBalanceResponse); rpc GetAllBalance(GetAllBalanceRequest) returns (GetAllBalanceResponse); + rpc CreateBalances(CreateBalancesRequest) returns (CreateBalancesResponse); } message GetDailyLikeBalanceRequest { @@ -68,4 +69,12 @@ message GetAllBalanceResponse { int32 DailyLikeBalance = 1; int32 PurchasedLikeBalance = 2; int32 MoneyBalance = 3; +} + +message CreateBalancesRequest { + int32 UserID = 1; + int32 Amount = 2; +} + +message CreateBalancesResponse { } \ No newline at end of file