Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/s3550293/FauxExchange
Browse files Browse the repository at this point in the history
  • Loading branch information
s3550293 committed Jun 3, 2019
2 parents b13190c + b62c337 commit d82fb09
Show file tree
Hide file tree
Showing 21 changed files with 126 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ public class CurrencyServiceController {
@Autowired
private CurrencyService currencyService;

/* Get Currencies API Call */
@RequestMapping(value = "/api/currencies", method = RequestMethod.GET)
public ResponseEntity<Object> getCurrencies() {
return new ResponseEntity<Object>(currencyService.getCurrencies(), HttpStatus.OK);
}

/* Get Currency by Code API Call */
@RequestMapping(value = "/api/currencies/{code}", method = RequestMethod.GET)
public ResponseEntity<Object> getCurrencyByCode(@PathVariable("code") String code) {
return new ResponseEntity<Object>(currencyService.getCurrency(code), HttpStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ public class OrderServiceController {
@Autowired
OrderService orderService;

/* Get All Orders API Call */
@RequestMapping(value = "/api/orders", method = RequestMethod.GET)
public ResponseEntity<Object> getOrders() {
return new ResponseEntity<>(orderService.getOrders(), HttpStatus.OK);
}


/* Create Order API Call */
@RequestMapping(value = "/api/orders", method = RequestMethod.POST)
public ResponseEntity<Object> createOrder(@RequestBody Order order) {
if(orderService.createOrder(order)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public ResponseEntity<Object> getSession(HttpSession session) {
}

/* Post Request for Session Creation */
/* Create Session API Call */
@RequestMapping(value = "/api/session", method = RequestMethod.POST)
public ResponseEntity<Object> createSession(@RequestBody SessionInfo si, HttpSession session) {

Expand All @@ -60,41 +61,47 @@ public ResponseEntity<Object> createSession(@RequestBody SessionInfo si, HttpSes
return new ResponseEntity<>("Created Session Successfully", HttpStatus.OK);
}

/* Get User Info API Call */
@RequestMapping(value = "/api/session/info", method = RequestMethod.GET)
public ResponseEntity<Object> getUserInfo(HttpSession session) {
// System.out.println("User Info Grab");
String userId = (String)session.getAttribute("userId");
return new ResponseEntity<>(userService.getUserInfo(userId), HttpStatus.OK);
}

/* Get User Orders API Call */
@RequestMapping(value = "/api/session/orders", method = RequestMethod.GET)
public ResponseEntity<Object> getUserOrders(HttpSession session) {
// System.out.println("User Order Grab");
String userId = (String)session.getAttribute("userId");
return new ResponseEntity<>(orderService.getOrdersByUserId(userId), HttpStatus.OK);
}

/* Get Wallet based on User API Call */
@RequestMapping(value = "/api/session/crypto", method = RequestMethod.GET)
public ResponseEntity<Object> getUserCrypto(HttpSession session) {
// System.out.println("User Crypto Grab");
String userId = (String)session.getAttribute("userId");
return new ResponseEntity<>(userService.getUserWallet(userId), HttpStatus.OK);
}

/* Get Transactions based on User API Call */
@RequestMapping(value = "/api/session/transactions", method = RequestMethod.GET)
public ResponseEntity<Object> getUserTransactions(HttpSession session) {
// System.out.println("User Transaction Grab");
String userId = (String)session.getAttribute("userId");
return new ResponseEntity<>(transactionService.getTransactionsByUserId(userId), HttpStatus.OK);
}

/* Get Friends based on User API Call */
@RequestMapping(value = "/api/session/friends", method = RequestMethod.GET)
public ResponseEntity<Object> getUserFriends(HttpSession session) {
// System.out.println("User Friend Grab");
String userId = (String)session.getAttribute("userId");
return new ResponseEntity<>(userService.getFriends(userId), HttpStatus.OK);
}

/* Add Friend API Call */
@RequestMapping(value = "/api/session/addfriends", method = RequestMethod.POST)
public ResponseEntity<Object> addUserFriends(@RequestBody Map<String, Object> email, HttpSession session) {
// System.out.println("SessionServiceController");
Expand All @@ -104,6 +111,7 @@ public ResponseEntity<Object> addUserFriends(@RequestBody Map<String, Object> em
return new ResponseEntity<>("Add Friend Successful", HttpStatus.OK);
}

/* Get User Account Value API Call */
@RequestMapping(value = "/api/session/value", method = RequestMethod.GET)
public ResponseEntity<Object> getUserValue(HttpSession session) {
HashMap<String, String> map = new HashMap<String, String>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class TransactionServiceController {
@Autowired
TransactionService tService;

/* Get Transaction API Call */
@RequestMapping(value = "/api/transaction/all", method = RequestMethod.GET)
public ResponseEntity<Object> getTransactions() {
return new ResponseEntity<>(tService.getTransactions(), HttpStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,25 @@ public class UserServiceController {
@Autowired
UserService userService;

/* Get Users API Call
JSON Get Request all the users */
@RequestMapping(value = "/api/user/all", method = RequestMethod.GET)
public ResponseEntity<Object> getUsers() {
return new ResponseEntity<>(userService.getUsers(), HttpStatus.OK);
}


/* Create User API Call
JSON Post Request creates the user
Response created */
@RequestMapping(value = "/api/user/registration", method = RequestMethod.POST)
public ResponseEntity<Object> createUser(@RequestBody User user) {
System.out.println("Creating User - ");
userService.createUser(user);
return new ResponseEntity<>("Hello World!", HttpStatus.OK);
}

/* Get Leaderboard API Call
JSON Get Request the leaderboard */
@RequestMapping(value = "/api/user/leaderboard", method = RequestMethod.GET)
public ResponseEntity<Object> getLeaderboard() {
return new ResponseEntity<>(userService.getLeaderboard(), HttpStatus.OK);
Expand Down
21 changes: 12 additions & 9 deletions src/main/java/com/g4/fauxexchange/model/Currency.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ public Currency(String code, String name) {
this.price.add(new Price(0.0));
}

@Override
public String toString() {
return String.format("Currency[id=%s, code='%s', name='%s'] | %s",
currencyId, code, name, price.peekLast());
}

// Getters & Setters

public String getCurrencyId() {
return this.currencyId;
}
Expand All @@ -48,27 +56,22 @@ public void setName(String name) {
this.name = name;
}

@Override
public String toString() {
return String.format("Currency[id=%s, code='%s', name='%s'] | %s",
currencyId, code, name, price.peekLast());
}
// Getters & Setters

/* CUSTOM
Getters & Setters
*/

// Update the current price in the Currency, given a price.
public void update(Price price) {
if(!this.price.isEmpty()) {
price.setChange(price.getValue() - this.price.peekLast().getValue());
this.price.add(price);
}
}

// Return the most recent price
public double getRecentPrice() {
return this.price.peekLast().getValue();
}

// Return the most recent change
public double getRecentChange() {
return this.price.peekLast().getChange();
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/g4/fauxexchange/model/LeaderboardInfo.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.g4.fauxexchange.model;

/*
This class is used for manipulating data for the frontend
*/

public class LeaderboardInfo {

public String name;
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/com/g4/fauxexchange/model/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ public String toString() {
return String.format("Order[id=%s, type='%s', code='%s', price='%f', qty='%f', userId='%s']", orderId, type, code, price, qty, userId);
}

/* GENERIC
Getters & Setters
*/
// Getters & Setters

public String getOrderId() {
return this.orderId;
}
Expand Down Expand Up @@ -84,10 +83,9 @@ public void setUserId(String userId) {
this.userId = userId;
}

/* CUSTOM
Getters & Setters
*/
// Custom Getters & Setters

// Return the current value of the order based on price per coin * qty
public double getValue() {
return this.price * this.qty;
}
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/g4/fauxexchange/model/Price.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public Price(double value) {
this.time = Instant.now().getEpochSecond();
}

@Override
public String toString() {
return String.format("Price[value='%f', change='%f', time='%d']", value, change, time);
}

// Getters & Setters

public double getValue() {
return this.value;
}
Expand All @@ -42,10 +49,5 @@ public void setTime(long time) {
this.time = time;
}

@Override
public String toString() {
return String.format("Price[value='%f', change='%f', time='%d']", value, change, time);
}

}

2 changes: 2 additions & 0 deletions src/main/java/com/g4/fauxexchange/model/SessionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

// This class is used for manipulation of data for the front end

@Document
public class SessionInfo {

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/g4/fauxexchange/model/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public Transaction(String type, String code, double ppc, double qty, double valu
this.userId = userId;
}

// Getters & Setters

public void setType(String type) {
this.type = type;
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/g4/fauxexchange/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,15 @@ public void setRole(String role) {
this.role = role;
}

//Custom Getters & Setters

//Return all wallets back
public LinkedList<Wallet> getWallets() {
return this.wallet;
}


//Return a specific wallet back
public Wallet getWallet(String code) {
Wallet wallet = null;
for(Wallet w : this.wallet) {
Expand All @@ -108,6 +113,7 @@ public Wallet getWallet(String code) {
return wallet;
}

//Return all the wallets collective total value
public double getWalletsValue() {
double result = 0;

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/g4/fauxexchange/model/UserInfo.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.g4.fauxexchange.model;

// This class is used for manipulation of data for the frontend

public class UserInfo {
public String fName;
public String lName;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/g4/fauxexchange/model/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public Wallet(String code, double price, double qty) {
this.value = price * qty;
}

//Getter & Setters

public String getCode() {
return this.code;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ public class CurrencyServiceImpl implements CurrencyService {
@Autowired
private CurrencyRepository currencyRepository;

/* Create Currency
Based on a given currency we can create a new currency to save to the database */
@Override
public void createCurrency(Currency currency) {
currencyRepository.save(currency);
}

/* Update Currency
This function pulls data from a API and sets the currencies price to the data.
All other data is calculated within this function. Eg, timestamp and change */
@Override
@Scheduled(fixedRate=60000, initialDelay = 60000)
public void updateCurrency() {
Expand Down Expand Up @@ -55,16 +60,20 @@ public void updateCurrency() {
}
}

/* Delete Currency
Based on a given currency remove it fomr the database */
@Override
public void deleteCurrency(Currency currency) {
currencyRepository.delete(currency);
}

/* Get All currencies */
@Override
public List<Currency> getCurrencies() {
return currencyRepository.findAllWithRecentPrices();
}

/* Get specific currency */
@Override
public Currency getCurrency(String code) {
return currencyRepository.findByCode(code);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ public boolean deleteOrder(Order order) {
return false;
}

/* Process Orders
This function runs through all orders and compares to the current market price. And then either
Sells or Buys.
If neither happens orders will exist unless they get deleted. */
@Override
@Scheduled(fixedRate = 15000, initialDelay = 15000)
public void processOrders() {
Expand Down Expand Up @@ -161,17 +165,19 @@ public void processOrders() {
}
}


/* Returns all the orders */
@Override
public List<Order> getOrders() {
return orderRepository.findAll();
}

/* Returns all orders based on code */
@Override
public List<Order> getOrders(String code) {
return orderRepository.findAll();
}

/* Returns all orders from user */
@Override
public List<Order> getOrdersByUserId(String id) {
return orderRepository.findByUserId(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class SecurityServiceImpl implements SecurityService {
@Autowired
private UserDetailsService userDetailsService;

/* Functino for logging in through security service */
@Override
public String findLoggedInUsername() {
Object userDetails = SecurityContextHolder.getContext().getAuthentication().getDetails();
Expand All @@ -29,6 +30,8 @@ public String findLoggedInUsername() {
return null;
}

/* Auto Login
WIP */
@Override
public void autoLogin(String email, String password) {
UserDetails userDetails = userDetailsService.loadUserByUsername(email);
Expand Down
Loading

0 comments on commit d82fb09

Please sign in to comment.