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