-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
228 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package factory | ||
|
||
import ( | ||
"github.com/jinzhu/gorm" | ||
"github.com/santosant/codepix/application/usecase" | ||
"github.com/santosant/codepix/infrastructure/repository" | ||
) | ||
|
||
func TransactionUseCaseFactory(database *gorm.DB) usecase.TransactionUseCase { | ||
pixRepository := repository.PixKeyRepositoryDb{Db: database} | ||
transactionRepository := repository.TransactionRepositoryDb{Db: database} | ||
|
||
transactionUseCase := usecase.TransactionUseCase{ | ||
TransactionRepository: &transactionRepository, | ||
PixRepository: &pixRepository, | ||
} | ||
|
||
return transactionUseCase | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package model | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/go-playground/validator/v10" | ||
"github.com/google/martian/log" | ||
) | ||
|
||
type Transaction struct { | ||
ID string `json:"id" validate:"required,uuid4"` | ||
AccountID string `json:"accountId" validate:"required,uuid4"` | ||
Amount float64 `json:"amount" validate:"required,numeric"` | ||
PixKeyTo string `json:"pixKeyTo" validate:"required"` | ||
PixKeyKindTo string `json:"pixKeyKindTo" validate:"required"` | ||
Description string `json:"description" validate:"required"` | ||
Status string `json:"status" validate:"-"` | ||
Error string `json:"error"` | ||
} | ||
|
||
func (t *Transaction) isValid() error { | ||
v := validator.New() | ||
err := v.Struct(t) | ||
if err != nil { | ||
log.Errorf("error during Transaction validation: %s", err.Error()) | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (t *Transaction) ParseJson(data []byte) error { | ||
err := json.Unmarshal(data, t) | ||
if err != nil { | ||
return err | ||
} | ||
err = t.isValid() | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (t *Transaction) ToJson() ([]byte, error) { | ||
err := t.isValid() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
result, err := json.Marshal(t) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return result, nil | ||
} | ||
|
||
func NewTransction() *Transaction { | ||
return &Transaction{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package cmd | ||
|
||
import ( | ||
ckafka "github.com/confluentinc/confluent-kafka-go/kafka" | ||
"github.com/santosant/codepix/application/grpc" | ||
"github.com/santosant/codepix/application/kafka" | ||
"github.com/santosant/codepix/infrastructure/db" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
gRPCPortNumber int | ||
) | ||
|
||
// allCmd represents the all command | ||
var allCmd = &cobra.Command{ | ||
Use: "all", | ||
Short: "Run gRPC and Kafka Consumer", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
database := db.ConnectDB(os.Getenv("env")) | ||
go grpc.StartGrpcServer(database, portNumber) | ||
|
||
deliveryChan := make(chan ckafka.Event) | ||
producer := kafka.NewKafkaProducer() | ||
|
||
go kafka.DeliveryReport(deliveryChan) | ||
KafkaProcessor := kafka.NewKafkaProcessor(database, producer, deliveryChan) | ||
KafkaProcessor.Consume() | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(allCmd) | ||
allCmd.Flags().IntVarP(&gRPCPortNumber, "grpc-port", "p", 50051, "gRPC Port") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters