@RequestMapping(value = "/transactionservice/transaction/{id}", method = RequestMethod.PUT) public ResponseEntity addTransaction(@PathVariable("id") Long id, @RequestBody String body) { Transaction aTransaction = gson.fromJson(body, Transaction.class); aTransaction.setId(id); long result = transactionService.addTransaction(aTransaction); if (result >= 0) { return new ResponseEntity<String>("{ \"status\": \"ok\" }", HttpStatus.OK); } else { return new ResponseEntity<String>( "Oops! You tried to feed me a duplicate transaction_id. Updating is not implemented, yet.", HttpStatus.UNPROCESSABLE_ENTITY); } }
public static Transaction getTransaction(int transactionID) { Transaction transaction = new Transaction(); try { String query = "select * from transaction_table where transaction_id=?"; PreparedStatement preparedStatement = connection.prepareStatement(query); preparedStatement.setInt(1, transactionID); ResultSet rs = preparedStatement.executeQuery(); if (rs.next()) { transaction.setId(rs.getInt("transaction_id")); transaction.setType(rs.getBoolean("type")); transaction.setCategory(rs.getString("category")); transaction.setDescription(rs.getString("description")); transaction.setAmount(rs.getFloat("amount")); transaction.setTransactionDate(rs.getString("transaction_date")); transaction.setAccountBalance(rs.getFloat("account_balance")); } } catch (SQLException e) { e.printStackTrace(); } return transaction; }
public void submitTransaction(View view) { Calendar currentDate = Calendar.getInstance(); TransactionService TransactionService = new TransactionService(); TransactionService.getTransactions(); EditText item = (EditText) findViewById(R.id.Item); EditText amount = (EditText) findViewById(R.id.Amount); EditText employee = (EditText) findViewById(R.id.Employee); String product = item.getText().toString(); String amountPurchased = amount.getText().toString(); String employeeOnDuty = employee.getText().toString(); Transaction newTransaction = new Transaction(); newTransaction.setId(UUID.randomUUID()); newTransaction.setItem(product); newTransaction.setAmount(amountPurchased); newTransaction.setEmployee(employeeOnDuty); newTransaction.setDate(currentDate.toString()); TransactionService.setTransaction(newTransaction); Intent manageTransactionintent = new Intent(this, manageTrnasactions.class); startActivity(manageTransactionintent); }
public static List<Transaction> getAllTransactions(int businessID) { List<Transaction> transactions = new ArrayList<Transaction>(); try { String query = "select * from transaction_table where business_id=?"; PreparedStatement preparedStatement = connection.prepareStatement(query); preparedStatement.setInt(1, businessID); ResultSet rs = preparedStatement.executeQuery(); while (rs.next()) { Transaction transaction = new Transaction(); transaction.setId(rs.getInt("transaction_id")); transaction.setType(rs.getBoolean("type")); transaction.setCategory(rs.getString("category")); transaction.setDescription(rs.getString("description")); transaction.setAmount(rs.getFloat("amount")); transaction.setTransactionDate(rs.getString("transaction_date")); transaction.setAccountBalance(rs.getFloat("account_balance")); transactions.add(transaction); } } catch (SQLException e) { e.printStackTrace(); } return transactions; }