Skip to content

Commit

Permalink
feat: Initialize project with entity classes
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyyHL committed Aug 26, 2024
1 parent 7175604 commit 586b763
Show file tree
Hide file tree
Showing 18 changed files with 359 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .gitignore
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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions pom.xml
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>
33 changes: 33 additions & 0 deletions src/main/java/com/globant/Main.java
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 src/main/java/com/globant/application/port/out/OrderBook.java
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 src/main/java/com/globant/application/port/out/WalletRepo.java
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();
}
34 changes: 34 additions & 0 deletions src/main/java/com/globant/domain/entities/Account.java
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;
}
}
28 changes: 28 additions & 0 deletions src/main/java/com/globant/domain/entities/BuyOrder.java
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() +
'}';
}
}
43 changes: 43 additions & 0 deletions src/main/java/com/globant/domain/entities/Crypto.java
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;
}
}
29 changes: 29 additions & 0 deletions src/main/java/com/globant/domain/entities/Order.java
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;
}
}
32 changes: 32 additions & 0 deletions src/main/java/com/globant/domain/entities/SellOrder.java
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 src/main/java/com/globant/domain/entities/Transaction.java
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 "";
}

}
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);
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/globant/domain/util/MakeId.java
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;
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/globant/domain/util/TradeType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.globant.domain.util;

public enum TradeType {
BUY, SELL
}

0 comments on commit 586b763

Please sign in to comment.