Skip to content

Commit

Permalink
Phone number getting saved in users db.
Browse files Browse the repository at this point in the history
  • Loading branch information
sam5102 committed Sep 1, 2024
1 parent 9203110 commit 47b6b3d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ public RazorPaymentRequest createPaymentRequest(final String orderId,
.waNumber(playerInput.getWaNumber())
.build())
.collect(Collectors.toList());

logger.info("This is an info message");
// Create or update the user with the provided phone number
CreateUserInput createUserInput = CreateUserInput.builder()
.email(email) // Assuming email is used to identify the user
.email(email) // Assuming you have the email from the payment request
.phoneNumber(phoneNumber)
.build();
userBuilder.createUser(createUserInput);

// System.out.println(orderId + " " + uniqueEventId + " " + " " + date + " " + location + " " + gameNumber + " " +email);
RazorPaymentRequest razorPaymentRequest = RazorPaymentRequest.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,46 @@
@Service

public class UserBuilder {
private UserRepository userRepository;
private final UserRepository userRepository;

public UserBuilder(UserRepository userRepository) {
this.userRepository = userRepository;
}

public User createUser(CreateUserInput input) {
// Checking if the user already exists
Optional<User> existingUser = userRepository.findByEmail(input.getEmail());
if(existingUser.isPresent()) {
return existingUser.get();
Optional<User> existingUserOptional = userRepository.findByEmail(input.getEmail());
User user;

if(existingUserOptional.isPresent()) {
// User already exists, update the phone number
user = existingUserOptional.get();
user.setPhoneNumber(input.getPhoneNumber());
log.info("User already exists, updating phone number for user: {}", user);
return userRepository.save(user);
} else {
// Create a new User object
user = new User();
user.setEmail(input.getEmail());
user.setName(input.getName());
user.setPhoneNumber(input.getPhoneNumber());
log.info("Creating a new user: {}", user);
}
// Create a new User object
User newUser = new User();
newUser.setEmail(input.getEmail());
newUser.setName(input.getName());
newUser.setPhoneNumber(input.getPhoneNumber());


try {
// Save the new user to the repository
userRepository.save(newUser);
log.info("User created successfully: {}", newUser);
return newUser;
// Save the user (new or updated) to the repository
userRepository.save(user);
log.info("User saved successfully: {}", user);
return user;
} catch (Exception e) {
log.error("Error creating user: {}", e.getMessage());
log.error("Error saving user: {}", e.getMessage());
throw e;
}

}

public List<User> getAllUsers() {
return userRepository.findAll();
}






}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public RazorPayOutput initiateRazorPayment(@Argument RazorPayInput input) {
String phoneNumber = input.getPhoneNumber();

// Log the phone number before creating the payment request
log.debug("Phone number to be saved: {}", phoneNumber);
log.info("Phone number to be saved: {}", phoneNumber);

razorPaymentRequestBuilder.createPaymentRequest(orderId,
input.getUniqueEventId(), input.getPlayerInputList(), dateString, location, gameNumber,email, phoneNumber);
Expand Down
1 change: 1 addition & 0 deletions platform/src/main/resources/graphql/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ input RazorPayInput {
playerInputList: [PlayerInput!]!
currency: String!
email: String!
phoneNumber: String!
}

type Pass {
Expand Down

0 comments on commit 47b6b3d

Please sign in to comment.