I'm working on an Android project. I get some DTO from REST API (e.g. CompanyDTO, DepartmentDTO,ProjectDTO) , and I want to persist them in my database.
These DTO may have has-a relations: for example, in each CompanyDTO we have a list of DepartmentDTO.
So I already created all converters that convert DTO to database entities (CompanyEntity, DepartmentEntity, etc.). But I have a problem, for example:
for (CompanyDTO companyDTO : apiDTOS.getCompanyDTO()) {
CompanyEntity companyEntity = CompanyConverter.convert(companyDTO);
companyRepository.insert(companyEntity);
for (DepartmentDTO departmentDTO : companyDTO.getDepartmentDTO) {
DepartmentEntity departmentEntity = DepartmentConverter.convert(departmentDTO);
departmentRepository.insert(departmentEntity );
// here we have more imbrications
}
}
I don't think it's good in the view of design, I want to know if there is a best practice to do this kind of conversions ? Thank you.
Aucun commentaire:
Enregistrer un commentaire