Refactor CourseSerivce
Currently the CourseService class has a few issues.
- The method findUser tries finding a user, else it creates a user.
Methods called
find
should not change state in the database only read it. Hence we should rename itfindOrCreateUser
to make this explicit. - This snippet:
Role role = null;
switch (csvUser.getRole()) {
case ROLE_ASSISTANT:
role = new Assistant(staff, course);
break;
case ROLE_TEACHER:
role = new Teacher(staff, course);
break;
case ROLE_MANAGER:
role = new Manager(staff, course);
break;
default:
throw new IllegalStateException("Unexpected value: " + csvUser.getRole());
}
Should become a method on CsvUserHelper
and could be unit tested there.
-
This save seems redundant since staff will be saved at the end of the method regardless.
-
All the repository fields can be marked final, if we create a constructor assigning them and mark that constructor as
@Autowired
instead of the individual fields.
Edited by Liam Clark