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/
.vscode/
### Mac OS ###
.DS_Store
\ No newline at end of file
.DS_Store
### ENV ###
.env
\ No newline at end of file
......@@ -38,21 +38,6 @@
<artifactId>webservices-api</artifactId>
<version>4.0.2</version>
</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>
<groupId>io.github.cdimascio</groupId>
<artifactId>java-dotenv</artifactId>
......
......@@ -7,9 +7,9 @@ import org.toco.entity.transaction_entity;
public class transaction_model {
// insert a transaction
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() ;
PreparedStatement command = connection.prepareStatement(sql)) {
PreparedStatement command = connection.prepareStatement(sqltrans)) {
command.setInt(1, transaction_entity.getUser_id());
command.setInt(2, transaction_entity.getAmount());
command.setString(3, transaction_entity.getImage());
......
......@@ -25,15 +25,19 @@ public class toco_service_impl implements toco_service {
if (validateApiKey()){
userGems_Entity userGems = new userGems_Entity(user_id, gem);
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)) {
Integer currentGems = userGemsModel.getUserGems(user_id);
userGems.setGem(currentGems + gem);
userGemsModel.update(userGems);
addLoggging("User with id " + user_id + " added " + gem + " gems");
transactionModel.insert(tan);
return "success";
} else {
userGemsModel.insert(userGems);
addLoggging("User with id " + user_id + " added " + gem + " gems");
transactionModel.insert(tan);
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