I have a DTO class with Object lists. Im running simple CRUD operations with my project. Since i need to fill bunch of comboboxes with one service, i just created a comboboxFillerDTO. Basically, what i can do is to call findAll() method for all object lists from their own repositories but i'm wondering if there is a better way to do it?
This my DTO;
@Data
public class ComboboxDTO {
private List<ContactType> contactTypes;
private List<DocumentType> documentTypes;
private List<EnvironmentType> environmentTypes;
private List<RelationType> relationTypes;
private List<SpecificationType> specificationTypes;
private List<ProjectStatus> projectStatuses;
}
Every object from the DTO is an Entity and my repository interfaces uses JpaRepository for basic operations.
Is there a better way other than calling findAll() for every Entity repository in my Service layer?
This is the only way i think is to call repository.findAll() for every object list in DTO;
@Service
@Qualifier("ComboboxFillerService")
public class ComboboxFillerService implements IComboboxFillerService {
private final ContactTypeRepository contactTypeRepository;
private final DocumentTypeRepository documentTypeRepository;
.
.
.
@Autowired
public ComboboxFillerService(ContactTypeRepository contactTypeRepository, DocumentTypeRepository documentTypeRepository...) {
this.contactTypeRepository = contactTypeRepository;
this.documentTypeRepository = documentTypeRepository;
.
.
.
}
@Override
public ComboboxDTO fillComboBox() {
ComboboxDTO dto = new ComboboxDTO();
dto.setContactTypes(contactTypeRepository.findAll());
dto.setDocumentTypes(documentTypeRepository.findAll());
.
.
.
return dto;
}
}
Aucun commentaire:
Enregistrer un commentaire