Skip to content

Commit

Permalink
Merge pull request #318 from flickmatch/pass-fix
Browse files Browse the repository at this point in the history
Add credits to the events.
  • Loading branch information
abhimanyu-fm authored Oct 13, 2024
2 parents 3e03559 + aa9d863 commit bd49c92
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,21 @@ public static class EventDetails {
String venueLocationLink;
List<PlayerDetails> playerDetailsList;
String stripePaymentUrl;
Double credits;

String currency;
//TODO:Add status attribute


@DynamoDBAttribute(attributeName = "credits")
public Double getCredits() {
return credits;
}

public void setCredits(Double credits) {
this.credits = credits;
}

@DynamoDBAttribute(attributeName = "currency")
public String getCurrency() {
return currency;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void setPassId(String passId) {

private String passType;

private Integer totalGames;
private Double totalGames;

// private Integer payForGames;

Expand All @@ -56,6 +56,7 @@ public void setPassId(String passId) {
private List<String> features;
private String description;


public List<String> getFeatures() {
return features;
}
Expand All @@ -72,6 +73,14 @@ public void setPassType(String passType) {
this.passType = passType;
}

public Double getTotalGames() {
return totalGames;
}

public void setTotalGames(Double totalGames) {
this.totalGames = totalGames;
}

public String getDescription() {
return passType;
}
Expand All @@ -80,21 +89,6 @@ public void setDescription(String description) {
this.description = description;
}

// public Integer getPayForGames() {
// return payForGames;
// }
//
// public void setPayForGames(Integer payForGames) {
// this.payForGames = payForGames;
// }

public Integer getTotalGames() {
return totalGames;
}

public void setTotalGames(Integer totalGames) {
this.totalGames = totalGames;
}

public Integer getTotalDays() {
return totalDays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void setSubscriptionId(String subscriptionId) {

private String passId;

private Integer gamesLeft;
private Double gamesLeft;

private String expiryDate;
private String cityId;
Expand All @@ -61,11 +61,11 @@ public void setPassId(String passId) {
this.passId = passId;
}

public Integer getGamesLeft() {
public Double getGamesLeft() {
return gamesLeft;
}

public void setGamesLeft(Integer gamesLeft) {
public void setGamesLeft(Double gamesLeft) {
this.gamesLeft = gamesLeft;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ private ParsedUniqueEventId parseUniqueEventId(final String uniqueEventId) {
}

private Event.EventDetails buildEventDetails(CreateEventInput input, int index) throws ParseException {
// System.out.println(input.getCredits());
List<SportsVenue> sportsVenueList = sportsVenueBuilder.getSportsVenues(input.getCityId());
String currency = getCurrencyForCity(input.getCityId());
Optional<SportsVenue> sportsVenue = sportsVenueList.stream()
Expand All @@ -287,6 +288,7 @@ private Event.EventDetails buildEventDetails(CreateEventInput input, int index)
.venueLocationLink(sportsVenue.get().getGoogleMapsLink())
.playerDetailsList(new ArrayList<>())
.stripePaymentUrl(getPaymentUrlForEvent(sportsVenue.get(), input.getCharges()))
.credits(input.getCredits())
.build();
return eventDetails;
}
Expand Down Expand Up @@ -342,6 +344,7 @@ private com.flickmatch.platform.graphql.type.Event mapEventToGQLType(Event.Event
.waitListPlayers(waitListPlayers)
.waitListPlayersCount(eventDetails.getWaitListPlayersCount())
.stripePaymentUrl(eventDetails.getStripePaymentUrl() + CLIENT_REFERENCE_ID + eventId)
.credits(eventDetails.getCredits())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public MutationResult createSubscription(String email, String passId) {
throw new Exception("The pass with the given passId has either been expired or does not exist");
}
Pass pass = passOpt.get();
Integer gamesLeft=pass.getTotalGames();
Double gamesLeft=pass.getTotalGames();
Integer totalDays=pass.getTotalDays();
LocalDate today = LocalDate.now();
LocalDate expiry = today.plusDays(totalDays);
Expand Down Expand Up @@ -121,7 +121,6 @@ public com.flickmatch.platform.graphql.type.Subscription getActiveSubscription(S
throw new Exception("The user with the given email does not exist");
}
User user = userOpt.get();
// System.out.println(userOpt.get().getName());
if (!user.getHasActiveSubscription()) {
throw new Exception("The user does not have an active subscription");
}
Expand Down Expand Up @@ -161,7 +160,7 @@ com.flickmatch.platform.graphql.type.Subscription mapEventToGQLType(Subscription
.build();
}

public MutationResult updateSubscription(String subscriptionId) {
public MutationResult updateSubscription(String subscriptionId,Double credits) {
try {
Subscription subs = subscriptionRepository.findBySubscriptionId(subscriptionId).get();
String passId = subs.getPassId();
Expand All @@ -181,16 +180,19 @@ public MutationResult updateSubscription(String subscriptionId) {
LocalDate expiryDate = LocalDate.parse(expiryDateString, formatter);
if (today.isAfter(expiryDate)) {
subs.setStatus("Expired");
subs.setGamesLeft(0);
subs.setGamesLeft(0.0);
user.setHasActiveSubscription(false);
throw new Exception("The subscription has already expired! Please try again refreshing the page.");
}
}
else if(type.equals("LimitedGames")) {
Integer totalGamesLeft = subs.getGamesLeft()-1;
if(credits>subs.getGamesLeft()) {
throw new Exception("Game credits are less than the balance. Please pay and book your spot.");
}
Double totalGamesLeft = subs.getGamesLeft()-credits;
// System.out.println("TotalGamesLeft: "+totalGamesLeft);
subs.setGamesLeft(totalGamesLeft);
if(totalGamesLeft==0) {
if(totalGamesLeft<=1.0) {
subs.setStatus("Expired");
subs.setExpiryDate(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
user.setHasActiveSubscription(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.flickmatch.platform.dynamodb.model.Subscription;
import com.flickmatch.platform.graphql.builder.SubscriptionBuilder;
import com.flickmatch.platform.graphql.input.CreateSubscriptionInput;
import com.flickmatch.platform.graphql.input.UpdateSubscriptionInput;
import com.flickmatch.platform.graphql.type.MutationResult;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -26,8 +27,8 @@ public MutationResult createSubscription(@Argument CreateSubscriptionInput input
return subscriptionBuilder.createSubscription(email, passId);
}
@MutationMapping
public MutationResult updateSubscription(@Argument String subscriptionId) {
return subscriptionBuilder.updateSubscription(subscriptionId);
public MutationResult updateSubscription(@Argument UpdateSubscriptionInput input) {
return subscriptionBuilder.updateSubscription(input.getSubscriptionId(),input.getCredits());
}

@QueryMapping
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.flickmatch.platform.graphql.input;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class CreateEventInput {
String cityId;
String startTime;
String endTime;
Double charges;
String sportsVenueId;
Integer reservedPlayersCount;
Integer waitListPlayersCount;
}
package com.flickmatch.platform.graphql.input;

import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
public class CreateEventInput {
String cityId;
String startTime;
String endTime;
Double charges;
String sportsVenueId;
Integer reservedPlayersCount;
Integer waitListPlayersCount;
Double credits;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
@Setter
@Builder
public class UpdateSubscriptionInput {
private String status;
private String subscriptionId;
private String passId;
private String userId;
private Integer gamesLeft;
private String expiryDate;
private Double credits;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ public class Event {
private List<Player> reservedPlayersList;
private List<Player> waitListPlayers;
private String stripePaymentUrl;
private Double credits;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Pass {
private String passId;
private String cityId;
private String passType;
private Integer totalGames;
private Double totalGames;
private Integer totalDays;
private String title;
private Double price;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Subscription {
private String subscriptionId;
private String passId;
private String userId;
private Integer gamesLeft;
private Double gamesLeft;
private String cityId;
private String expiryDate;
}
11 changes: 9 additions & 2 deletions platform/src/main/resources/graphql/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Mutation {
initiateRazorPayment(input: RazorPayInput!): RazorPayOutput!
initiatePassPayment(input: PassPaymentInput!): PassPaymentOutput!
createSubscription(input: CreateSubscriptionInput!): MutationResult!
updateSubscription(subscriptionId: String!): MutationResult!
updateSubscription(input: UpdateSubscriptionInput!): MutationResult!
"""
This is not implemented yet, will be required for P1
"""
Expand All @@ -41,6 +41,7 @@ input CreateEventInput {
sportsVenueId: ID!
reservedPlayersCount: Int!
waitListPlayersCount: Int!
credits: Float
"""
Not required for P0, will be defaulted to FOOTBALL
"""
Expand Down Expand Up @@ -82,6 +83,11 @@ input RazorPayInput {
redirectUrl: String!
}

input UpdateSubscriptionInput {
subscriptionId: String!
credits: Float!
}

input PassPaymentInput {
passId: ID!
email: String!
Expand All @@ -104,7 +110,7 @@ type Subscription {
passId: String!
userId: String!
expiryDate: String!
gamesLeft: Int!
gamesLeft: Float!
status: String!
cityId: String!
}
Expand Down Expand Up @@ -233,6 +239,7 @@ type EVENT {
We need to make this mandatory in future
"""
stripePaymentUrl: String
credits: Float
}

type Player {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void setup() {
ddbPass1.setPassId("1");
ddbPass1.setCityId("1");
ddbPass1.setPassType("LimitedGames");
ddbPass1.setTotalGames(10);
ddbPass1.setTotalGames(10.0);
ddbPass1.setTotalDays(3000);
ddbPass1.setPrice(1000.0);
ddbPass1.setTitle("10 games pass");
Expand All @@ -47,7 +47,7 @@ public void setup() {
ddbPass2.setPassId("2");
ddbPass2.setCityId("2");
ddbPass2.setPassType("LimitedDays");
ddbPass2.setTotalGames(1000);
ddbPass2.setTotalGames(1000.0);
ddbPass2.setTotalDays(30);
ddbPass2.setPrice(1000.0);
ddbPass2.setTitle("30 days pass");
Expand All @@ -57,7 +57,7 @@ public void setup() {
ddbPass2.setPassId("2");
ddbPass2.setCityId("2");
ddbPass2.setPassType("LimitedDays");
ddbPass2.setTotalGames(10000);
ddbPass2.setTotalGames(10000.0);
ddbPass2.setTotalDays(30);
ddbPass2.setPrice(100.0);
ddbPass2.setTitle("30 days pass");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void setup() {
// Sample DynamoDB Pass object
testPass = new Pass();
testPass.setPassId("pass-id");
testPass.setTotalGames(10);
testPass.setTotalGames(10.0);
testPass.setTotalDays(30);

// Sample DynamoDB User object
Expand All @@ -63,7 +63,7 @@ public void setup() {
testSubscription.setSubscriptionId("subscription-id");
testSubscription.setPassId("pass-id");
testSubscription.setUserId("user-id");
testSubscription.setGamesLeft(10);
testSubscription.setGamesLeft(10.0);
testSubscription.setStatus("Active");
testSubscription.setExpiryDate(LocalDate.now().plusDays(30).format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
}
Expand Down

0 comments on commit bd49c92

Please sign in to comment.