From 5c5a5a011ff44f51f0c37e3df99dbc4a57998885 Mon Sep 17 00:00:00 2001 From: Alexander Dudkin Date: Thu, 26 Sep 2024 16:58:40 +0300 Subject: [PATCH] fix: add new mapstruct method to map UserDto to send signup response --- .../main/java/dev/earlspilner/users/mapper/UserMapper.java | 4 ++++ .../java/dev/earlspilner/users/service/UserServiceImpl.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/library-api-users-service/src/main/java/dev/earlspilner/users/mapper/UserMapper.java b/library-api-users-service/src/main/java/dev/earlspilner/users/mapper/UserMapper.java index 374d019..2aa6715 100644 --- a/library-api-users-service/src/main/java/dev/earlspilner/users/mapper/UserMapper.java +++ b/library-api-users-service/src/main/java/dev/earlspilner/users/mapper/UserMapper.java @@ -3,6 +3,7 @@ import dev.earlspilner.users.dto.UserDto; import dev.earlspilner.users.model.User; import org.mapstruct.Mapper; +import org.mapstruct.Mapping; /** * @author Alexander Dudkin @@ -11,4 +12,7 @@ public interface UserMapper { User toUserEntity(UserDto userDto); UserDto toUserDto(User user); + + @Mapping(target = "password", ignore = true) + UserDto toRegisterResponse(User user); } diff --git a/library-api-users-service/src/main/java/dev/earlspilner/users/service/UserServiceImpl.java b/library-api-users-service/src/main/java/dev/earlspilner/users/service/UserServiceImpl.java index a427944..740844b 100644 --- a/library-api-users-service/src/main/java/dev/earlspilner/users/service/UserServiceImpl.java +++ b/library-api-users-service/src/main/java/dev/earlspilner/users/service/UserServiceImpl.java @@ -45,7 +45,7 @@ public UserDto saveUser(UserDto dto) { User user = userMapper.toUserEntity(dto); user.setPassword(passwordEncoder.encode(dto.password())); userRepository.save(user); - return userMapper.toUserDto(user); + return userMapper.toRegisterResponse(user); } @Override