Life-Pill / pharmacy-pos-main-backend

The Pharmacy POS System Backend is the server-side component of our comprehensive pharmacy management software. It is developed using Spring Boot, Java, Spring Security ,and Microservices Architecture
Apache License 2.0
5 stars 3 forks source link

Fix Issue with Employer ID in Response #93

Closed PramithaMJ closed 6 months ago

PramithaMJ commented 6 months ago

Pull Request: Fix Issue with Employer ID in Response

Issue Description

92 ID retrieve issue in create cashier endpoint

Problem

When creating a new cashier using the API endpoint /employers/save-without-image, the response always returns an ID of 0 instead of the expected unique ID for the newly created cashier.

Steps to Reproduce

  1. Send a POST request to the /employers/save-without-image endpoint with valid data for creating a new cashier.
  2. Receive the response from the server.
  3. Check the ID field in the response.

Expected Behavior

The response should include a unique ID for the newly created cashier, allowing us to identify and work with this cashier in subsequent operations.

Actual Behavior

The ID in the response is consistently returning as 0, which does not match the expected behavior.

Example response:

{
    "code": 201,
    "message": "successfully saved",
    "data": {
        "employerId": 299,
        "branchId": 3,
        "employerNicName": "mfwefgewgwegwegama",
        "employerFirstName": "John",
        "employerLastName": "Doe",
        "employerPassword": "secretpassword",
        "employerEmail": "john@,mm,,mdnfkjfnewefewfwefwewjkfwke.com",
        "employerPhone": "+1234567890",
        "employerAddress": "123 Main Street",
        "employerSalary": 50000.0,
        "employerNic": "ABCD1234",
        "gender": "MALE",
        "dateOfBirth": "1990-01-01T00:00:00.000+00:00",
        "role": "OWNER",
        "pin": 1234,
        "activeStatus": true
    }
}

Solution

Changes Made

Affected Files

Test Plan

Example Test

A test to ensure that the correct ID is returned:

@Test
void createEmployerWithoutImage_ReturnsCorrectId() throws Exception {
    EmployerDTO employerDTO = new EmployerDTO();
    employerDTO.setEmployerFirstName("John");
    employerDTO.setEmployerLastName("Doe");
    // set other properties...

    when(employerService.saveEmployerWithoutImage(any(EmployerDTO.class))).thenReturn(employerDTO);

    mockMvc.perform(post("/employers/save-without-image")
            .contentType(MediaType.APPLICATION_JSON)
            .content(asJsonString(employerDTO)))
            .andExpect(status().isOk())
            .andExpect(jsonPath("$.data.employerId").value(employerDTO.getEmployerId()));
}

Screenshots

Before Fix

Screenshot 2024-05-16 at 12 05 01 AM

After Fix

Screenshot 2024-05-16 at 12 05 20 AM

Conclusion

This pull request addresses the issue of the response always returning an ID of 0 when creating a new cashier. The fix ensures that the correct unique ID is included in the response, improving the functionality and reliability of the /employers/save-without-image endpoint.

Your feedback on this fix and any suggestions for further improvement are highly appreciated.

Best regards,
Pramitha Jauasooriya Backend Developer at LifePill