update api

This commit is contained in:
GME 2019-04-11 18:03:43 +02:00
parent 7961e25793
commit 7cc40b2122
4 changed files with 31 additions and 24 deletions

View file

@ -42,7 +42,7 @@ public class UserImplementation {
user.setApproved(false); user.setApproved(false);
userDao.addUser(user); userDao.addUser(user);
response.put("userHash",user.getUser_hash()); response.put("user_hash",user.getUser_hash());
response.put("response","true"); response.put("response","true");
return response; return response;
} }

View file

@ -19,8 +19,8 @@ import java.util.Map;
public class WalletImplementation { public class WalletImplementation {
public Map<String,String> createWallet(Wallet wallet) throws Exception { public Wallet createWallet(Wallet wallet) throws Exception {
Map<String,String> response = new HashMap<>(); //Map<String,String> response = new HashMap<>();
TransactionWrapper transactionWrapper = new TransactionWrapper(); TransactionWrapper transactionWrapper = new TransactionWrapper();
WalletDao walletDao = new WalletDao(); WalletDao walletDao = new WalletDao();
UserDao userDao = new UserDao(); UserDao userDao = new UserDao();
@ -38,13 +38,15 @@ public class WalletImplementation {
walletDao.addWallet(wallet); // add wallet to replica DB walletDao.addWallet(wallet); // add wallet to replica DB
response.put("walletHash",wallet.getWallet_hash()); /*
response.put("walletType",wallet.getType()); response.put("wallet_hash",wallet.getWallet_hash());
response.put("walletBalance",wallet.getBalance().toString()); response.put("wallet_type",wallet.getType());
response.put("ownerHash",wallet.getUser_hash()); response.put("wallet_balance",wallet.getBalance().toString());
response.put("owner_hash",wallet.getUser_hash());
response.put("response","true"); response.put("response","true");
*/
return response; return wallet;
} }
//getAllUserWallets //getAllUserWallets

View file

@ -14,7 +14,7 @@ import java.util.Map;
public class UserResource { public class UserResource {
@RequestMapping(value = "/register", method = RequestMethod.POST,produces = "application/json") @RequestMapping(value = "/register", method = RequestMethod.POST,produces = "application/json")
@ResponseStatus(HttpStatus.CREATED) @ResponseStatus(HttpStatus.CREATED)
public ResponseEntity<StringResponse> registerUser(@Valid @RequestBody User user){ public ResponseEntity registerUser(@Valid @RequestBody User user){
try{ try{
UserImplementation userImplementation = new UserImplementation(); UserImplementation userImplementation = new UserImplementation();
Map<String,String> userHashResponse = userImplementation.registerUser(user); Map<String,String> userHashResponse = userImplementation.registerUser(user);
@ -22,11 +22,11 @@ public class UserResource {
if(Boolean.parseBoolean(userHashResponse.get("response"))){ if(Boolean.parseBoolean(userHashResponse.get("response"))){
//TEMPORARY AUTOMATIC APPROVE //TEMPORARY AUTOMATIC APPROVE
user.setUser_hash(userHashResponse.get("userHash")); user.setUser_hash(userHashResponse.get("user_hash"));
userImplementation.approveUser(user); userImplementation.approveUser(user);
// //
StringResponse responseS = new StringResponse("Ok",userHashResponse.get("userHash")); StringResponse responseS = new StringResponse("Ok",userHashResponse.get("user_hash"));
return ResponseEntity.status(HttpStatus.OK).body(responseS); return ResponseEntity.status(HttpStatus.OK).body(responseS);
}else { }else {
StringResponse responseS = new StringResponse("User already exist"); StringResponse responseS = new StringResponse("User already exist");

View file

@ -18,32 +18,37 @@ public class WalletResource {
public ResponseEntity createWallet(@Valid @RequestBody Wallet wallet){ public ResponseEntity createWallet(@Valid @RequestBody Wallet wallet){
try{ try{
WalletImplementation walletImplementation = new WalletImplementation(); WalletImplementation walletImplementation = new WalletImplementation();
Map<String,String> walletResponse = walletImplementation.createWallet(wallet); Wallet walletResponse = walletImplementation.createWallet(wallet);
/*
Wallet returnWallet = new Wallet(); Wallet returnWallet = new Wallet();
returnWallet.setWallet_hash(walletResponse.get("walletHash")); returnWallet.setWallet_hash(walletResponse.get("wallet_hash"));
returnWallet.setUser_hash(wallet.getUser_hash()); returnWallet.setUser_hash(wallet.getUser_hash());
returnWallet.setBalance(Double.parseDouble(walletResponse.get("walletBalance"))); returnWallet.setBalance(Double.parseDouble(walletResponse.get("wallet_balance")));
returnWallet.setType(walletResponse.get("walletType")); returnWallet.setType(walletResponse.get("wallet_type"));
*/
return ResponseEntity.status(HttpStatus.OK).body(walletResponse);
/*
if(Boolean.parseBoolean(walletResponse.get("response"))){ if(Boolean.parseBoolean(walletResponse.get("response"))){
return ResponseEntity.status(HttpStatus.OK).body(returnWallet);
}else { }else {
StringResponse responseS = new StringResponse("Wallet already exist"); StringResponse responseS = new StringResponse("Wallet already exist");
return ResponseEntity.status(HttpStatus.FOUND).body(responseS); return ResponseEntity.status(HttpStatus.FOUND).body(responseS);
} }
*/
}catch (Exception e){ }catch (Exception e){
StringResponse responseS = new StringResponse(e.getMessage()); StringResponse responseS = new StringResponse(e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS); return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
} }
} }
@RequestMapping(value = "/getUserWallets", method = RequestMethod.GET, params = {"userHash"}, produces = "application/json") @RequestMapping(value = "/getUserWallets", method = RequestMethod.GET, params = {"user_hash"}, produces = "application/json")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
public ResponseEntity getWallets(@RequestParam(value = "userHash") String userHash){ public ResponseEntity getWallets(@RequestParam(value = "user_hash") String user_hash){
WalletImplementation walletImplementation = new WalletImplementation(); WalletImplementation walletImplementation = new WalletImplementation();
try{ try{
JsonArray wallets = walletImplementation.getAllUserWallets(userHash); JsonArray wallets = walletImplementation.getAllUserWallets(user_hash);
return ResponseEntity.status(HttpStatus.OK).body(wallets); return ResponseEntity.status(HttpStatus.OK).body(wallets);
} catch (Exception e){ } catch (Exception e){
StringResponse responseS = new StringResponse(e.getMessage()); StringResponse responseS = new StringResponse(e.getMessage());
@ -51,12 +56,12 @@ public class WalletResource {
} }
} }
@RequestMapping(value = "/getWallet", method = RequestMethod.GET, params = {"walletHash"}, produces = "application/json") @RequestMapping(value = "/getWallet", method = RequestMethod.GET, params = {"wallet_hash"}, produces = "application/json")
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
public ResponseEntity getWallet(@RequestParam(value = "walletHash") String walletHash){ public ResponseEntity getWallet(@RequestParam(value = "wallet_hash") String wallet_hash){
WalletImplementation walletImplementation = new WalletImplementation(); WalletImplementation walletImplementation = new WalletImplementation();
try{ try{
Wallet walletResponse = walletImplementation.getWallet(walletHash); Wallet walletResponse = walletImplementation.getWallet(wallet_hash);
if(walletResponse!=null){ if(walletResponse!=null){
return ResponseEntity.status(HttpStatus.OK).body(walletResponse); return ResponseEntity.status(HttpStatus.OK).body(walletResponse);
}else{ }else{
@ -96,8 +101,8 @@ public class WalletResource {
@RequestMapping(value = "/delete", method = RequestMethod.POST) @RequestMapping(value = "/delete", method = RequestMethod.POST)
public ResponseEntity deleteWallet(@RequestBody Map<String,String> requestParam){ public ResponseEntity deleteWallet(@RequestBody Map<String,String> requestParam){
String userHash = requestParam.get("userHash"); String userHash = requestParam.get("user_hash");
String walletHash = requestParam.get("walletHash"); String walletHash = requestParam.get("wallet_hash");
WalletImplementation walletImplementation = new WalletImplementation(); WalletImplementation walletImplementation = new WalletImplementation();
try{ try{
walletImplementation.deleteWallet(walletHash,userHash); walletImplementation.deleteWallet(walletHash,userHash);