-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
302 additions
and
112 deletions.
There are no files selected for viewing
88 changes: 0 additions & 88 deletions
88
...s-web-service/src/main/java/flyinghigh/services/accounts/domain/FrequentFlyerAccount.java
This file was deleted.
Oops, something went wrong.
142 changes: 142 additions & 0 deletions
142
...ts-web-service/src/main/java/flyinghigh/services/accounts/domain/FrequentFlyerMember.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
package flyinghigh.services.accounts.domain; | ||
|
||
import org.springframework.data.annotation.Id; | ||
|
||
import java.lang.String; | ||
|
||
public class FrequentFlyerMember { | ||
@Id | ||
private String id; | ||
private String accountNumber; | ||
private String firstName; | ||
private String lastName; | ||
private String homeAirportCode; | ||
private int statusPoints; | ||
private Status status = Status.Bronze; | ||
|
||
public FrequentFlyerMember() { | ||
} | ||
|
||
public FrequentFlyerMember(String id, | ||
String accountNumber, | ||
String firstName, | ||
String lastName) { | ||
this.id = id; | ||
this.accountNumber = accountNumber; | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
this.statusPoints = 0; | ||
} | ||
|
||
protected FrequentFlyerMember(String id, | ||
String accountNumber, | ||
String firstName, | ||
String lastName, | ||
String homeAirportCode, | ||
int statusPoints, | ||
Status status) { | ||
this.id = id; | ||
this.accountNumber = accountNumber; | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
this.homeAirportCode = homeAirportCode; | ||
this.statusPoints = statusPoints; | ||
this.status = status; | ||
} | ||
|
||
public FrequentFlyerMember(String accountNumber, String firstName, String lastName) { | ||
this.accountNumber = accountNumber; | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
this.statusPoints = 0; | ||
} | ||
|
||
public FrequentFlyerMember(String accountNumber, String firstName, String lastName, int statusPoints, String homeAirportCode) { | ||
this.accountNumber = accountNumber; | ||
this.firstName = firstName; | ||
this.lastName = lastName; | ||
this.statusPoints = statusPoints; | ||
this.homeAirportCode = homeAirportCode; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public int getStatusPoints() { | ||
return statusPoints; | ||
} | ||
|
||
protected void setStatusPoints(int statusPoints) { | ||
this.statusPoints = statusPoints; | ||
} | ||
|
||
protected void setStatus(Status status) { | ||
this.status = status; | ||
} | ||
|
||
public String getAccountNumber() { | ||
return accountNumber; | ||
} | ||
|
||
public java.lang.String getLastName() { | ||
return lastName; | ||
} | ||
|
||
public String getFirstName() { | ||
return firstName; | ||
} | ||
|
||
public String getHomeAirportCode() { | ||
return homeAirportCode; | ||
} | ||
|
||
public Status getStatus() { | ||
return status; | ||
} | ||
|
||
public FrequentFlyerMember withStatusPoints(int statusPoints) { | ||
return new FrequentFlyerMember(id, accountNumber, firstName, lastName, homeAirportCode, statusPoints, status); | ||
} | ||
public FrequentFlyerMember withStatus(Status status) { | ||
return new FrequentFlyerMember(id, accountNumber, firstName, lastName, homeAirportCode, statusPoints, status); | ||
} | ||
|
||
public Earner earns(int amount) { | ||
return new Earner(amount, this); | ||
} | ||
|
||
public static class Earner { | ||
private final int amount; | ||
|
||
private final FrequentFlyerMember account; | ||
|
||
public Earner(int amount, FrequentFlyerMember account) { | ||
this.amount = amount; | ||
this.account = account; | ||
} | ||
|
||
public void statusPoints() { | ||
account.setStatusPoints(account.getStatusPoints() + amount); | ||
account.setStatus(Status.statusLevelFor(account.getStatusPoints())); | ||
} | ||
} | ||
|
||
|
||
public static FrequentFlyerBuilder withFrequentFlyerNumber(String frequentFlyerNumber) { | ||
return new FrequentFlyerBuilder(frequentFlyerNumber); | ||
} | ||
|
||
public static class FrequentFlyerBuilder { | ||
|
||
private String frequentFlyerNumber; | ||
|
||
public FrequentFlyerBuilder(String frequentFlyerNumber) { | ||
this.frequentFlyerNumber = frequentFlyerNumber; | ||
} | ||
|
||
public FrequentFlyerMember named(String firstName, String lastName) { | ||
return new FrequentFlyerMember(frequentFlyerNumber, firstName, lastName); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
accounts-web-service/src/main/java/flyinghigh/services/accounts/domain/Status.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package flyinghigh.services.accounts.domain; | ||
|
||
import java.util.Arrays; | ||
import java.util.Optional; | ||
|
||
public enum Status { | ||
|
||
Bronze(0), Silver(300), Gold(700), Platinum(1500); | ||
|
||
private final int minimumPoints; | ||
|
||
Status(int minimumPoints) { | ||
this.minimumPoints = minimumPoints; | ||
} | ||
|
||
public static Status statusLevelFor(int points) { | ||
Optional<Status> matchingStatus = | ||
Arrays.asList(Status.values()) | ||
.stream() | ||
.sorted(Status::decendingMinimumPoints) | ||
.filter(status -> points >= status.getMinimumPoints()) | ||
.findFirst(); | ||
|
||
return matchingStatus.orElse(Bronze); | ||
} | ||
|
||
public int getMinimumPoints() { | ||
return minimumPoints; | ||
} | ||
|
||
private static int decendingMinimumPoints(Status status1, Status status2) { | ||
return status2.getMinimumPoints() - status1.getMinimumPoints(); | ||
} | ||
|
||
|
||
} |
8 changes: 3 additions & 5 deletions
8
...eb-service/src/main/java/flyinghigh/services/accounts/repositories/AccountRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
package flyinghigh.services.accounts.repositories; | ||
|
||
import flyinghigh.services.accounts.domain.FrequentFlyerAccount; | ||
import flyinghigh.services.accounts.domain.FrequentFlyerMember; | ||
import org.springframework.data.mongodb.repository.MongoRepository; | ||
import org.springframework.data.repository.query.Param; | ||
import org.springframework.data.rest.core.annotation.RepositoryRestResource; | ||
|
||
import java.util.List; | ||
|
||
@RepositoryRestResource(collectionResourceRel = "accounts", path = "accounts") | ||
public interface AccountRepository extends MongoRepository<FrequentFlyerAccount, String> { | ||
FrequentFlyerAccount findByAccountNumber(@Param("number") String number); | ||
public interface AccountRepository extends MongoRepository<FrequentFlyerMember, String> { | ||
FrequentFlyerMember findByAccountNumber(@Param("number") String number); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...eb-service/src/test/groovy/flyinghigh/services/flights/domain/WhenManagingAccounts.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.