Should I avoid putting setters in dto?
Here is my business logic.
@Transactional
public PoiIconDto save(PoiIconRequestDto poiIconRequestDto) {
if (poiIconRequestDto.id() != null) {
throw new IllegalArgumentException("Invalid parameter.");
}
String fileName = UUID.randomUUID().toString();
PoiIconRequestDto poiIconRequestDtoComplete = PoiIconRequestDto.builder()
.name(poiIconRequestDto.name())
.iconFileName(fileName)
.file(poiIconRequestDto.file())
.build();
PoiIcon poiIcon = poiIconRepository.save(PoiIconRequestDto.toEntity(poiIconRequestDtoComplete));
if (poiIconRequestDto.file() != null && !poiIconRequestDto.file().isEmpty()) {
savePoiIconFile(poiIcon.getId(), poiIcon.getIconFileName(), poiIconRequestDto.file());
}
return PoiIcon.toDto(poiIcon);
}
As you can see, there is no setter, so I am creating it with a builder to put the fileName in the poiIconRequestDto that is entered as a parameter. I think it is better to use a setter in the above situation.
I wonder if it's common not to use setters for dto in general, or if it's okay to use setters for dto.
The reason I left out the setter is because of the consistency of the data.