Fix bug with create user and refactor
This commit is contained in:
+1
-1
@@ -33,6 +33,6 @@ build/
|
||||
.vscode/
|
||||
|
||||
###API_KEYS###
|
||||
src/main/java/com/Samsung/TaskTraker_Server/Repository/API_KEYS.java
|
||||
src/main/java/com/Samsung/TaskTraker_Server/API_KEYS.java
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.Samsung.TaskTraker_Server.Repository;
|
||||
package com.Samsung.TaskTraker_Server.Models;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package com.Samsung.TaskTraker_Server.Repository;
|
||||
package com.Samsung.TaskTraker_Server.Models;
|
||||
import java.util.Objects;
|
||||
|
||||
public class User {
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.Samsung.TaskTraker_Server.Repository;
|
||||
|
||||
import com.Samsung.TaskTraker_Server.API_KEYS;
|
||||
import com.Samsung.TaskTraker_Server.Models.Task;
|
||||
import com.Samsung.TaskTraker_Server.Models.User;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
|
||||
@@ -32,11 +36,18 @@ public class DataBase {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void SaveUser(User user) throws SQLException {
|
||||
public User SaveUser(String login, String password) throws SQLException {
|
||||
PreparedStatement saveUser_stmt = connection.prepareStatement("INSERT INTO users(login, password) VALUE (?, ?)");
|
||||
saveUser_stmt.setString(1, user.getLogin());
|
||||
saveUser_stmt.setString(2, user.getPassword());
|
||||
saveUser_stmt.setString(1, login);
|
||||
saveUser_stmt.setString(2, password);
|
||||
saveUser_stmt.executeUpdate();
|
||||
|
||||
PreparedStatement findID = connection.prepareStatement("SELECT id FROM users WHERE login = ?");
|
||||
findID.setString(1, login);
|
||||
ResultSet newID = findID.executeQuery();
|
||||
|
||||
newID.next();
|
||||
return new User(newID.getInt(1), login, password);
|
||||
}
|
||||
|
||||
public void AddTask(Task task, User user) throws SQLException {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.Samsung.TaskTraker_Server.Repository;
|
||||
|
||||
import com.Samsung.TaskTraker_Server.Models.User;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
|
||||
@@ -29,9 +31,7 @@ public class UserRepository {
|
||||
if(find != null)
|
||||
return null;
|
||||
|
||||
User user = new User(0, login, password);
|
||||
|
||||
DataBase.getInstance().SaveUser(user);
|
||||
User user = DataBase.getInstance().SaveUser(login, password);
|
||||
if(UserCache.size() >= MAX_COUNT_USERS_IN_CACHE)
|
||||
UserCache.remove(0);
|
||||
UserCache.add(user);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.Samsung.TaskTraker_Server;
|
||||
|
||||
import com.Samsung.TaskTraker_Server.Models.Task;
|
||||
import com.Samsung.TaskTraker_Server.Models.User;
|
||||
import com.Samsung.TaskTraker_Server.Repository.*;
|
||||
import org.springframework.boot.ExitCodeGenerator;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
||||
Reference in New Issue
Block a user