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

Refactor Item Details Endpoints and Clean Code #101

Closed PramithaMJ closed 6 months ago

PramithaMJ commented 6 months ago

Pull Request: Refactor Item Details Endpoints and Clean Code

Title

Refactor Item Details Endpoints and Clean Code

Description

This pull request refactors the /get-item-all-details-by-id/{id} and /get-item-details-by-id/{id} endpoints to provide consistent response structures and includes various code cleanups to remove duplication and enhance maintainability.

Changes Made

Endpoint Changes:

  1. Refactor /get-item-all-details-by-id/{id} Endpoint:

    • Modified the response structure to include the itemGetAllResponseDTO wrapper.
    • Kept existing structures for itemCategoryDTO, supplierDTO, and supplierCompanyDTO.
  2. Refactor /get-item-details-by-id/{id} Endpoint:

    • Modified the response structure to include the itemGetAllResponseDTO wrapper.
    • Kept the existing structure for itemCategoryDTO.

Code Cleanups:

Example Changes in Code:

Controller Methods:

@GetMapping(path = "/get-item-all-details-by-id/{id}")
public ResponseEntity<StandardResponse> getItemAllDetailsById(@PathVariable(value = "id") long itemId) {
    ItemGetAllResponseDTO itemGetAllResponseDTO = itemService.getAllDetailsItemById(itemId);
    return new ResponseEntity<>(
            new StandardResponse(200, "Success", itemGetAllResponseDTO),
            HttpStatus.OK
    );
}

@GetMapping(path = "/get-item-details-by-id/{id}")
public ResponseEntity<StandardResponse> getItemWithCategoryById(@PathVariable(value = "id") long itemId) {
    ItemGetAllResponseDTO itemGetAllResponseDTO = itemService.getItemById(itemId);
    return new ResponseEntity<>(
            new StandardResponse(200, "Success", itemGetAllResponseDTO),
            HttpStatus.OK
    );
}

Sample Responses:

/get-item-all-details-by-id/{id} Response:

{
    "code": 200,
    "message": "Success",
    "data": {
        "itemGetAllResponseDTO": {
            "itemId": 316,
            // Other item details
        },
        "itemCategoryDTO": {
            // Category details
        },
        "supplierDTO": {
            // Supplier details
        },
        "supplierCompanyDTO": {
            // Supplier company details
        }
    }
}

/get-item-details-by-id/{id} Response:

{
    "code": 200,
    "message": "Success",
    "data": {
        "itemGetAllResponseDTO": {
            "itemId": 316,
            "brandId": 0,
            "itemName": "new2",
            "sellingPrice": 100.0,
            // Other item details
        },
        "itemCategoryDTO": {
            // Category details
        }
    }
}

Impact Analysis

Affected Files

Test Plan

Related Issues

Checklist

Conclusion

This pull request refactors the item details endpoints to ensure consistent response structures and includes various code cleanups for better maintainability. Please review the changes and provide feedback or approval for merging.

Best regards,
Pramitha Jayasooriya Backend Developer at LifePill https://pramithamj.me

sonarcloud[bot] commented 6 months ago

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarCloud