Skip to content

Commit

Permalink
fix: paying to themself
Browse files Browse the repository at this point in the history
  • Loading branch information
ImSoZRious committed Oct 28, 2023
1 parent 35b12d7 commit 1089482
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions internal/wallet/wallet.grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ func (s *walletServiceImpl) Pay(ctx context.Context, request *v1.PayRequest) (*v
return nil, status.Error(codes.FailedPrecondition, "not enough money")
}


receiverId := request.ReceiverId
if payer.ID.String() == receiverId {
return nil, status.Error(codes.FailedPrecondition, "you cannot pay to yourself")
}
receiver, err := s.userRepo.FindUserById(ctx, receiverId)
if err != nil {
return nil, status.Error(codes.NotFound, "receiver not found")
Expand Down Expand Up @@ -270,15 +274,19 @@ func (s *walletServiceImpl) PayPleasePay(ctx context.Context, request *v1.PayPle
return nil, err
}

if float32(payer.Money) < float32(pleasePay.Amount) {
return nil, status.Error(codes.FailedPrecondition, "not enough money")
}

receiver, err := pleasePay.QueryReceiver().First(ctx)
if err != nil {
return nil, status.Error(codes.NotFound, "receiver not found")
}

if payer.ID == receiver.ID {
return nil, status.Error(codes.FailedPrecondition, "you cannot pay to yourself")
}

if float32(payer.Money) < float32(pleasePay.Amount) {
return nil, status.Error(codes.FailedPrecondition, "not enough money")
}

amount := pleasePay.Amount

tx, err := s.client.Tx(ctx)
Expand Down

0 comments on commit 1089482

Please sign in to comment.