Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added credits to the events. #318

Merged
merged 7 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -40,7 +40,7 @@ public void setPassId(String passId) {

private String passType;

private Integer totalGames;
private Double totalGames;

private Integer totalDays;

Expand All @@ -58,11 +58,11 @@ public void setPassType(String passType) {
this.passType = passType;
}

public Integer getTotalGames() {
public Double getTotalGames() {
return totalGames;
}

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

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,15 +180,18 @@ 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);
}
}
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<=.5) {
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 @@ -11,7 +11,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 @@ -81,6 +82,11 @@ input RazorPayInput {
phoneNumber: String!
}

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

input PassPaymentInput {
passId: ID!
email: String!
Expand All @@ -103,7 +109,7 @@ type Subscription {
passId: String!
userId: String!
expiryDate: String!
gamesLeft: Int!
gamesLeft: Float!
status: String!
cityId: String!
}
Expand Down Expand Up @@ -229,6 +235,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
Loading