Skip to content

Create Wallet feature#39

Open
SURABHI2003 wants to merge 3 commits intoVaniThapar:wallet-featurefrom
SURABHI2003:wallet-feature
Open

Create Wallet feature#39
SURABHI2003 wants to merge 3 commits intoVaniThapar:wallet-featurefrom
SURABHI2003:wallet-feature

Conversation

@SURABHI2003
Copy link
Collaborator

Created Wallet feature. Implemented all the methods in all the corresponding layers.

public class Wallet {

private String walletid;
private String Walletid;
Copy link
Collaborator

@NehaKariya0309 NehaKariya0309 Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to keep same naming conventions for a single class. Either small(for now) or camelcase. Might create problems later.

public Wallet getWalletInfo(@PathVariable String userId) throws ControllerException{

@GetMapping("/get-wallet-info/{userId}")
public ResponseEntity<Wallet> getWalletInfo(@PathVariable String userId) throws ControllerException {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can u write the function name getWalletInfoByUserId, like it would help us in future , because there are 2 apis for getting wallet info , one by user id and another by wallet id. It may create confusion later.

Wallet currentWallet = walletService.getWalletById(walletId);

if (currentWallet == null) {
return null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be better if u can log a statement here , "Wallet not found" , would help in debugging.

}
}

@PostMapping("/{walletId}/addAmount")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think api name should have function name followed by {walletId}.

public Wallet getWalletById(String walletId) throws ServiceException{
try {
Wallet wallet = walletRepository.getWalletById(walletId);
User user = walletRepository.getUserIdWithWallet(wallet);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we setting user here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to set user explicitly because when I'm trying to get the wallet info through walletId, I'm getting null instead of user object.

@@ -31,48 +31,80 @@ public class WalletController extends BaseController {
public List<Wallet> getAllWallets() throws ControllerException {
try {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function doc is missing,
This holds true for all the methods.


return walletList;
} catch (Exception e) {
log.error("Error encountered in getting the users");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message should be
log.error("Error encountered in getting the users", e);

try {
return walletService.getWalletInfo(userId);
if (userId == null || userId.isEmpty()) {
return ResponseEntity.badRequest().body(null);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throw exception in case of userId is empty, With exception message.

try {
return walletService.getWalletById(walletId);
if (walletId == null || walletId.isEmpty()) {
return null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throw exception here with message

public ResponseEntity<String> addAmountToWallet(@PathVariable String walletId, @RequestParam Float amount) throws ControllerException {
try {
if (walletId == null || walletId.isEmpty()) {
return ResponseEntity.badRequest().body(null);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its not a badRequest, Throw exception with error message

return sqlQueryBuilder.toString();
}

public static String getUserIdWithWalletQuery(@Param("ex") Wallet ex) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow the proper naming convention.
what ex is denoting here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Query here might return no values.
Please add the proper validation.
Or this can be handled at service layer as well.

} else {
sqlQueryBuilder.append("NULL");
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The below code is not making sense,
Why are we comparing with null;

Instead throw exception when walletId is null

if (walletid == null) {
        throw new IllegalArgumentException("walletid cannot be null");
    }

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add similar exception handling in all the other methods where params are necessary

@NoArgsConstructor
@AllArgsConstructor
public class Wallet {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the wallet have more fields?

Wallet getWalletById(String walletId) throws ServiceException;
Wallet getWalletByWalletId(String walletId) throws ServiceException;

void addAmountToWallet(String walletId, Float amount) throws ServiceException;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can another method be added to deductFromWallet()



@Override
public void generateWallet(String userId) throws ServiceException {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name should be generateWalletForUser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants