Merge branch 'features1.4/database' into develop-1.4
This commit is contained in:
commit
3893526f3d
|
@ -1,4 +1,105 @@
|
|||
package database.Wallet;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
|
||||
@DatabaseTable(tableName = "T_WALLET")
|
||||
public class Wallet {
|
||||
@DatabaseField(canBeNull = false)
|
||||
private String wallet_hash;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private String user_hash;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private String type;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private Double sold;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private long creation_date;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private long modification_date;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private boolean is_active;
|
||||
|
||||
//Constructors
|
||||
//Default constructor for ORMLite
|
||||
public Wallet() {
|
||||
}
|
||||
|
||||
public Wallet(String wallet_hash, String user_hash, String type, boolean isActive) {
|
||||
this.wallet_hash = wallet_hash;
|
||||
this.user_hash = user_hash;
|
||||
this.type = type;
|
||||
this.is_active = isActive;
|
||||
}
|
||||
|
||||
public Wallet(String wallet_hash, String user_hash, String type, Double sold, boolean isActive) {
|
||||
this.wallet_hash = wallet_hash;
|
||||
this.user_hash = user_hash;
|
||||
this.type = type;
|
||||
this.sold = sold;
|
||||
this.is_active = isActive;
|
||||
}
|
||||
|
||||
public String getWallet_hash() {
|
||||
return wallet_hash;
|
||||
}
|
||||
public void setWallet_hash(String wallet_hash) {
|
||||
this.wallet_hash = wallet_hash;
|
||||
}
|
||||
|
||||
public String getUser_hash() {
|
||||
return user_hash;
|
||||
}
|
||||
public void setUser_hash(String user_hash) {
|
||||
this.user_hash = user_hash;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Double getSold() {
|
||||
return sold;
|
||||
}
|
||||
public void setSold(Double sold) {
|
||||
this.sold = sold;
|
||||
}
|
||||
|
||||
public boolean isIs_active() {
|
||||
return is_active;
|
||||
}
|
||||
|
||||
public void setIs_active(boolean is_active) {
|
||||
this.is_active = is_active;
|
||||
}
|
||||
|
||||
public long getCreation_date() {
|
||||
return creation_date;
|
||||
}
|
||||
|
||||
public void setCreation_date(long creation_date) {
|
||||
this.creation_date = creation_date;
|
||||
}
|
||||
|
||||
public long getModification_date() {
|
||||
return modification_date;
|
||||
}
|
||||
|
||||
public void setModification_date(long modification_date) {
|
||||
this.modification_date = modification_date;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Wallet{" +
|
||||
"wallet_hash='" + wallet_hash + '\'' +
|
||||
", user_hash='" + user_hash + '\'' +
|
||||
", type='" + type + '\'' +
|
||||
", sold=" + sold +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,74 @@
|
|||
package database.Wallet;
|
||||
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.dao.DaoManager;
|
||||
import com.j256.ormlite.stmt.PreparedQuery;
|
||||
import com.j256.ormlite.stmt.QueryBuilder;
|
||||
import com.j256.ormlite.stmt.UpdateBuilder;
|
||||
import database.DatabaseHelper;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
|
||||
public class WalletDao {
|
||||
private DatabaseHelper dbh = new DatabaseHelper();
|
||||
private Dao<Wallet, String> walletDao;
|
||||
|
||||
private Dao createWalletDaoConnection(){
|
||||
try {
|
||||
return DaoManager.createDao(dbh.setupDatabaseConnection(),Wallet.class);
|
||||
}catch (Exception e){
|
||||
System.out.println(e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void addWallet(Wallet wallet)throws Exception {
|
||||
walletDao = createWalletDaoConnection();
|
||||
walletDao.create(wallet);
|
||||
}
|
||||
|
||||
public Wallet getWallet(String walletHash) throws Exception {
|
||||
walletDao = createWalletDaoConnection();
|
||||
QueryBuilder<Wallet, String> queryBuilder = walletDao.queryBuilder();
|
||||
queryBuilder.where().eq("wallet_hash",walletHash).and().eq("is_active",true);
|
||||
PreparedQuery<Wallet> preparedQuery = queryBuilder.prepare();
|
||||
return walletDao.queryForFirst(preparedQuery);
|
||||
}
|
||||
|
||||
public List<Wallet> getUserWallet(String userHash) throws Exception {
|
||||
walletDao = createWalletDaoConnection();
|
||||
QueryBuilder<Wallet, String> queryBuilder = walletDao.queryBuilder();
|
||||
queryBuilder.where().eq("user_hash",userHash).and().eq("is_active",true);
|
||||
PreparedQuery<Wallet> preparedQuery = queryBuilder.prepare();
|
||||
return walletDao.query(preparedQuery);
|
||||
}
|
||||
|
||||
public List<Wallet> getOldUserWallets(String userHash) throws Exception{
|
||||
walletDao = createWalletDaoConnection();
|
||||
QueryBuilder<Wallet, String> queryBuilder = walletDao.queryBuilder();
|
||||
queryBuilder.where().eq("user_hash",userHash).and().eq("is_active",false);
|
||||
PreparedQuery<Wallet> preparedQuery = queryBuilder.prepare();
|
||||
return walletDao.query(preparedQuery);
|
||||
}
|
||||
|
||||
public void transferWallet(String walletHash, String newUserHash) throws Exception{
|
||||
walletDao = createWalletDaoConnection();
|
||||
UpdateBuilder<Wallet, String> updateBuilder = walletDao.updateBuilder();
|
||||
updateBuilder.updateColumnValue("user_hash",newUserHash);
|
||||
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
|
||||
updateBuilder.updateColumnValue("modification_date",timestamp.getTime());
|
||||
updateBuilder.where().eq("walletHash",walletHash).and().eq("is_active",true);
|
||||
updateBuilder.update();
|
||||
}
|
||||
|
||||
public void deleteWallet(String walletHash) throws Exception{
|
||||
walletDao = createWalletDaoConnection();
|
||||
UpdateBuilder<Wallet, String> updateBuilder = walletDao.updateBuilder();
|
||||
updateBuilder.updateColumnValue("is_active",false);
|
||||
Timestamp timestamp = new Timestamp(System.currentTimeMillis());
|
||||
updateBuilder.updateColumnValue("modification_date",timestamp.getTime());
|
||||
updateBuilder.where().eq("walletHash",walletHash);
|
||||
updateBuilder.update();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -79,6 +79,7 @@ public class UserImplementation {
|
|||
return response;
|
||||
}
|
||||
|
||||
|
||||
private String hashPassword(String plainTextPassword){
|
||||
return BCrypt.hashpw(plainTextPassword,BCrypt.gensalt());
|
||||
}
|
||||
|
|
|
@ -89,6 +89,20 @@ public class UserResource {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@PostMapping(value = "/delete", produces = "application/json")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResponseEntity<StringResponse> removeUser(@Valid @RequestBody User user){
|
||||
try{
|
||||
UserImplementation userImplementation = new UserImplementation();
|
||||
|
||||
}catch (Exception e){
|
||||
StringResponse responseS = new StringResponse(e.getMessage());
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(responseS);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
@PostMapping(value = "/update")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
|
|
Loading…
Reference in a new issue