I have a small application using Domain Driven Design and now I would like to have an entity with translations.
I have read on the internet that the best practices in Domain Driven Design is to separate the translations from the model but I don't know how to do it.
Here an example of what I have:
@Entity
class Product {
@Id
private String id;
private String name;
private String description;
private BigDecimal price;
private BigDecimal originalPrice;
...
}
@Service
class ProductService {
@Autowired
private ProductRepository productRepository;
public List<Product> getAll() {
return productRepository.findAll();
}
public List<Product> getById(String id) {
return productRepository.findById(id);
}
public List<Product> create(ProductDto productDto) {
Product product = new Product(
productDto.getName(),
productDto.getDescription(),
productDto.getPrice(),
productDto.getOriginalPrice()
);
return productRepository.save(product);
}
}
Then my questions are:
Imagine I am receiving the translations in the product DTO and I would like to know how to do it.
Thanks and appreciate your help.
I would recommend to differ your domain model from your data model. While in your domain model you really will not care about any translations and it will look like as what you've proposed, your data model may look different:
Then inside of your repository youl will map from your domain model to your data model, while you will take
languageId
from some application settings.