Added some migrations and Simple GUI

This commit is contained in:
maciejrusek
2026-04-26 16:18:14 +02:00
parent c1af31f41d
commit e5c5670ac5
16 changed files with 283 additions and 29 deletions

18
src/main/java/main.java Normal file
View File

@@ -0,0 +1,18 @@
import ui.MyFrame;
import java.awt.*;
public class main {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new MyFrame();
}
});
}
}

View File

@@ -5,16 +5,26 @@ import java.util.Objects;
public class Task {
private User user;
private String title;
private String description;
private Date createdAt;
public Task(String title, String description) {
public Task(String title, String description, User user) {
this.user = user;
this.title = title;
this.description = description;
this.createdAt = new Date();
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String getTitle() {
return title;
}
@@ -43,6 +53,7 @@ public class Task {
public String toString() {
return "Task{" +
"title='" + title + '\'' +
", user='" + user + '\'' +
", description='" + description + '\'' +
", createdAt=" + createdAt +
'}';
@@ -52,11 +63,11 @@ public class Task {
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
Task task = (Task) o;
return Objects.equals(title, task.title) && Objects.equals(description, task.description) && Objects.equals(createdAt, task.createdAt);
return Objects.equals(user, task.user) && Objects.equals(title, task.title) && Objects.equals(description, task.description) && Objects.equals(createdAt, task.createdAt);
}
@Override
public int hashCode() {
return Objects.hash(title, description, createdAt);
return Objects.hash(user, title, description, createdAt);
}
}

View File

@@ -0,0 +1,9 @@
package repository.impl;
import repository.TaskRepository;
public class TaskRepositoryImpl {
}

View File

@@ -0,0 +1,32 @@
package service;
import models.User;
import java.util.Optional;
public class UserService {
public Optional<User> login(String username, String password) {
try {
return Optional.empty();
} catch (Exception e) {
System.out.println(e.getMessage());
return Optional.empty();
}
}
public Optional<User> register(String username, String password) {
try {
return Optional.empty();
} catch (Exception e) {
System.out.println(e.getMessage());
return Optional.empty();
}
}
}

View File

@@ -0,0 +1,43 @@
package ui;
import models.User;
import service.UserService;
import util.Session;
import javax.swing.*;
import java.awt.*;
import java.util.Optional;
public class LoginPanel {
public static JPanel getLoginPanel(){
JPanel panel = new JPanel();
JTextField username = new JTextField("Login");
JPasswordField password = new JPasswordField("Password");
panel.add(username, BorderLayout.NORTH);
panel.add(password, BorderLayout.CENTER);
JButton loginButton = new JButton("Login");
loginButton.addActionListener(e -> {
String usernameText = username.getText();
String passwordText = new String(password.getPassword());
UserService service = new UserService();
Optional<User> user = service.login(usernameText, passwordText);
if (user.isPresent()) {
Session.getInstance().setUser(user.get());
// Wywoałeni jakeiś metody która by mi zmieniała Panele
// Home
} else {
JOptionPane.showMessageDialog(panel, "User not found");
}
});
panel.add(loginButton, BorderLayout.SOUTH);
return panel;
}
}

View File

@@ -0,0 +1,36 @@
package ui;
import javax.swing.*;
import java.awt.*;
public class MyFrame extends JFrame {
JPanel mainPanel = new JPanel(new CardLayout());
public void changePanel(String panel) {
}
public MyFrame() {
super("Todo App");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(800, 600);
setLocation(50, 50);
setLayout(new CardLayout());
JPanel startPanel = new JPanel();
JButton loginButton = new JButton("Login");
startPanel.add(loginButton);
mainPanel.add(startPanel, "start");
mainPanel.add(LoginPanel.getLoginPanel(), "login");
loginButton.addActionListener(e -> {
CardLayout cl = (CardLayout)mainPanel.getLayout();
cl.show(mainPanel, "login");
});
add(mainPanel);
setVisible(true);
}
}

View File

@@ -0,0 +1,28 @@
package util;
import models.User;
public class Session {
private static Session instance;
private User user;
public static Session getInstance() {
if (instance == null) {
instance = new Session();
}
return instance;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public void logout() {
this.user = null;
}
}