Skip to content

Commit

Permalink
Added user mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
PavloSliepchenko committed May 4, 2024
1 parent 3357baa commit f15c7ea
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/java/com/example/usersapi/config/MapperConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.usersapi.config;

import org.mapstruct.InjectionStrategy;
import org.mapstruct.NullValueCheckStrategy;

@org.mapstruct.MapperConfig(
componentModel = "spring",
injectionStrategy = InjectionStrategy.CONSTRUCTOR,
nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
implementationPackage = "<PACKAGE_NAME>.impl"
)
public class MapperConfig {
}
17 changes: 17 additions & 0 deletions src/main/java/com/example/usersapi/mapper/UserMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.usersapi.mapper;

import com.example.usersapi.config.MapperConfig;
import com.example.usersapi.dto.CreateUserRequestDto;
import com.example.usersapi.dto.UserResponseDto;
import com.example.usersapi.model.User;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

@Mapper(config = MapperConfig.class)
public interface UserMapper {
@Mapping(target = "birthDate", source = "birthDate", dateFormat = "dd/MM/yyyy")
User toModel(CreateUserRequestDto requestDto);

@Mapping(target = "birthDate", source = "birthDate", dateFormat = "dd/MM/yyyy")
UserResponseDto toDto(User user);
}

0 comments on commit f15c7ea

Please sign in to comment.