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
New Endpoint for Daily Orders and Sales Summary by Branch and bug fixed #109
Pull Request: New Endpoint for Daily Orders and Sales Summary by Branch
Title
Add Endpoint for Retrieving Daily Orders and Sales Summary by Branch
Description
This pull request introduces a new endpoint in our pharmacy POS system to provide daily orders and sales summary for a specific branch over the past year. The endpoint will allow the frontend and DevOps teams to retrieve the required data for analysis and reporting purposes.
Endpoint Details
URL:/api/v1/sales-summary/daily
HTTP Method: GET
Parameters:
branchId (required): The ID of the branch for which the data is requested.
Request Example
GET [/api/v1/sales-summary/daily?branchId=12345 HTTP/1.1](http://localhost:8079/lifepill/v1/branch-summary/sales-summary/daily)
Host: localhost:8079
Response Format
The response will be a JSON array of objects, where each object contains:
Created a new endpoint in the sales controller to handle GET requests for daily sales summaries.
Added service methods to fetch and process the sales data from the database.
2. Service Layer
Added methods in the service layer to aggregate daily sales data for the specified branch.
Implemented logic to handle data retrieval, transformation, and response formatting.
3. Data Layer
Modified repository methods to support fetching daily orders and sales data.
Ensured efficient querying to handle potentially large datasets.
Code Snippets
Controller
@RestController
@RequestMapping("/api/v1/sales-summary")
public class SalesSummaryController {
@Autowired
private SalesSummaryService salesSummaryService;
@GetMapping("/daily")
public ResponseEntity<ApiResponse<List<DailySalesSummaryDTO>>> getDailySalesSummary(@RequestParam long branchId) {
List<DailySalesSummaryDTO> dailySalesSummary = salesSummaryService.getDailySalesSummary(branchId);
ApiResponse<List<DailySalesSummaryDTO>> response = new ApiResponse<>(200, "SUCCESS", dailySalesSummary);
return ResponseEntity.ok(response);
}
}
Service
@Service
public class SalesSummaryService {
@Autowired
private SalesRepository salesRepository;
public List<DailySalesSummaryDTO> getDailySalesSummary(long branchId) {
List<DailySalesSummary> dailySalesSummaries = salesRepository.findDailySalesSummaryByBranchId(branchId);
return dailySalesSummaries.stream()
.map(this::convertToDTO)
.collect(Collectors.toList());
}
private DailySalesSummaryDTO convertToDTO(DailySalesSummary dailySalesSummary) {
return new DailySalesSummaryDTO(dailySalesSummary.getDate(), dailySalesSummary.getOrders(), dailySalesSummary.getSales());
}
}
Repository
public interface SalesRepository extends JpaRepository<Sale, Long> {
@Query("SELECT new com.example.DailySalesSummary(s.date, COUNT(s.id), SUM(s.totalAmount)) " +
"FROM Sale s WHERE s.branchId = :branchId GROUP BY s.date")
List<DailySalesSummary> findDailySalesSummaryByBranchId(@Param("branchId") long branchId);
}
DTO
public class DailySalesSummaryDTO {
private String date;
private long orders;
private double sales;
public DailySalesSummaryDTO(String date, long orders, double sales) {
this.date = date;
this.orders = orders;
this.sales = sales;
}
// Getters and setters
}
Testing
Unit Tests: Added unit tests for the new service methods to ensure correct data processing and transformation.
Integration Tests: Added integration tests for the new endpoint to validate end-to-end functionality.
Manual Testing: Performed manual testing using Postman to verify the endpoint's response format and data accuracy.
Issue
[Issue #107 ]: Request for New Endpoint: Daily Orders and Sales for a Branch
[Issue #108 ]: Request for New Endpoint: Daily Orders and Sales for a Branch
Checklist
[x] Implemented new endpoint in the controller.
[x] Added service methods for data aggregation.
[x] Updated repository methods for data retrieval.
[x] Added DTO for response formatting.
[x] Tested the endpoint using unit and integration tests.
[x] Verified response format and data accuracy through manual testing.
Conclusion
This pull request adds a valuable endpoint to our system, enabling frontend and DevOps teams to retrieve daily orders and sales summaries for specific branches efficiently. The implementation follows best practices and has been thoroughly tested to ensure reliability and performance.
Best regards,
Pramitha Jayasooriya,
Backend Developer at LifePill,
https://pramithamj.me
Pull Request: New Endpoint for Daily Orders and Sales Summary by Branch
Title
Add Endpoint for Retrieving Daily Orders and Sales Summary by Branch
Description
This pull request introduces a new endpoint in our pharmacy POS system to provide daily orders and sales summary for a specific branch over the past year. The endpoint will allow the frontend and DevOps teams to retrieve the required data for analysis and reporting purposes.
Endpoint Details
/api/v1/sales-summary/daily
branchId
(required): The ID of the branch for which the data is requested.Request Example
Response Format
The response will be a JSON array of objects, where each object contains:
date
: The date in YYYY-MM-DD format.orders
: The number of orders for that date.sales
: The total sales amount for that date.Example Response
Changes Made
1. New Endpoint Implementation
2. Service Layer
3. Data Layer
Code Snippets
Controller
Service
Repository
DTO
Testing
Issue
[Issue #107 ]: Request for New Endpoint: Daily Orders and Sales for a Branch [Issue #108 ]: Request for New Endpoint: Daily Orders and Sales for a Branch
Checklist
Conclusion
This pull request adds a valuable endpoint to our system, enabling frontend and DevOps teams to retrieve daily orders and sales summaries for specific branches efficiently. The implementation follows best practices and has been thoroughly tested to ensure reliability and performance.
Best regards,
Pramitha Jayasooriya, Backend Developer at LifePill, https://pramithamj.me