#repeating modules
10 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @frail osprey! Please use
/closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
you can create another module containing the common code and dependencies
and then just use that module as a dependency in the other modules
I dont think it is that easy look at my facades
public ClassroomResponseDto addClassroomLayout(ClassroomDto classroomLayoutFromUser) {
Integer columns = classroomLayoutFromUser.columns();
Integer rows = classroomLayoutFromUser.rows();
ValidatorResultFacade validate = classroomValidator.validate(columns, rows);
String message = validate.resultMessage();
if(validate.isValid()) {
repository.save(new Classroom(columns, rows));
}
return new ClassroomResponseDto(message, columns, rows);
}
public StudentDto addStudent(StudentDto studentInputData) {
String firstName = studentInputData.firstName();
String lastName = studentInputData.lastName();
Byte age = studentInputData.age();
ValidatorResultFacade validate = studentValidator.validate(firstName, lastName, age);
if(validate.isValid()) {
repository.save(new Student(firstName, lastName, age));
}
return studentInputData;
}
you could do that (would do exactly the same)
public <T,U> T addElement(T inputData, Function<T,ValidatorResultFacade> validator, Function<T,U> mapper) {
ValidatorResultFacade validate = validator.apply(inputData);
if(validate.isValid()) {
repository.save(mapper.apply(inputData));
}
return inputData;
}
or
public <T,U> T addElement(T inputData, ValidatorResultFacade validate, Function<T,U> mapper) {
if(validate.isValid()) {
repository.save(mapper.apply(inputData));
}
return inputData;
}
or you could add methods to your DTO that convert it to a DB object and to validate it and declare these in a common interface for your DTOs
but aside from that, you can't do much