Changed folder structure
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
|
||||
package com.faf223.expensetrackerfaf.model;
|
||||
|
||||
public class Categories {
|
||||
|
||||
@@ -1,26 +1,43 @@
|
||||
|
||||
package com.faf223.expensetrackerfaf.model;
|
||||
|
||||
import com.faf223.expensetrackerfaf.util.IMoneyTransaction;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "expense")
|
||||
public class Expense implements IMoneyTransaction {
|
||||
|
||||
private int userId;
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "user_id", referencedColumnName = "id")
|
||||
private User user;
|
||||
private int amount;
|
||||
private Categories.ExpenseCategory category;
|
||||
|
||||
public Expense(int userId, int amount, Categories.ExpenseCategory category) {
|
||||
this.userId = userId;
|
||||
public Expense(User user, int amount, Categories.ExpenseCategory category) {
|
||||
this.user = user;
|
||||
this.amount = amount;
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public Expense() {}
|
||||
|
||||
@Override
|
||||
public long getUserId() {
|
||||
return userId;
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUserId(int userId) {
|
||||
this.userId = userId;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getUserId() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,22 +1,39 @@
|
||||
package com.faf223.expensetrackerfaf.model;
|
||||
|
||||
import com.faf223.expensetrackerfaf.util.IMoneyTransaction;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "income")
|
||||
public class Income implements IMoneyTransaction {
|
||||
|
||||
private long userId;
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "user_id", referencedColumnName = "id")
|
||||
private User user;
|
||||
private int amount;
|
||||
private Categories.IncomeCategory category;
|
||||
|
||||
public Income(long userId, int amount, Categories.IncomeCategory category) {
|
||||
this.userId = userId;
|
||||
public Income(User user, int amount, Categories.IncomeCategory category) {
|
||||
this.user = user;
|
||||
this.amount = amount;
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public Income() {}
|
||||
|
||||
@Override
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getUserId() {
|
||||
return userId;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -29,8 +46,8 @@ public class Income implements IMoneyTransaction {
|
||||
return category.getEffectiveName();
|
||||
}
|
||||
|
||||
public void setUserId(long userId) {
|
||||
this.userId = userId;
|
||||
public void setUserId(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public void setAmount(int amount) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
|
||||
package com.faf223.expensetrackerfaf.model;
|
||||
|
||||
public enum Role {
|
||||
|
||||
UNREGISTERED, REGISTERED, ADMIN;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,25 @@
|
||||
|
||||
package com.faf223.expensetrackerfaf.model;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(name = "User")
|
||||
public class User {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id;
|
||||
private String name, email, login, password;
|
||||
private String name;
|
||||
private String email;
|
||||
private String login;
|
||||
private String password;
|
||||
private Role role;
|
||||
|
||||
@OneToMany(mappedBy = "user")
|
||||
private List<Expense> expenses;
|
||||
|
||||
@OneToMany(mappedBy = "user")
|
||||
private List<Income> incomes;
|
||||
|
||||
public User(long id, String name, String email, String login, String password, Role role, List<Expense> expenses, List<Income> incomes) {
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.faf223.expensetrackerfaf.security;
|
||||
|
||||
import com.faf223.expensetrackerfaf.entities.Role;
|
||||
import jakarta.persistence.EnumType;
|
||||
import jakarta.persistence.Enumerated;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class PersonDetails implements UserDetails {
|
||||
|
||||
private final User user;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Role role;
|
||||
|
||||
public PersonDetails(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends GrantedAuthority> getAuthorities() {
|
||||
return List.of(new SimpleGrantedAuthority(role.name()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return user.getPassword();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return user.getUsername();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonExpired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonLocked() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCredentialsNonExpired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
package com.faf223.expensetrackerfaf.util;
|
||||
|
||||
import com.faf223.expensetrackerfaf.model.User;
|
||||
|
||||
public interface IMoneyTransaction {
|
||||
|
||||
User getUser();
|
||||
|
||||
long getUserId();
|
||||
int getAmount();
|
||||
String getCategory();
|
||||
|
||||
Reference in New Issue
Block a user