-
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.
feat: Initialize project with entity classes
- Loading branch information
1 parent
7175604
commit 586b763
Showing
18 changed files
with
359 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea/modules.xml | ||
.idea/jarRepositories.xml | ||
.idea/compiler.xml | ||
.idea/libraries/ | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.example</groupId> | ||
<artifactId>CryptoExchangeSystem</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<maven.compiler.source>21</maven.compiler.source> | ||
<maven.compiler.target>21</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
</project> |
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,33 @@ | ||
package com.globant; | ||
|
||
import com.globant.domain.entities.Account; | ||
import com.globant.domain.entities.Crypto; | ||
import com.globant.domain.entities.Order; | ||
import com.globant.domain.entities.SellOrder; | ||
import com.globant.domain.util.InvalidOrderException; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public class Main { | ||
static int numberId = 10; | ||
public static void main(String[] args) { | ||
// TESTS | ||
Account account = new Account("anthleon", "[email protected]", "12345a6"); | ||
System.out.println("000" + numberId); | ||
System.out.println(account.getAccountId()); | ||
|
||
System.out.println("\n"); | ||
|
||
try { | ||
Crypto crypto = new Crypto("Bitcoin", new BigDecimal(1000)); | ||
Order order = new SellOrder(crypto, new BigDecimal(10), new BigDecimal(2000)); | ||
System.out.println(order); | ||
System.out.println("\n"); | ||
} catch (InvalidOrderException e) { | ||
System.out.println(e.getMessage()); | ||
} | ||
|
||
Crypto crypto1 = new Crypto("Bitcoin", new BigDecimal(1000)); | ||
System.out.println(crypto1.getShorthandSymbol()); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/globant/application/port/out/OrderBook.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,5 @@ | ||
package com.globant.application.port.out; | ||
|
||
public interface OrderBook { | ||
//a | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/globant/application/port/out/WalletRepo.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,15 @@ | ||
package com.globant.application.port.out; | ||
|
||
import com.globant.domain.entities.Crypto; | ||
import com.globant.domain.entities.Transaction; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.List; | ||
|
||
public interface WalletRepo { | ||
BigDecimal getBalance(); | ||
List<Crypto> getCryptocurrencies(); | ||
List<Transaction> getTransactions(); | ||
void updateBalance(); | ||
void addCryptocurrency(); | ||
} |
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,34 @@ | ||
package com.globant.domain.entities; | ||
|
||
import com.globant.domain.util.MakeId; | ||
|
||
import java.util.List; | ||
|
||
public class Account { | ||
static int accountNumberId = 1; | ||
private final String accountId; | ||
protected String username; | ||
protected String email; | ||
protected transient String password; | ||
private List<Transaction> transactions; | ||
|
||
public Account(String username, String email, String password) { | ||
this.username = username; | ||
this.email = email; | ||
this.password = password; | ||
|
||
accountId = MakeId.makeIdNumber(accountNumberId); | ||
} | ||
|
||
public String getAccountId() { | ||
return accountId; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
||
public String getEmail() { | ||
return email; | ||
} | ||
} |
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,28 @@ | ||
package com.globant.domain.entities; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public class BuyOrder extends Order{ | ||
private BigDecimal maximumPrice; | ||
|
||
public BuyOrder(Crypto cryptoType, BigDecimal amount, BigDecimal maximumPrice) { | ||
super(cryptoType, amount); | ||
this.maximumPrice = maximumPrice; | ||
} | ||
|
||
public BigDecimal getMaximumPrice() { | ||
return maximumPrice; | ||
} | ||
|
||
public void setMaximumPrice(BigDecimal maximumPrice) { | ||
this.maximumPrice = maximumPrice; | ||
} | ||
|
||
public String toString() { | ||
return "BuyOrder{" + | ||
"maximumPrice=" + maximumPrice + | ||
", cryptoType=" + this.getCryptoType() + | ||
", amount=" + this.getAmount() + | ||
'}'; | ||
} | ||
} |
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,43 @@ | ||
package com.globant.domain.entities; | ||
|
||
import com.globant.domain.util.MakeId; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public class Crypto { | ||
static int cryptoIdNumber = 1; | ||
private final String cryptoId; | ||
private String shorthandSymbol; | ||
protected String name; | ||
protected BigDecimal price; | ||
|
||
public Crypto(String name, BigDecimal price) { | ||
this.name = name; | ||
this.price = price; | ||
cryptoId = MakeId.makeIdNumber(cryptoIdNumber); | ||
if (name.length() > 3) | ||
this.shorthandSymbol = name.substring(0, 3).toUpperCase(); | ||
else | ||
this.shorthandSymbol = name; | ||
} | ||
public Crypto(String name, BigDecimal price, String shorthandSymbol) { | ||
this(name, price); | ||
this.shorthandSymbol = shorthandSymbol.toUpperCase(); | ||
} | ||
|
||
public String getShorthandSymbol() { | ||
return shorthandSymbol; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public BigDecimal getPrice() { | ||
return price; | ||
} | ||
|
||
public String getCryptoId() { | ||
return cryptoId; | ||
} | ||
} |
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,29 @@ | ||
package com.globant.domain.entities; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public abstract class Order { | ||
private Crypto cryptoType; | ||
private BigDecimal amount; | ||
|
||
public Order(Crypto cryptoType, BigDecimal amount) { | ||
this.cryptoType = cryptoType; | ||
this.amount = amount; | ||
} | ||
|
||
public Crypto getCryptoType() { | ||
return cryptoType; | ||
} | ||
|
||
public void setCryptoType(Crypto cryptoType) { | ||
this.cryptoType = cryptoType; | ||
} | ||
|
||
public BigDecimal getAmount() { | ||
return amount; | ||
} | ||
|
||
public void setAmount(BigDecimal amount) { | ||
this.amount = amount; | ||
} | ||
} |
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,32 @@ | ||
package com.globant.domain.entities; | ||
|
||
import com.globant.domain.util.InvalidOrderException; | ||
|
||
import java.math.BigDecimal; | ||
import java.security.InvalidAlgorithmParameterException; | ||
|
||
public class SellOrder extends Order{ | ||
private BigDecimal minimumPrice; | ||
public SellOrder(Crypto cryptoType, BigDecimal amount, BigDecimal minimumPrice) throws InvalidOrderException { | ||
super(cryptoType, amount); | ||
if (cryptoType.getPrice().compareTo(minimumPrice.subtract(new BigDecimal(1))) < 0) | ||
throw new InvalidOrderException("The minimum price is higher than the current price"); | ||
} | ||
|
||
public BigDecimal getMinimumPrice() { | ||
return minimumPrice; | ||
} | ||
|
||
public void setMinimumPrice(BigDecimal minimumPrice) { | ||
this.minimumPrice = minimumPrice; | ||
} | ||
|
||
public String toString() { | ||
return "SellOrder{" + | ||
"minimumPrice=" + minimumPrice + | ||
", cryptoType=" + this.getCryptoType() + | ||
", amount=" + this.getAmount() + | ||
'}'; | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/globant/domain/entities/Transaction.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,25 @@ | ||
package com.globant.domain.entities; | ||
|
||
import com.globant.domain.util.TradeType; | ||
|
||
import java.math.BigDecimal; | ||
|
||
public class Transaction { | ||
private Crypto cryptoTraded; | ||
private BigDecimal amountTraded; | ||
private BigDecimal priceAtTheMoment; | ||
private TradeType tradeType; | ||
|
||
public Transaction(Crypto cryptoTraded, BigDecimal amountTraded, TradeType tradeType){ | ||
this.cryptoTraded = cryptoTraded; | ||
this.amountTraded = amountTraded; | ||
this.tradeType = tradeType; | ||
this.priceAtTheMoment = cryptoTraded.price; | ||
} | ||
|
||
@Override | ||
public String toString(){ | ||
return ""; | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/globant/domain/util/InvalidOrderException.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,7 @@ | ||
package com.globant.domain.util; | ||
|
||
public class InvalidOrderException extends Exception{ | ||
public InvalidOrderException(String message) { | ||
super(message); | ||
} | ||
} |
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,18 @@ | ||
package com.globant.domain.util; | ||
|
||
public class MakeId { | ||
public static String makeIdNumber(int numberId) { | ||
String id; | ||
if (numberId < 10) { | ||
id = "000" + numberId; | ||
} else if (numberId < 100) { | ||
id = "00" + numberId; | ||
} else if (numberId < 1000) { | ||
id = "0" + numberId; | ||
} else { | ||
id = "" + numberId; | ||
} | ||
numberId++; | ||
return id; | ||
} | ||
} |
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,5 @@ | ||
package com.globant.domain.util; | ||
|
||
public enum TradeType { | ||
BUY, SELL | ||
} |