-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add modelmapper and configure it to convert EmployeeRequest to Employee
- Loading branch information
1 parent
b8a0c6c
commit 9ddbc5d
Showing
21 changed files
with
164 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
hr-microservice-hexagonal/src/main/java/com/example/hr/config/ModelMapperConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.example.hr.config; | ||
|
||
import org.modelmapper.Converter; | ||
import org.modelmapper.ModelMapper; | ||
import org.modelmapper.TypeMap; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import com.example.hr.domain.Employee; | ||
import com.example.hr.domain.MoneyCurrency; | ||
import com.example.hr.dto.EmployeeRequest; | ||
|
||
/** | ||
* | ||
* @author Binnur Kurt <binnur.kurt@gmail.com> | ||
* | ||
*/ | ||
@Configuration | ||
public class ModelMapperConfig { | ||
|
||
@Bean | ||
public ModelMapper modelMapper() { | ||
ModelMapper mapper = new ModelMapper(); | ||
TypeMap<EmployeeRequest, Employee> employeeRequestToEmployeeTypeMap = mapper.getTypeMap(EmployeeRequest.class, | ||
Employee.class); | ||
if (employeeRequestToEmployeeTypeMap == null) { | ||
employeeRequestToEmployeeTypeMap = mapper.createTypeMap(EmployeeRequest.class, Employee.class); | ||
} | ||
employeeRequestToEmployeeTypeMap.setProvider(provisionRequest -> { | ||
var employeeRequest = EmployeeRequest.class.cast(provisionRequest.getSource()); | ||
String[] tokens = employeeRequest.getFullname().split("\\w+"); | ||
return new Employee.Builder(employeeRequest.getIdentity()).fullname(tokens[0], tokens[1]) | ||
.iban(employeeRequest.getIban()).salary(employeeRequest.getSalary(), MoneyCurrency.TL) | ||
.birthYear(employeeRequest.getBirthYear()).fulltime(employeeRequest.isFulltime()) | ||
.department(employeeRequest.getDepartment()).photo(employeeRequest.getPhoto()).build(); | ||
}); | ||
return mapper; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
hr-microservice-hexagonal/src/main/java/com/example/hr/dto/EmployeeResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
hr-microservice-hexagonal/src/main/java/com/example/hr/dto/RestErrorMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.