testing front api
This commit is contained in:
parent
14d111508e
commit
b328940037
|
@ -6,6 +6,10 @@ import com.j256.ormlite.stmt.PreparedQuery;
|
||||||
import com.j256.ormlite.stmt.QueryBuilder;
|
import com.j256.ormlite.stmt.QueryBuilder;
|
||||||
import com.j256.ormlite.stmt.UpdateBuilder;
|
import com.j256.ormlite.stmt.UpdateBuilder;
|
||||||
import database.DatabaseHelper;
|
import database.DatabaseHelper;
|
||||||
|
import org.apache.log4j.BasicConfigurator;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import restImplementation.WalletImplementation;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -36,6 +40,7 @@ public class WalletDao {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateWalletBalance(String walletHash, double newBalance) throws Exception {
|
public void updateWalletBalance(String walletHash, double newBalance) throws Exception {
|
||||||
|
|
||||||
walletDao = createWalletDaoConnection();
|
walletDao = createWalletDaoConnection();
|
||||||
UpdateBuilder<Wallet, String> updateBuilder = walletDao.updateBuilder();
|
UpdateBuilder<Wallet, String> updateBuilder = walletDao.updateBuilder();
|
||||||
long now = Instant.now().toEpochMilli();
|
long now = Instant.now().toEpochMilli();
|
||||||
|
|
|
@ -3,12 +3,17 @@ package restImplementation;
|
||||||
import blockchain.query.TransactionWrapper;
|
import blockchain.query.TransactionWrapper;
|
||||||
import database.user.User;
|
import database.user.User;
|
||||||
import database.user.UserDao;
|
import database.user.UserDao;
|
||||||
|
import org.apache.log4j.BasicConfigurator;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
import org.springframework.security.crypto.bcrypt.BCrypt;
|
import org.springframework.security.crypto.bcrypt.BCrypt;
|
||||||
|
import restService.UserResource;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class UserImplementation {
|
public class UserImplementation {
|
||||||
|
private static Logger logger = Logger.getLogger(UserImplementation.class);
|
||||||
|
|
||||||
public Map<String,String> registerUser(User user) throws Exception {
|
public Map<String,String> registerUser(User user) throws Exception {
|
||||||
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||||
|
@ -87,10 +92,13 @@ public class UserImplementation {
|
||||||
|
|
||||||
|
|
||||||
public Map<String,String> userLogger(User user) throws Exception {
|
public Map<String,String> userLogger(User user) throws Exception {
|
||||||
|
BasicConfigurator.configure();
|
||||||
|
|
||||||
UserDao userDao = new UserDao();
|
UserDao userDao = new UserDao();
|
||||||
Map<String,String> response = new HashMap<>();
|
Map<String,String> response = new HashMap<>();
|
||||||
|
|
||||||
User userResponse = userDao.getUserWithEmail(user.getEmail());
|
User userResponse = userDao.getUserWithEmail(user.getEmail());
|
||||||
|
logger.info(userResponse.getEmail());
|
||||||
|
|
||||||
if(userResponse != null){
|
if(userResponse != null){
|
||||||
String hash = userResponse.getPassword();
|
String hash = userResponse.getPassword();
|
||||||
|
|
|
@ -7,7 +7,10 @@ import database.Wallet.WalletDao;
|
||||||
import database.user.User;
|
import database.user.User;
|
||||||
import database.user.UserDao;
|
import database.user.UserDao;
|
||||||
import org.apache.commons.lang.RandomStringUtils;
|
import org.apache.commons.lang.RandomStringUtils;
|
||||||
|
import org.apache.log4j.BasicConfigurator;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
import org.springframework.security.crypto.bcrypt.BCrypt;
|
import org.springframework.security.crypto.bcrypt.BCrypt;
|
||||||
|
import restService.UserResource;
|
||||||
|
|
||||||
import javax.json.Json;
|
import javax.json.Json;
|
||||||
import javax.json.JsonArray;
|
import javax.json.JsonArray;
|
||||||
|
@ -19,6 +22,7 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class WalletImplementation {
|
public class WalletImplementation {
|
||||||
|
private static Logger logger = Logger.getLogger(WalletImplementation.class);
|
||||||
|
|
||||||
public Map<String,String> createWallet(Wallet wallet) throws Exception {
|
public Map<String,String> createWallet(Wallet wallet) throws Exception {
|
||||||
Map<String,String> response = new HashMap<>();
|
Map<String,String> response = new HashMap<>();
|
||||||
|
@ -81,6 +85,8 @@ public class WalletImplementation {
|
||||||
|
|
||||||
//setBalance
|
//setBalance
|
||||||
public void setBalanceToWallet(String associationHash, String associationPwd, String walletHash, double amount) throws Exception {
|
public void setBalanceToWallet(String associationHash, String associationPwd, String walletHash, double amount) throws Exception {
|
||||||
|
BasicConfigurator.configure();
|
||||||
|
|
||||||
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
TransactionWrapper transactionWrapper = new TransactionWrapper();
|
||||||
UserDao userDao = new UserDao();
|
UserDao userDao = new UserDao();
|
||||||
User association = userDao.getUserWithHash(associationHash);
|
User association = userDao.getUserWithHash(associationHash);
|
||||||
|
@ -91,8 +97,12 @@ public class WalletImplementation {
|
||||||
double newBalance = 0.0;
|
double newBalance = 0.0;
|
||||||
transactionWrapper.sendTransaction("setBalanceOnWallet",new String[]{walletHash,String.valueOf(amount)});
|
transactionWrapper.sendTransaction("setBalanceOnWallet",new String[]{walletHash,String.valueOf(amount)});
|
||||||
Wallet wallet = getWallet(walletHash);
|
Wallet wallet = getWallet(walletHash);
|
||||||
|
logger.info("wallet : "+wallet);
|
||||||
if(wallet!=null){
|
if(wallet!=null){
|
||||||
|
logger.info("wallet!=null");
|
||||||
newBalance=wallet.getBalance();
|
newBalance=wallet.getBalance();
|
||||||
|
logger.info("newBalance : "+newBalance);
|
||||||
|
logger.info("walletHash : "+walletHash);
|
||||||
WalletDao walletDao = new WalletDao();
|
WalletDao walletDao = new WalletDao();
|
||||||
walletDao.updateWalletBalance(walletHash,newBalance);
|
walletDao.updateWalletBalance(walletHash,newBalance);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package restService;
|
package restService;
|
||||||
|
|
||||||
import database.user.User;
|
import database.user.User;
|
||||||
|
import org.apache.log4j.BasicConfigurator;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
@ -12,6 +14,7 @@ import java.util.Map;
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(value = "/api/rest/user")
|
@RequestMapping(value = "/api/rest/user")
|
||||||
public class UserResource {
|
public class UserResource {
|
||||||
|
private static Logger logger = Logger.getLogger(UserResource.class);
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping(value = "/register", method = RequestMethod.POST,produces = "application/json")
|
@RequestMapping(value = "/register", method = RequestMethod.POST,produces = "application/json")
|
||||||
|
@ -59,9 +62,13 @@ public class UserResource {
|
||||||
@RequestMapping(value = "/login", method = RequestMethod.POST, produces = "application/json")
|
@RequestMapping(value = "/login", method = RequestMethod.POST, produces = "application/json")
|
||||||
@ResponseStatus(HttpStatus.OK)
|
@ResponseStatus(HttpStatus.OK)
|
||||||
public ResponseEntity<StringResponse> login(@Valid @RequestBody User user){
|
public ResponseEntity<StringResponse> login(@Valid @RequestBody User user){
|
||||||
|
BasicConfigurator.configure();
|
||||||
try{
|
try{
|
||||||
UserImplementation userImplementation = new UserImplementation();
|
UserImplementation userImplementation = new UserImplementation();
|
||||||
|
logger.info(user.getEmail());
|
||||||
|
logger.info(user.getPassword());
|
||||||
Map<String,String> response = userImplementation.userLogger(user);
|
Map<String,String> response = userImplementation.userLogger(user);
|
||||||
|
logger.info(response.get("response"));
|
||||||
switch (response.get("response")){
|
switch (response.get("response")){
|
||||||
case "Not Exist" : {
|
case "Not Exist" : {
|
||||||
StringResponse responseS = new StringResponse("Not Found");
|
StringResponse responseS = new StringResponse("Not Found");
|
||||||
|
@ -75,7 +82,7 @@ public class UserResource {
|
||||||
StringResponse responseS = new StringResponse("Error");
|
StringResponse responseS = new StringResponse("Error");
|
||||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
|
||||||
}
|
}
|
||||||
case "Ok":{
|
case "true":{
|
||||||
StringResponse responseS = new StringResponse("Ok",response.get("userHash"));
|
StringResponse responseS = new StringResponse("Ok",response.get("userHash"));
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(responseS);
|
return ResponseEntity.status(HttpStatus.OK).body(responseS);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ public class WalletResource {
|
||||||
|
|
||||||
Wallet returnWallet = new Wallet();
|
Wallet returnWallet = new Wallet();
|
||||||
returnWallet.setWallet_hash(walletResponse.get("walletHash"));
|
returnWallet.setWallet_hash(walletResponse.get("walletHash"));
|
||||||
|
returnWallet.setUser_hash(wallet.getUser_hash());
|
||||||
returnWallet.setBalance(Double.parseDouble(walletResponse.get("walletBalance")));
|
returnWallet.setBalance(Double.parseDouble(walletResponse.get("walletBalance")));
|
||||||
returnWallet.setType(walletResponse.get("walletType"));
|
returnWallet.setType(walletResponse.get("walletType"));
|
||||||
|
|
||||||
|
@ -102,8 +103,10 @@ public class WalletResource {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping(value = "/{userHash}/delete/{walletHash}", method = RequestMethod.DELETE)
|
@RequestMapping(value = "/delete", method = RequestMethod.POST)
|
||||||
public ResponseEntity deleteWallet(@PathVariable("walletHash") String walletHash, @PathVariable("userHash") String userHash){
|
public ResponseEntity deleteWallet(@RequestBody Map<String,String> requestParam){
|
||||||
|
String userHash = requestParam.get("userHash");
|
||||||
|
String walletHash = requestParam.get("walletHash");
|
||||||
WalletImplementation walletImplementation = new WalletImplementation();
|
WalletImplementation walletImplementation = new WalletImplementation();
|
||||||
try{
|
try{
|
||||||
walletImplementation.deleteWallet(walletHash,userHash);
|
walletImplementation.deleteWallet(walletHash,userHash);
|
||||||
|
@ -113,9 +116,4 @@ public class WalletResource {
|
||||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,11 @@ import database.Wallet.Wallet;
|
||||||
import database.user.User;
|
import database.user.User;
|
||||||
import org.apache.log4j.BasicConfigurator;
|
import org.apache.log4j.BasicConfigurator;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.junit.Ignore;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Ignore
|
||||||
public class CreateDataSetProcess { //OK
|
public class CreateDataSetProcess { //OK
|
||||||
private static Logger logger = Logger.getLogger(CreateDataSetProcess.class);
|
private static Logger logger = Logger.getLogger(CreateDataSetProcess.class);
|
||||||
private static String gonetteHash = "";
|
private static String gonetteHash = "";
|
||||||
|
|
Loading…
Reference in a new issue