feat: add DTO classes
This commit is contained in:
4
pom.xml
4
pom.xml
@@ -36,6 +36,10 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.postgresql</groupId>
|
<groupId>org.postgresql</groupId>
|
||||||
<artifactId>postgresql</artifactId>
|
<artifactId>postgresql</artifactId>
|
||||||
|
|||||||
13
src/main/java/com/example/bankcards/dto/AuthResponse.java
Normal file
13
src/main/java/com/example/bankcards/dto/AuthResponse.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package com.example.bankcards.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class AuthResponse {
|
||||||
|
|
||||||
|
private String token;
|
||||||
|
private String username;
|
||||||
|
private String role;
|
||||||
|
}
|
||||||
17
src/main/java/com/example/bankcards/dto/CardResponse.java
Normal file
17
src/main/java/com/example/bankcards/dto/CardResponse.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package com.example.bankcards.dto;
|
||||||
|
|
||||||
|
import com.example.bankcards.entity.CardStatus;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CardResponse {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private String maskedNumber;
|
||||||
|
private String ownerUsername;
|
||||||
|
private LocalDate expiryDate;
|
||||||
|
private CardStatus status;
|
||||||
|
private BigDecimal balance;
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.example.bankcards.dto;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.*;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CreateCardRequest {
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
@Pattern(regexp = "\\d{16}", message = "Card number must be 16 digits")
|
||||||
|
private String cardNumber;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Long ownerId;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Future
|
||||||
|
private LocalDate expiryDate;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@DecimalMin("0.00")
|
||||||
|
private BigDecimal initialBalance;
|
||||||
|
}
|
||||||
20
src/main/java/com/example/bankcards/dto/ErrorResponse.java
Normal file
20
src/main/java/com/example/bankcards/dto/ErrorResponse.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package com.example.bankcards.dto;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Map;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ErrorResponse {
|
||||||
|
|
||||||
|
private int status;
|
||||||
|
private String message;
|
||||||
|
private LocalDateTime timestamp;
|
||||||
|
private Map<String, String> errors;
|
||||||
|
|
||||||
|
public ErrorResponse(int status, String message) {
|
||||||
|
this.status = status;
|
||||||
|
this.message = message;
|
||||||
|
this.timestamp = LocalDateTime.now();
|
||||||
|
}
|
||||||
|
}
|
||||||
14
src/main/java/com/example/bankcards/dto/LoginRequest.java
Normal file
14
src/main/java/com/example/bankcards/dto/LoginRequest.java
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package com.example.bankcards.dto;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class LoginRequest {
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
private String password;
|
||||||
|
}
|
||||||
20
src/main/java/com/example/bankcards/dto/RegisterRequest.java
Normal file
20
src/main/java/com/example/bankcards/dto/RegisterRequest.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package com.example.bankcards.dto;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.*;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class RegisterRequest {
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
@Size(min = 3, max = 50)
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
@Email
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
@Size(min = 6)
|
||||||
|
private String password;
|
||||||
|
}
|
||||||
19
src/main/java/com/example/bankcards/dto/TransferRequest.java
Normal file
19
src/main/java/com/example/bankcards/dto/TransferRequest.java
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package com.example.bankcards.dto;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.*;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class TransferRequest {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Long fromCardId;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Long toCardId;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@DecimalMin(value = "0.01", message = "Transfer amount must be positive")
|
||||||
|
private BigDecimal amount;
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.example.bankcards.dto;
|
||||||
|
|
||||||
|
import com.example.bankcards.entity.Role;
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UpdateUserRoleRequest {
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Role role;
|
||||||
|
}
|
||||||
13
src/main/java/com/example/bankcards/dto/UserResponse.java
Normal file
13
src/main/java/com/example/bankcards/dto/UserResponse.java
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package com.example.bankcards.dto;
|
||||||
|
|
||||||
|
import com.example.bankcards.entity.Role;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class UserResponse {
|
||||||
|
|
||||||
|
private Long id;
|
||||||
|
private String username;
|
||||||
|
private String email;
|
||||||
|
private Role role;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user