Fix: Mapper set null fields for DTO and Entity.
This commit is contained in:
parent
faf9e0f7af
commit
e86ab4f209
8 changed files with 39 additions and 10 deletions
|
|
@ -43,16 +43,16 @@ dependencies {
|
||||||
implementation("org.springframework.boot:spring-boot-starter-web")
|
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||||
implementation("org.flywaydb:flyway-core")
|
implementation("org.flywaydb:flyway-core")
|
||||||
implementation("org.flywaydb:flyway-database-postgresql:11.10.0")
|
implementation("org.flywaydb:flyway-database-postgresql:11.10.0")
|
||||||
implementation("org.mapstruct:mapstruct:1.6.3")
|
|
||||||
implementation("org.postgresql:postgresql")
|
implementation("org.postgresql:postgresql")
|
||||||
implementation("org.apache.logging.log4j:log4j-api:2.22.1")
|
implementation("org.apache.logging.log4j:log4j-api:2.22.1")
|
||||||
implementation("org.apache.logging.log4j:log4j-core:2.22.1")
|
implementation("org.apache.logging.log4j:log4j-core:2.22.1")
|
||||||
implementation("org.slf4j:slf4j-api:2.0.13")
|
implementation("org.slf4j:slf4j-api:2.0.13")
|
||||||
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.6")
|
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.6")
|
||||||
runtimeOnly("org.apache.logging.log4j:log4j-slf4j-impl:2.22.1")
|
runtimeOnly("org.apache.logging.log4j:log4j-slf4j-impl:2.22.1")
|
||||||
annotationProcessor("org.mapstruct:mapstruct-processor:1.6.3")
|
|
||||||
compileOnly("org.projectlombok:lombok")
|
compileOnly("org.projectlombok:lombok")
|
||||||
annotationProcessor("org.projectlombok:lombok")
|
annotationProcessor("org.projectlombok:lombok")
|
||||||
|
annotationProcessor("org.mapstruct:mapstruct-processor:1.6.3")
|
||||||
|
implementation("org.mapstruct:mapstruct:1.6.3")
|
||||||
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||||
testImplementation("org.springframework.security:spring-security-test")
|
testImplementation("org.springframework.security:spring-security-test")
|
||||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,12 @@
|
||||||
package ru.team58.profileservice.controller.schemes;
|
package ru.team58.profileservice.controller.schemes;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
public class CreateUserRequest {
|
public class CreateUserRequest {
|
||||||
String username;
|
String username;
|
||||||
String firstName;
|
String firstName;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,12 @@
|
||||||
package ru.team58.profileservice.controller.schemes;
|
package ru.team58.profileservice.controller.schemes;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
public class GetUserResponse {
|
public class GetUserResponse {
|
||||||
String username;
|
String username;
|
||||||
String firstName;
|
String firstName;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,14 @@
|
||||||
package ru.team58.profileservice.controller.schemes;
|
package ru.team58.profileservice.controller.schemes;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
public class UpdateUserRequest {
|
public class UpdateUserRequest {
|
||||||
UUID id;
|
UUID id;
|
||||||
String username;
|
String username;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,14 @@
|
||||||
package ru.team58.profileservice.controller.schemes;
|
package ru.team58.profileservice.controller.schemes;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Builder
|
||||||
public class UserResponse {
|
public class UserResponse {
|
||||||
UUID id;
|
UUID id;
|
||||||
String username;
|
String username;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package ru.team58.profileservice.mapper;
|
package ru.team58.profileservice.mapper;
|
||||||
|
|
||||||
import org.mapstruct.Mapper;
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.Mapping;
|
||||||
import org.mapstruct.factory.Mappers;
|
import org.mapstruct.factory.Mappers;
|
||||||
import ru.team58.profileservice.controller.schemes.CreateUserRequest;
|
import ru.team58.profileservice.controller.schemes.CreateUserRequest;
|
||||||
import ru.team58.profileservice.controller.schemes.GetUserResponse;
|
import ru.team58.profileservice.controller.schemes.GetUserResponse;
|
||||||
|
|
@ -9,12 +10,13 @@ import ru.team58.profileservice.controller.schemes.UserResponse;
|
||||||
import ru.team58.profileservice.persistence.entity.UserEntity;
|
import ru.team58.profileservice.persistence.entity.UserEntity;
|
||||||
import ru.team58.profileservice.service.UserDTO;
|
import ru.team58.profileservice.service.UserDTO;
|
||||||
|
|
||||||
@Mapper
|
@Mapper(componentModel = "spring")
|
||||||
public interface UserMapper {
|
public interface UserMapper {
|
||||||
UserMapper INSTANCE = Mappers.getMapper(UserMapper.class);
|
UserMapper INSTANCE = Mappers.getMapper(UserMapper.class);
|
||||||
|
|
||||||
UserDTO toUserDTO(UserEntity entity);
|
UserDTO toUserDTO(UserEntity entity);
|
||||||
UserDTO toUserDTO(UpdateUserRequest request);
|
UserDTO toUserDTO(UpdateUserRequest request);
|
||||||
|
@Mapping(target = "id", ignore = true)
|
||||||
UserDTO toUserDTO(CreateUserRequest request);
|
UserDTO toUserDTO(CreateUserRequest request);
|
||||||
|
|
||||||
UserEntity toUserEntity(UserDTO dto);
|
UserEntity toUserEntity(UserDTO dto);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package ru.team58.profileservice.persistence.entity;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.*;
|
import lombok.*;
|
||||||
import ru.team58.profileservice.service.UserDTO;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
|
@ -17,17 +16,17 @@ public class UserEntity {
|
||||||
@Id
|
@Id
|
||||||
@Column(name = "id", nullable = false)
|
@Column(name = "id", nullable = false)
|
||||||
@GeneratedValue(strategy = GenerationType.UUID)
|
@GeneratedValue(strategy = GenerationType.UUID)
|
||||||
UUID id;
|
private UUID id;
|
||||||
|
|
||||||
@Column(name = "username", nullable = false)
|
@Column(name = "username", nullable = false)
|
||||||
String username;
|
private String username;
|
||||||
|
|
||||||
@Column(name = "firstName", nullable = false)
|
@Column(name = "firstName", nullable = false)
|
||||||
String firstName;
|
private String firstName;
|
||||||
|
|
||||||
@Column(name = "lastName", nullable = false)
|
@Column(name = "lastName", nullable = false)
|
||||||
String lastName;
|
private String lastName;
|
||||||
|
|
||||||
@Column(name = "email", nullable = false)
|
@Column(name = "email", nullable = false)
|
||||||
String email;
|
private String email;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ spring.datasource.url=jdbc:postgresql://localhost:5432/userdb
|
||||||
spring.datasource.username=userdb
|
spring.datasource.username=userdb
|
||||||
spring.datasource.password=1205
|
spring.datasource.password=1205
|
||||||
|
|
||||||
spring.jpa.hibernate.ddl-auto=update
|
spring.jpa.hibernate.ddl-auto=validate
|
||||||
|
|
||||||
## Flyway
|
## Flyway
|
||||||
spring.flyway.enabled=true
|
spring.flyway.enabled=true
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue