102 lines
5 KiB
Java
102 lines
5 KiB
Java
package restService;
|
|
|
|
import database.Wallet.BalanceWallet;
|
|
import database.Wallet.Wallet;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import restImplementation.WalletImplementation;
|
|
import javax.json.JsonArray;
|
|
import javax.validation.Valid;
|
|
import java.util.Map;
|
|
|
|
@RestController
|
|
@RequestMapping(value = "/api/rest/wallet")
|
|
public class WalletResource {
|
|
@RequestMapping(value = "/create", method = RequestMethod.POST,produces = "application/json")
|
|
@ResponseStatus(HttpStatus.CREATED)
|
|
public ResponseEntity createWallet(@Valid @RequestBody Wallet wallet){
|
|
try{
|
|
WalletImplementation walletImplementation = new WalletImplementation();
|
|
Wallet walletResponse = walletImplementation.createWallet(wallet);
|
|
return ResponseEntity.status(HttpStatus.OK).body(walletResponse);
|
|
}catch (Exception e){
|
|
String r = "{\"response\":\""+e.getMessage()+"\"}";
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
|
|
}
|
|
}
|
|
|
|
@RequestMapping(value = "/getUserWallets", method = RequestMethod.GET, params = {"user_hash"}, produces = "application/json")
|
|
@ResponseStatus(HttpStatus.OK)
|
|
public ResponseEntity getWallets(@RequestParam(value = "user_hash") String user_hash){
|
|
WalletImplementation walletImplementation = new WalletImplementation();
|
|
try{
|
|
JsonArray wallets = walletImplementation.getAllUserWallets(user_hash);
|
|
return ResponseEntity.status(HttpStatus.OK).body(wallets);
|
|
} catch (Exception e){
|
|
String r = "{\"response\":\""+e.getMessage()+"\"}";
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
|
|
}
|
|
}
|
|
|
|
@RequestMapping(value = "/getWallet", method = RequestMethod.GET, params = {"wallet_hash"}, produces = "application/json")
|
|
@ResponseStatus(HttpStatus.OK)
|
|
public ResponseEntity getWallet(@RequestParam(value = "wallet_hash") String wallet_hash){
|
|
WalletImplementation walletImplementation = new WalletImplementation();
|
|
try{
|
|
Wallet walletResponse = walletImplementation.getWallet(wallet_hash);
|
|
if(walletResponse!=null){
|
|
return ResponseEntity.status(HttpStatus.OK).body(walletResponse);
|
|
}else{
|
|
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("{\"response\":null}");
|
|
}
|
|
}catch (Exception e){
|
|
String r = "{\"response\":\""+e.getMessage()+"\"}";
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
|
|
}
|
|
}
|
|
|
|
@RequestMapping(value = "/setBalance", method = RequestMethod.POST,produces = "application/json")
|
|
@ResponseStatus(HttpStatus.OK)
|
|
public ResponseEntity setBalance(@RequestBody BalanceWallet BalanceWallet){
|
|
WalletImplementation walletImplementation = new WalletImplementation();
|
|
try{
|
|
walletImplementation.setBalanceToWallet(BalanceWallet.getAssociation_hash(), BalanceWallet.getAssocation_pwd(), BalanceWallet.getWallet_hash(),BalanceWallet.getAmount());
|
|
return ResponseEntity.status(HttpStatus.OK).body("{\"response\":\"ok\"}");
|
|
} catch (Exception e){
|
|
String r = "{\"response\":\""+e.getMessage()+"\"}";
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
|
|
}
|
|
}
|
|
|
|
@RequestMapping(value = "/transfer", method = RequestMethod.POST, produces = "application/json")
|
|
@ResponseStatus(HttpStatus.OK)
|
|
public ResponseEntity transferWallet(@RequestBody Wallet wallet){
|
|
WalletImplementation walletImplementation = new WalletImplementation();
|
|
try {
|
|
walletImplementation.transferWallet(wallet.getWallet_hash(),wallet.getUser_hash());
|
|
return ResponseEntity.status(HttpStatus.OK).body("{\"response\":\"ok\"}");
|
|
} catch (Exception e){
|
|
String r = "{\"response\":\""+e.getMessage()+"\"}";
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
|
|
}
|
|
}
|
|
|
|
@RequestMapping(value = "/delete", method = RequestMethod.POST)
|
|
public ResponseEntity deleteWallet(@RequestBody Map<String,String> requestParam){
|
|
String user_email = requestParam.get("user_email");
|
|
String user_hash = requestParam.get("user_hash");
|
|
String user_password = requestParam.get("user_password");
|
|
String wallet_hash_source = requestParam.get("wallet_hash_source");
|
|
String wallet_hash_dest = requestParam.get("wallet_hash_dest");
|
|
WalletImplementation walletImplementation = new WalletImplementation();
|
|
try{
|
|
walletImplementation.deleteWallet(user_email,user_hash,user_password,wallet_hash_source,wallet_hash_dest);
|
|
return ResponseEntity.status(HttpStatus.OK).body("{\"response\":\"true\"}");
|
|
}catch (Exception e){
|
|
String r = "{\"response\":\"false\"}";
|
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(r);
|
|
}
|
|
}
|
|
}
|