-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create User DB Layer for v9 Migration #12110
Create User DB Layer for v9 Migration #12110
Conversation
4446e09
to
f01e51e
Compare
/** | ||
* Checks if a user exists by its {@code id}. | ||
*/ | ||
private boolean doesUserExist(Integer id) { | ||
assert id != null; | ||
|
||
User user = HibernateUtil.getSessionFactory().getCurrentSession().get(User.class, id); | ||
|
||
return user != null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
String courseId = user.getCourse().getId(); | ||
String email = user.getEmail(); | ||
|
||
if (doesUserExist(courseId, email)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the issue here, will need to split this method back into instructor/student. Validation for both would be different, since course/email is not unique for user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your comment samuel! By splitting back into instructor/student does that mean reverting back to something like this?
// This logic is definitely wrong 😓
if (getInstructor(user.getId()) == null) {
throw new EntityAlreadyExistsException(String.format(ERROR_CREATE_ENTITY_ALREADY_EXISTS, user.toString()));
}
if (getStudent(user.getId()) == null) {
throw new EntityAlreadyExistsException(String.format(ERROR_CREATE_ENTITY_ALREADY_EXISTS, user.toString()));
}
I checked on the EntitiesDb hasExisting methods in both Instructor and Student:
Instructor
Do I follow these above? If I am, may I ask how should I go about doing it for Student
? Noted that course + email is not unique for user too, for this new implementation it would be id
itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, split createUser into createInstructor and createStudent. Validate existence separately for both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, thanks samuel!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last thing, you mentioned that validation will be different for both, are we not using courseId and email anymore? How should I do the validation? A little lost on this part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, but need hasExistngInstructor and hasExistingStudent. courseId and email is only unique for instructor/student, not for users in general.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved! Thanks samuel for clarifying! Hope it's good now!
40e3779
to
c5d913b
Compare
- Split create method into subclass methods - Rename existence method to be uniform
7e5c521
to
7a893f2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the branch and made some minor tweaks, feel free to have a look.
@samuelfangjw Hey samuel, noted on the changes! Thank you! For the Thanks again! 🍻 |
Part of #12048.
Outline of Solution
The User DB layer supports CRUD ops for both Instructor and Student entities.
To add tests in the future.