-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* sorry * chat is not my good friend * overloaded contract factory with getting a user from database and passing in a user
- Loading branch information
1 parent
dc1e8dc
commit 60ad0a0
Showing
9 changed files
with
122 additions
and
180 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.appdev.allin.data; | ||
import com.appdev.allin.contract.OpposingTeam; | ||
import com.appdev.allin.contract.Rarity; | ||
import com.appdev.allin.user.User; | ||
import com.appdev.allin.player.Player; | ||
import com.appdev.allin.contract.Contract; | ||
import com.appdev.allin.contract.Event; | ||
import com.appdev.allin.data.PlayerFactory; | ||
import com.appdev.allin.user.UserRepo; | ||
import com.appdev.allin.user.UserService; | ||
import com.github.javafaker.Faker; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
import java.util.Random; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
//needs tests | ||
public class ContractFactory { | ||
private static final Faker faker = new Faker(); | ||
private final Random random = new Random(); | ||
|
||
private static final PlayerFactory playerFactory = new PlayerFactory(); | ||
|
||
private final UserFactory userFactory = new UserFactory(); | ||
|
||
@Autowired UserService userService; | ||
|
||
|
||
|
||
|
||
public Contract createRandomContract(User owner) { | ||
Player player = playerFactory.createFakePlayer(); | ||
Double buyPrice = faker.number().randomDouble(2, 100, 5000); // Random buy price between 100 and 5000 | ||
Rarity rarity = Rarity.getRandomRarity(); // Random rarity | ||
OpposingTeam opposingTeam = OpposingTeam.getRandomOpposingTeam(); | ||
String opposingTeamImage = faker.internet().avatar(); // Random image URL | ||
Event event = Event.getRandomEvent(); | ||
Integer eventThreshold = faker.number().numberBetween(1, 100); // Random event threshold between 1 and 100 | ||
LocalDate creationTime = LocalDate.now().minusDays(faker.number().numberBetween(1, 365)); // Within the past year | ||
Double value = faker.number().randomDouble(2, 100, 5000); // Random value between 100 and 5000 | ||
Boolean expired = faker.bool().bool(); | ||
Boolean forSale = faker.bool().bool(); | ||
Double sellPrice = forSale ? faker.number().randomDouble(2, 100, 5000) : null; // If for sale, random sell price | ||
|
||
return new Contract(player, owner, buyPrice, rarity, opposingTeam, opposingTeamImage, event, eventThreshold, | ||
creationTime, value, expired, forSale, sellPrice); | ||
} | ||
public Contract createRandomContract() throws Exception { | ||
Player player = playerFactory.createFakePlayer(); | ||
List<User> users = userService.getAllUsers(); | ||
User owner; | ||
if (users.isEmpty()){ | ||
throw new Exception("No initialized users!"); | ||
}else{ | ||
owner = users.get(0); | ||
} | ||
Double buyPrice = faker.number().randomDouble(2, 100, 5000); // Random buy price between 100 and 5000 | ||
Rarity rarity = Rarity.getRandomRarity(); // Random rarity | ||
OpposingTeam opposingTeam = OpposingTeam.getRandomOpposingTeam(); | ||
String opposingTeamImage = faker.internet().avatar(); // Random image URL | ||
Event event = Event.getRandomEvent(); | ||
Integer eventThreshold = faker.number().numberBetween(1, 100); // Random event threshold between 1 and 100 | ||
LocalDate creationTime = LocalDate.now().minusDays(faker.number().numberBetween(1, 365)); // Within the past year | ||
Double value = faker.number().randomDouble(2, 100, 5000); // Random value between 100 and 5000 | ||
Boolean expired = faker.bool().bool(); | ||
Boolean forSale = faker.bool().bool(); | ||
Double sellPrice = forSale ? faker.number().randomDouble(2, 100, 5000) : null; // If for sale, random sell price | ||
|
||
return new Contract(player, owner, buyPrice, rarity, opposingTeam, opposingTeamImage, event, eventThreshold, | ||
creationTime, value, expired, forSale, sellPrice); | ||
} | ||
} | ||
|
8 changes: 4 additions & 4 deletions
8
...example/allin/data/PlayerDataFactory.java → .../appdev/allin/data/PlayerDataFactory.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
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,34 +1,41 @@ | ||
package com.appdev.allin.data; | ||
|
||
import com.appdev.allin.player.Player; | ||
import com.appdev.allin.player.Position; | ||
import com.github.javafaker.Faker; | ||
import java.util.Random; | ||
|
||
|
||
public class PlayerFactory { | ||
private static final Faker faker = new Faker(); | ||
private static final Random random = new Random(); | ||
|
||
public static Player fakeTemplate() { | ||
return new Player( | ||
"LeBron", | ||
"James", | ||
new Position[] {Position.Center}, | ||
23, | ||
"6'9", | ||
250, | ||
"Akron, OH", | ||
"St. Vincent-St. Mary", | ||
"src/main/resources/static/images/players/default.jpg"); | ||
} | ||
|
||
public static Player fake() { | ||
// return a player with random values | ||
return new Player( | ||
"LeBron", | ||
"James", | ||
new Position[] {Position.Center}, | ||
23, | ||
"6'9", | ||
250, | ||
"Akron, OH", | ||
"St. Vincent-St. Mary", | ||
"src/main/resources/static/images/players/default.jpg"); | ||
public static Player createFakePlayer() { | ||
String firstName = faker.name().firstName(); | ||
String lastName = faker.name().lastName(); | ||
Position[] positions = generateRandomPositions(); | ||
Integer number = faker.number().numberBetween(1, 99); // Jersey numbers typically range from 1-99 | ||
String height = generateRandomHeight(); | ||
Integer weight = faker.number().numberBetween(150, 250); // Weight in pounds, adjustable as needed | ||
String hometown = faker.address().city() + ", " + faker.address().state(); | ||
String highSchool = faker.educator().secondarySchool(); | ||
return new Player(firstName, lastName, positions, number, height, weight, hometown, highSchool); | ||
} | ||
|
||
private static Position[] generateRandomPositions() { | ||
Position[] allPositions = Position.values(); | ||
int count = random.nextInt(2) + 1; // Players can have 1 or 2 positions | ||
Position[] positions = new Position[count]; | ||
for (int i = 0; i < count; i++) { | ||
positions[i] = allPositions[random.nextInt(allPositions.length)]; | ||
} | ||
return positions; | ||
} | ||
|
||
private static String generateRandomHeight() { | ||
int feet = faker.number().numberBetween(5, 7); // Heights between 5 and 7 feet | ||
int inches = faker.number().numberBetween(0, 11); | ||
return feet + "'" + inches + "\""; | ||
} | ||
|
||
} |
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
4 changes: 2 additions & 2 deletions
4
...a/com/example/allin/data/UserFactory.java → ...va/com/appdev/allin/data/UserFactory.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
60 changes: 0 additions & 60 deletions
60
src/test/java/com/example/allin/AllInApplicationTests.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.