-
Notifications
You must be signed in to change notification settings - Fork 36
Create mentee registration for ad hoc #416
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
base: main
Are you sure you want to change the base?
Create mentee registration for ad hoc #416
Conversation
…languages, mentorship types and previous mentorship types.
… in MenteeMapperTest.
…eeRepository class.
| * @return Mentee record created successfully. | ||
| */ | ||
| public Mentee create(final Mentee mentee) { | ||
| final Optional<Mentee> menteeExists = menteeRepository.findById(mentee.getId()); |
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.
Actually mentee should be null, because it will be returned after is saved. But we need to check the mentorship type and the cycle. This could be another ticket to be solved. Don't need to do it now.
| ( | ||
| mentee_id INTEGER NOT NULL REFERENCES mentees (mentee_id) ON DELETE CASCADE, | ||
| mentorship_type INTEGER NOT NULL REFERENCES mentorship_types (id) ON DELETE CASCADE, | ||
| PRIMARY KEY (mentee_id, mentorship_type) |
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.
Probably we need year on this table, because every year is a different cycle. In the primary key. Or you can create incremental key, and mentee and mentorship type are FK and year must be unique.
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.
We can do in another ticket. So we don't block this one :)
| ); | ||
|
|
||
| -- TABLE Mentee previous mentorship types (join table) | ||
| CREATE TABLE IF NOT EXISTS mentee_previous_mentorship_types |
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.
in this case we don't need to store the information again you can re-use from previous table. Adding the year solve the problem and this table is not necessary.
| final Optional<Mentee> menteeExists = menteeRepository.findById(mentee.getId()); | ||
|
|
||
| if (menteeExists.isPresent()) { | ||
| throw new DuplicatedMemberException(menteeExists.get().getEmail()); |
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.
in this case the exception should be returned the Id, because you are checking the id, not the email.
| import org.springframework.jdbc.core.JdbcTemplate; | ||
|
|
||
|
|
||
| public class MenteeMapperTest { |
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.
The tests don't need to be public ;)
|
|
||
| public class MenteeMapperTest { | ||
|
|
||
| public static final String COLUMN_MENTEE_ID = "mentee_id"; |
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.
if you are not going to re-use the constants in another class, and probably they should be private.
| } | ||
|
|
||
| @Test | ||
| void testMapRowToMenteeSuccessfully() throws Exception { |
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.
Probably it is missing the failure test.
| ); | ||
|
|
||
| verify(jdbc).update( | ||
| eq("INSERT INTO mentee_languages (mentee_id, language_id) VALUES (?, ?)"), |
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.
this SQL are private, probably you could make them package visible and re-use here, so in case the query change you don't need to fix the test.
| import org.springframework.jdbc.core.ResultSetExtractor; | ||
| import org.springframework.jdbc.core.RowMapper; | ||
|
|
||
| public class PostgresMenteeRepositoryTest { |
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.
you can remove public from here also.
| @@ -0,0 +1,8 @@ | |||
|
|
|||
| -- TABLE Mentee mentorship focus areas (join table) | |||
| CREATE TABLE mentee_mentorship_focus_areas | |||
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.
Because you didn't merge yet, you could move this change to your migration 15; Locally you can just remove your database and you won't have any problem ;)
| } | ||
|
|
||
| @Test | ||
| void testCreate() { |
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 don't know if you checked by the integration tests are failing now. Probably it is missing some setup.
Description
Implemented a POST endpoint for creating mentees, including request handling, service-layer logic, and persistence via the repository.
Related Issue
This PR closes the issue #77
Change Type
Screenshots
Swagger:
Controller:
Successful POST request:
DB tables created:
Pull request checklist
Please check if your PR fulfills the following requirements: