Move models and add DTOs
This commit is contained in:
10
pom.xml
10
pom.xml
@@ -15,6 +15,7 @@
|
||||
<description>banking-service</description>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<modelmapper.version>3.1.1</modelmapper.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@@ -29,6 +30,15 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.modelmapper</groupId>
|
||||
<artifactId>modelmapper</artifactId>
|
||||
<version>${modelmapper.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package net.kapcake.bankingservice.domain;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Data;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
public class Balance {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
private Long amount;
|
||||
private String currency;
|
||||
@Enumerated(EnumType.STRING)
|
||||
private BalanceType type;
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package net.kapcake.bankingservice.domain;
|
||||
|
||||
public enum PaymentStatus {
|
||||
EXECUTED
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.kapcake.bankingservice.domain;
|
||||
package net.kapcake.bankingservice.model.domain;
|
||||
|
||||
public enum AccountStatus {
|
||||
ENABLED,
|
||||
@@ -0,0 +1,19 @@
|
||||
package net.kapcake.bankingservice.model.domain;
|
||||
|
||||
import jakarta.validation.constraints.DecimalMin;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
public class BalanceDTO {
|
||||
private Long id;
|
||||
@NotNull
|
||||
@DecimalMin(value = "0", inclusive = false)
|
||||
private BigDecimal amount;
|
||||
@NotNull
|
||||
private Currency currency;
|
||||
@NotNull
|
||||
private BalanceType type;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.kapcake.bankingservice.domain;
|
||||
package net.kapcake.bankingservice.model.domain;
|
||||
|
||||
public enum BalanceType {
|
||||
END_OF_DAY,
|
||||
@@ -0,0 +1,25 @@
|
||||
package net.kapcake.bankingservice.model.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class BankAccountDTO {
|
||||
private Long id;
|
||||
@NotBlank
|
||||
private String accountNumber;
|
||||
@NotEmpty
|
||||
@JsonIgnore
|
||||
private List<UserDTO> users;
|
||||
@NotBlank
|
||||
private String accountName;
|
||||
@NotEmpty
|
||||
private List<BalanceDTO> balances;
|
||||
@NotNull
|
||||
private AccountStatus status;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package net.kapcake.bankingservice.model.domain;
|
||||
|
||||
public enum Currency {
|
||||
EUR,
|
||||
USD,
|
||||
GBP
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package net.kapcake.bankingservice.model.domain;
|
||||
|
||||
import jakarta.validation.constraints.DecimalMin;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class PaymentDTO {
|
||||
private Long id;
|
||||
@NotNull
|
||||
@DecimalMin(value = "0", inclusive = false)
|
||||
private BigDecimal amount;
|
||||
@NotNull
|
||||
private Currency currency;
|
||||
@NotNull
|
||||
private Long giverAccount;
|
||||
@NotNull
|
||||
private String beneficiaryAccountNumber;
|
||||
@NotNull
|
||||
private String beneficiaryName;
|
||||
private String communication;
|
||||
private Date creationDate;
|
||||
private PaymentStatus status;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package net.kapcake.bankingservice.model.domain;
|
||||
|
||||
public enum PaymentStatus {
|
||||
EXECUTED
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package net.kapcake.bankingservice.model.domain;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UserDTO {
|
||||
private Long id;
|
||||
@NotEmpty
|
||||
private String username;
|
||||
private String street;
|
||||
private Integer number;
|
||||
private String numberExtension;
|
||||
private Integer postalCode;
|
||||
private String country;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package net.kapcake.bankingservice.model.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.kapcake.bankingservice.model.domain.BalanceType;
|
||||
import net.kapcake.bankingservice.model.domain.Currency;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
public class Balance {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
private BigDecimal amount;
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Currency currency;
|
||||
@Enumerated(EnumType.STRING)
|
||||
private BalanceType type;
|
||||
}
|
||||
@@ -1,21 +1,26 @@
|
||||
package net.kapcake.bankingservice.domain;
|
||||
package net.kapcake.bankingservice.model.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.kapcake.bankingservice.model.domain.AccountStatus;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@Getter
|
||||
@Setter
|
||||
public class BankAccount {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String accountNumber;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(
|
||||
joinColumns = {@JoinColumn(name = "BANK_ACCOUNT_ID", nullable = false)},
|
||||
inverseJoinColumns = {@JoinColumn(name = "USER_ID", nullable = false)}
|
||||
)
|
||||
private List<User> users;
|
||||
@Column(nullable = false)
|
||||
private String accountName;
|
||||
@@ -1,24 +1,30 @@
|
||||
package net.kapcake.bankingservice.domain;
|
||||
package net.kapcake.bankingservice.model.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.kapcake.bankingservice.model.domain.Currency;
|
||||
import net.kapcake.bankingservice.model.domain.PaymentStatus;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@Getter
|
||||
@Setter
|
||||
public class Payment {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
@Column(nullable = false)
|
||||
private Long amount;
|
||||
private BigDecimal amount;
|
||||
@Column(nullable = false)
|
||||
private String currency;
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Currency currency;
|
||||
@ManyToOne
|
||||
@JoinColumn(nullable = false)
|
||||
private BankAccount giver;
|
||||
private BankAccount giverAccount;
|
||||
@Column(nullable = false)
|
||||
private String beneficiaryAccountNumber;
|
||||
@Column(nullable = false)
|
||||
@@ -1,10 +1,12 @@
|
||||
package net.kapcake.bankingservice.domain;
|
||||
package net.kapcake.bankingservice.model.entities;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(name = "BANKING_USER")
|
||||
@Accessors(chain = true)
|
||||
@@ -14,7 +16,6 @@ public class User {
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String username;
|
||||
@Column(nullable = false)
|
||||
@@ -24,4 +25,7 @@ public class User {
|
||||
private String numberExtension;
|
||||
private Integer postalCode;
|
||||
private String country;
|
||||
@ManyToMany(mappedBy = "users", fetch = FetchType.EAGER)
|
||||
private List<BankAccount> bankAccounts;
|
||||
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
package net.kapcake.bankingservice.repositories;
|
||||
|
||||
import net.kapcake.bankingservice.domain.BankAccount;
|
||||
import net.kapcake.bankingservice.model.entities.BankAccount;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface BankAccountRepository extends JpaRepository<BankAccount, Long> {
|
||||
List<BankAccount> findAllByUsers_username(String username);
|
||||
Optional<List<BankAccount>> findAllByUsers_username(String username);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.kapcake.bankingservice.repositories;
|
||||
|
||||
import net.kapcake.bankingservice.domain.Payment;
|
||||
import net.kapcake.bankingservice.model.entities.Payment;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface PaymentRepository extends JpaRepository<Payment, Long> {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.kapcake.bankingservice.repositories;
|
||||
|
||||
import net.kapcake.bankingservice.domain.User;
|
||||
import net.kapcake.bankingservice.model.entities.User;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.kapcake.bankingservice.security;
|
||||
|
||||
import net.kapcake.bankingservice.domain.User;
|
||||
import net.kapcake.bankingservice.model.entities.User;
|
||||
import net.kapcake.bankingservice.repositories.UserRepository;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package net.kapcake.bankingservice.services;
|
||||
|
||||
import net.kapcake.bankingservice.domain.BankAccount;
|
||||
import net.kapcake.bankingservice.model.entities.BankAccount;
|
||||
import net.kapcake.bankingservice.model.entities.User;
|
||||
import net.kapcake.bankingservice.repositories.BankAccountRepository;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@Service
|
||||
public class AccountService {
|
||||
private final BankAccountRepository bankAccountRepository;
|
||||
|
||||
@@ -16,6 +17,6 @@ public class AccountService {
|
||||
}
|
||||
|
||||
public List<BankAccount> getAccounts(User user) {
|
||||
return bankAccountRepository.findAllByUsers_username(user.getUsername());
|
||||
return bankAccountRepository.findAllByUsers_username(user.getUsername()).orElse(Collections.emptyList());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user