Skip to content

Conversation

@ValeriyaMix
Copy link
Contributor

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

  • Bug Fix
  • New Feature
  • Code Refactor
  • Documentation
  • Test
  • Other

Screenshots

Swagger:

ticket79_1

Controller:

ticket79_2

Successful POST request:

ticket79_5

DB tables created:

ticket79_4

Pull request checklist

Please check if your PR fulfills the following requirements:

* @return Mentee record created successfully.
*/
public Mentee create(final Mentee mentee) {
final Optional<Mentee> menteeExists = menteeRepository.findById(mentee.getId());
Copy link
Collaborator

@dricazenck dricazenck Dec 29, 2025

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)
Copy link
Collaborator

@dricazenck dricazenck Dec 29, 2025

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.

Copy link
Collaborator

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
Copy link
Collaborator

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());
Copy link
Collaborator

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 {
Copy link
Collaborator

@dricazenck dricazenck Dec 29, 2025

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";
Copy link
Collaborator

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 {
Copy link
Collaborator

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 (?, ?)"),
Copy link
Collaborator

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 {
Copy link
Collaborator

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
Copy link
Collaborator

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() {
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants