add a query, tested
This commit is contained in:
parent
618fa237d0
commit
a50e07535c
|
@ -3,55 +3,55 @@ package database.transaction;
|
|||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@DatabaseTable(tableName = "T_TRANSACTION")
|
||||
public class Transaction {
|
||||
@DatabaseField
|
||||
@DatabaseField(generatedId = true)
|
||||
private int transactionId;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private int userId;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private long transactionDate;
|
||||
@DatabaseField(columnName = "transactionFrom", canBeNull = false)
|
||||
private String sourceAddress;
|
||||
@DatabaseField(columnName = "transactionTo", canBeNull = false)
|
||||
private String destAddress;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private String transactionFrom;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private String transactionTo;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private String transactionHash;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private BigInteger amount;
|
||||
private Double transactionAmount;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private String unit;
|
||||
private String transactionUnit;
|
||||
|
||||
public Transaction() {
|
||||
super();
|
||||
}
|
||||
|
||||
public Transaction(long transactionDate, String sourceAddress, String destAddress, String transactionHash, BigInteger amount, String unit) {
|
||||
public Transaction(long transactionDate, String transactionFrom, String transactionTo, String transactionHash, Double transactionAmount, String transactionUnit) {
|
||||
super();
|
||||
this.transactionDate = transactionDate;
|
||||
this.sourceAddress = sourceAddress;
|
||||
this.destAddress = destAddress;
|
||||
this.transactionFrom = transactionFrom;
|
||||
this.transactionTo = transactionTo;
|
||||
this.transactionHash = transactionHash;
|
||||
this.amount = amount;
|
||||
this.unit = unit;
|
||||
this.transactionAmount = transactionAmount;
|
||||
this.transactionUnit = transactionUnit;
|
||||
}
|
||||
|
||||
public String getSourceAddress() {
|
||||
return sourceAddress;
|
||||
public String getTransactionFrom() {
|
||||
return transactionFrom;
|
||||
}
|
||||
|
||||
public void setSourceAddress(String sourceAddress) {
|
||||
this.sourceAddress = sourceAddress;
|
||||
public void setTransactionFrom(String transactionFrom) {
|
||||
this.transactionFrom = transactionFrom;
|
||||
}
|
||||
|
||||
public String getDestAddress() {
|
||||
return destAddress;
|
||||
return transactionTo;
|
||||
}
|
||||
|
||||
public void setDestAddress(String destAddress) {
|
||||
this.destAddress = destAddress;
|
||||
public void setTransactionTo(String transactionTo) {
|
||||
this.transactionTo = transactionTo;
|
||||
}
|
||||
|
||||
public String getTransactionHash() {
|
||||
|
@ -62,12 +62,12 @@ public class Transaction {
|
|||
this.transactionHash = transactionHash;
|
||||
}
|
||||
|
||||
public BigInteger getAmount() {
|
||||
return amount;
|
||||
public Double getTransactionAmount() {
|
||||
return transactionAmount;
|
||||
}
|
||||
|
||||
public void setAmount(BigInteger amount) {
|
||||
this.amount = amount;
|
||||
public void setTransactionAmount(Double transactionAmount) {
|
||||
this.transactionAmount = transactionAmount;
|
||||
}
|
||||
|
||||
public int getTransactionId() {
|
||||
|
@ -94,12 +94,25 @@ public class Transaction {
|
|||
this.transactionDate = transactionDate;
|
||||
}
|
||||
|
||||
public String getUnit() {
|
||||
return unit;
|
||||
public String getTransactionUnit() {
|
||||
return transactionUnit;
|
||||
}
|
||||
|
||||
public void setUnit(String unit) {
|
||||
this.unit = unit;
|
||||
public void setTransactionUnit(String transactionUnit) {
|
||||
this.transactionUnit = transactionUnit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Transaction{" +
|
||||
"transactionId=" + transactionId +
|
||||
", userId=" + userId +
|
||||
", transactionDate=" + transactionDate +
|
||||
", transactionFrom='" + transactionFrom + '\'' +
|
||||
", transactionTo='" + transactionTo + '\'' +
|
||||
", transactionHash='" + transactionHash + '\'' +
|
||||
", transactionAmount=" + transactionAmount +
|
||||
", transactionUnit='" + transactionUnit + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import com.j256.ormlite.table.DatabaseTable;
|
|||
//Class User which represent an User in the postgresDB
|
||||
@DatabaseTable(tableName = "T_USER")
|
||||
public class User {
|
||||
@DatabaseField
|
||||
@DatabaseField(generatedId = true)
|
||||
private int userId;
|
||||
@DatabaseField(canBeNull = false)
|
||||
private String name;
|
||||
|
@ -127,4 +127,19 @@ public class User {
|
|||
this.approved = approved;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{" +
|
||||
"userId=" + userId +
|
||||
", name='" + name + '\'' +
|
||||
", firstname='" + firstname + '\'' +
|
||||
", email='" + email + '\'' +
|
||||
", password='" + password + '\'' +
|
||||
", creation_date=" + creation_date +
|
||||
", modification_date=" + modification_date +
|
||||
", verified=" + verified +
|
||||
", approved=" + approved +
|
||||
", user_hash='" + user_hash + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,9 +41,26 @@ public class DatabaseTransactionResource {
|
|||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/getLatest", method = RequestMethod.GET, params = {"userId"}, produces = "application/json")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResponseEntity<List<Transaction>> getLatestTransactions(@RequestParam(value = "userId") int userId){
|
||||
try{
|
||||
DatabaseTransactionImplementation databaseTransactionImplementation = new DatabaseTransactionImplementation();
|
||||
List<Transaction> transactionList = databaseTransactionImplementation.getLastTenTransactions(userId);
|
||||
if(!transactionList.isEmpty()){
|
||||
return ResponseEntity.status(HttpStatus.OK).body(transactionList);
|
||||
}else {
|
||||
return new ResponseEntity("Error", HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}catch (Exception e){
|
||||
return new ResponseEntity(e.getMessage(), HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/getAll", method = RequestMethod.GET, params = {"userId"}, produces = "application/json")
|
||||
@ResponseStatus(HttpStatus.OK)
|
||||
public ResponseEntity<List<Transaction>> getAllTransaction(@RequestParam(value = "userId") int userId){
|
||||
public ResponseEntity<List<Transaction>> getAllTransactions(@RequestParam(value = "userId") int userId){
|
||||
try{
|
||||
DatabaseTransactionImplementation databaseTransactionImplementation = new DatabaseTransactionImplementation();
|
||||
List<Transaction> transactionList = databaseTransactionImplementation.getAllUserTransactions(userId);
|
||||
|
|
Loading…
Reference in a new issue