Skip to content
Snippets Groups Projects
Commit 93e033e8 authored by Raditss's avatar Raditss
Browse files

add gems included in transaction

parent d1da9343
Branches
Tags
No related merge requests found
...@@ -35,4 +35,7 @@ build/ ...@@ -35,4 +35,7 @@ build/
.vscode/ .vscode/
### Mac OS ### ### Mac OS ###
.DS_Store .DS_Store
\ No newline at end of file
### ENV ###
.env
\ No newline at end of file
...@@ -38,21 +38,6 @@ ...@@ -38,21 +38,6 @@
<artifactId>webservices-api</artifactId> <artifactId>webservices-api</artifactId>
<version>4.0.2</version> <version>4.0.2</version>
</dependency> </dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5-20081211</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>3.0.4</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>6.0.13</version>
</dependency>
<dependency> <dependency>
<groupId>io.github.cdimascio</groupId> <groupId>io.github.cdimascio</groupId>
<artifactId>java-dotenv</artifactId> <artifactId>java-dotenv</artifactId>
......
...@@ -7,9 +7,9 @@ import org.toco.entity.transaction_entity; ...@@ -7,9 +7,9 @@ import org.toco.entity.transaction_entity;
public class transaction_model { public class transaction_model {
// insert a transaction // insert a transaction
public void insert (transaction_entity transaction_entity) { public void insert (transaction_entity transaction_entity) {
String sql = "INSERT INTO transaction (user_id, amount, image, status) VALUES (?, ?, ?, ?)"; String sqltrans = "INSERT INTO transaction (user_id, amount, image, status) VALUES (?, ?, ?, ?)";
try (Connection connection = connector.connect() ; try (Connection connection = connector.connect() ;
PreparedStatement command = connection.prepareStatement(sql)) { PreparedStatement command = connection.prepareStatement(sqltrans)) {
command.setInt(1, transaction_entity.getUser_id()); command.setInt(1, transaction_entity.getUser_id());
command.setInt(2, transaction_entity.getAmount()); command.setInt(2, transaction_entity.getAmount());
command.setString(3, transaction_entity.getImage()); command.setString(3, transaction_entity.getImage());
......
...@@ -25,15 +25,19 @@ public class toco_service_impl implements toco_service { ...@@ -25,15 +25,19 @@ public class toco_service_impl implements toco_service {
if (validateApiKey()){ if (validateApiKey()){
userGems_Entity userGems = new userGems_Entity(user_id, gem); userGems_Entity userGems = new userGems_Entity(user_id, gem);
userGems_model userGemsModel = new userGems_model(); userGems_model userGemsModel = new userGems_model();
transaction_model transactionModel = new transaction_model();
transaction_entity tan = new transaction_entity(user_id, gem, "add gems", "ACCEPTED");
if (userGemsModel.checkUser(user_id)) { if (userGemsModel.checkUser(user_id)) {
Integer currentGems = userGemsModel.getUserGems(user_id); Integer currentGems = userGemsModel.getUserGems(user_id);
userGems.setGem(currentGems + gem); userGems.setGem(currentGems + gem);
userGemsModel.update(userGems); userGemsModel.update(userGems);
addLoggging("User with id " + user_id + " added " + gem + " gems"); addLoggging("User with id " + user_id + " added " + gem + " gems");
transactionModel.insert(tan);
return "success"; return "success";
} else { } else {
userGemsModel.insert(userGems); userGemsModel.insert(userGems);
addLoggging("User with id " + user_id + " added " + gem + " gems"); addLoggging("User with id " + user_id + " added " + gem + " gems");
transactionModel.insert(tan);
return "success"; return "success";
} }
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment