File size: 942 Bytes
b58280e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.example.app.mappers;

import org.springframework.stereotype.Component;

import com.example.app.dtos.UserAccountCreationDto;
import com.example.app.entities.UserAccount;

import lombok.RequiredArgsConstructor;

import org.springframework.security.crypto.password.PasswordEncoder;

@Component
@RequiredArgsConstructor
public class UserAccountCreationMapper implements Mapper<UserAccount, UserAccountCreationDto> {
    private final PasswordEncoder passwordEncoder;

    @Override
    public UserAccount fromDto(UserAccountCreationDto dto) {
        return UserAccount
                .builder()
                .id(null)
                .email(dto.getEmail())
                .passwordHash(passwordEncoder.encode(dto.getPassword()))
                .build();
    }

    @Override
    public UserAccountCreationDto toDto(UserAccount entity) {
        throw new UnsupportedOperationException("Unimplemented method 'toDto'");
    }

}