Skip to content

Commit

Permalink
Merge pull request #297 from flickmatch/fixing-addingPlayer
Browse files Browse the repository at this point in the history
adding phonenumber to user database
  • Loading branch information
abhimanyu-fm authored Sep 11, 2024
2 parents 491162d + 68f1d97 commit 064a1a3
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public class RazorPaymentRequest {
private String gameNumber;
private String email;

private String phoneNumber;


@DynamoDBHashKey(attributeName="orderId")
public String getOrderId() {
Expand Down Expand Up @@ -64,6 +66,16 @@ public void setStatus(String status) {
this.status = status;
}

// Getter and Setter for phoneNumber
@DynamoDBAttribute(attributeName="phoneNumber")
public String getPhoneNumber() {
return phoneNumber;
}

public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}

@DynamoDBAttribute(attributeName="date")
public String getDate() {
return date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import com.flickmatch.platform.graphql.input.PlayerInput;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import lombok.extern.log4j.Log4j2;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@Service
@Log4j2
public class PaymentRequestBuilder {

@Autowired
Expand All @@ -26,6 +27,8 @@ public PaymentRequest createPaymentRequest(final String merchantTransactionId,
.waNumber(playerInput.getWaNumber())
.build())
.collect(Collectors.toList());
log.info("Razorpay Merchant Transaction Id", merchantTransactionId);
log.info("Players Joined", playerInputList);
PaymentRequest paymentRequest = PaymentRequest.builder()
.merchantTransactionId(merchantTransactionId)
.uniqueEventId(uniqueEventId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.flickmatch.platform.dynamodb.repository.RazorPaymentRequestRepository;
import com.flickmatch.platform.graphql.input.PlayerInput;
import com.flickmatch.platform.graphql.input.RazorPayInput;
import com.flickmatch.platform.dynamodb.model.User;
import com.flickmatch.platform.graphql.input.CreateUserInput;
import com.razorpay.Order;
import com.razorpay.RazorpayClient;
import com.razorpay.RazorpayException;
Expand All @@ -23,12 +25,16 @@
@Service
@Log4j2
public class RazorPaymentRequestBuilder {
@Autowired

@Autowired
RazorPaymentRequestRepository razorPaymentRequestRepository;

@Autowired
private UserBuilder userBuilder; // Inject UserBuilder

public String createOrderRequest(RazorpayClient razorpayClient, RazorPayInput input, EventBuilder eventBuilder,long amount) throws RazorpayException {
JSONObject orderRequest = new JSONObject();
String[] parts =input.getUniqueEventId().split("-");
String[] parts = input.getUniqueEventId().split("-");
String cityId = parts[0];
String currency = input.getCurrency();
orderRequest.put("amount", amount);
Expand All @@ -42,13 +48,23 @@ public RazorPaymentRequest createPaymentRequest(final String orderId,
final String date,
final String location,
final String gameNumber,
final String email) {
final String email,
final String phoneNumber) {

List<Event.PlayerDetails> playerDetailsList = playerInputList.stream()
.map(playerInput -> Event.PlayerDetails.builder()
.name(playerInput.getName())
.waNumber(playerInput.getWaNumber())
.build())
.collect(Collectors.toList());

// Create or update the user with the provided phone number
CreateUserInput createUserInput = CreateUserInput.builder()
.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()
.orderId(orderId)
Expand All @@ -59,6 +75,7 @@ public RazorPaymentRequest createPaymentRequest(final String orderId,
.location(location)
.gameNumber(gameNumber)
.email(email)
.phoneNumber(phoneNumber)
.build();
return razorPaymentRequestRepository.save(razorPaymentRequest);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,52 @@
@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();
}
// Create a new User object
User newUser = new User();
newUser.setEmail(input.getEmail());
newUser.setName(input.getName());
newUser.setPhoneNumber(input.getPhoneNumber());
newUser.setHasActiveSubscription(false);
newUser.setSubscriptionHistory(new ArrayList<>());

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());
user.setHasActiveSubscription(false);
user.setSubscriptionHistory(new ArrayList<>());
log.info("Creating a new user: {}", user);
}

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();
}


public void createUserSubscription(String email,String passId,String subscriptionId) {
try {
// Find the existing user by email
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,14 @@ public RazorPayOutput initiateRazorPayment(@Argument RazorPayInput input) {
String location = city.getCityName();
String gameNumber = input.getUniqueEventId().split("-")[4];
String email = input.getEmail();
String phoneNumber = input.getPhoneNumber();

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

razorPaymentRequestBuilder.createPaymentRequest(orderId,
input.getUniqueEventId(), input.getPlayerInputList(), dateString, location, gameNumber,email);
input.getUniqueEventId(), input.getPlayerInputList(), dateString, location, gameNumber,email, phoneNumber);
return RazorPayOutput.builder().orderId(orderId).isInitiated(true).amount(amount).build();
} catch (DynamoDBMappingException dbe) {
log.error("DynamoDB mapping error: {}", dbe.getMessage(), dbe);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.flickmatch.platform.graphql.controller;

import com.flickmatch.platform.dynamodb.model.User;
//import com.flickmatch.platform.dynamodb.service.PlayerService;
import com.flickmatch.platform.graphql.builder.UserBuilder;
import com.flickmatch.platform.graphql.input.CreateUserInput;
import com.flickmatch.platform.graphql.type.UserResult;
Expand All @@ -19,6 +20,7 @@ public class UserController {

@Autowired
private UserBuilder userBuilder;
//private PlayerService playerService;

@MutationMapping
public UserResult createUser(@Argument CreateUserInput input) {
Expand All @@ -37,6 +39,11 @@ public UserResult createUser(@Argument CreateUserInput input) {


}

// @DeleteMapping("/{id}")
// public void deletePlayer(@PathVariable Long id) {
// playerService.deletePlayer(id);
// }
@QueryMapping(name="users")
public List<User> getAllUsers() {
return userBuilder.getAllUsers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@ public class RazorPayInput {
List<PlayerInput> playerInputList;
String currency;
String email;
String phoneNumber;

public String getPhoneNumber() {
return phoneNumber;
}

public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
}
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 @@ -77,6 +77,7 @@ input RazorPayInput {
playerInputList: [PlayerInput!]!
currency: String!
email: String!
phoneNumber: String!
}

input PassPaymentInput {
Expand Down
9 changes: 8 additions & 1 deletion react-fm/src/pages/matchQueues/eventsComponents/JoinNow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,14 @@ export const JoinNow: FC<EventDetails> = ({
generateUrl();
} else {
// createOrder('2-2024-07-11-1', objectArray, setAmount, currency || 'INR', email) // to be changed after local testing
createOrder(uniqueEventId, objectArray, setAmount, currency || 'INR', email) // to be changed after local testing
createOrder(
uniqueEventId,
objectArray,
setAmount,
currency || 'INR',
email,
userData.phoneNumber,
) // to be changed after local testing
.then((orderId) => {
setOrderId(orderId);
setOpen(false);
Expand Down
2 changes: 2 additions & 0 deletions react-fm/src/pages/matchQueues/eventsComponents/RazorPay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const createOrder = (
setAmount: React.Dispatch<React.SetStateAction<number>>,
currency: string,
email: string,
phoneNumber: string,
): Promise<string> =>
// fetch('http://localhost:8080/graphql', {
fetch('https://service.flickmatch.in/platform-0.0.1-SNAPSHOT/graphql', {
Expand All @@ -21,6 +22,7 @@ const createOrder = (
.join(',')}],
currency : "${currency}"
email : "${email}"
phoneNumber: "${phoneNumber}"
}
) {
orderId
Expand Down

0 comments on commit 064a1a3

Please sign in to comment.