Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@ services:
build: .
container_name: analytics-app
ports:
- "8080:8080"
- "8083:8080"
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/analytics_db_dev
SPRING_DATASOURCE_USERNAME: postgres
SPRING_DATASOURCE_PASSWORD: 123
SPRING_RABBITMQ_HOST: rabbitmq # RabbitMQ container name or use its IP if needed
SPRING_RABBITMQ_HOST: host.docker.internal
SPRING_RABBITMQ_PORT: 5672
SPRING_RABBITMQ_USERNAME: guest
SPRING_RABBITMQ_PASSWORD: guest
depends_on:
- db
extra_hosts:
- "host.docker.internal:host-gateway"


db:
image: postgres
container_name: analytics-db
ports:
- "5432:5432"
- "5435:5432"
environment:
POSTGRES_DB: analytics_db_dev
POSTGRES_USER: postgres
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Tag(name = "Courier Reports", description = "Endpoints for courier"
+ " analytics and performance metrics")
@RestController
@RequestMapping("/courier-analytics")
@RequiredArgsConstructor
@Slf4j
public final class CourierReportController {

private final CourierAnalyticsService courierAnalyticsService;
Expand All @@ -37,6 +39,8 @@ public final class CourierReportController {
@GetMapping("/delivery-counts")
public ResponseEntity<List<CourierDeliveryCountResponse>> getDeliveryCounts(
@Valid @ModelAttribute final DateRangeRequest dateRange) {
log.info("Request on: /courier-analytics/delivery-counts "
+ "with attributes: {}", dateRange);
List<CourierDeliveryCountResponse> counts = courierAnalyticsService
.getCourierDeliveryCounts(dateRange.getStartDate(),
dateRange.getEndDate());
Expand All @@ -48,6 +52,9 @@ public ResponseEntity<List<CourierDeliveryCountResponse>> getDeliveryCounts(
@GetMapping("/success-rate")
public ResponseEntity<List<CourierSuccessRateResponse>> getSuccessRate(
@Valid @ModelAttribute final DateRangeRequest dateRange) {
log.info("Request on: /courier-analytics/success-rate "
+ "with attributes: {}",
dateRange);
List<CourierSuccessRateResponse> rates = courierAnalyticsService
.getCourierSuccessRate(dateRange.getStartDate(),
dateRange.getEndDate());
Expand All @@ -59,6 +66,8 @@ public ResponseEntity<List<CourierSuccessRateResponse>> getSuccessRate(
@GetMapping("/average-rating")
public ResponseEntity<List<CourierAverageRatingResponse>> getAverageRating(
@Valid @ModelAttribute final DateRangeRequest dateRange) {
log.info("Request on: /courier-analytics/average-rating "
+ "with attributes: {}", dateRange);
List<CourierAverageRatingResponse> ratings = courierAnalyticsService
.getCourierAverageRating(dateRange.getStartDate(),
dateRange.getEndDate());
Expand All @@ -70,6 +79,8 @@ public ResponseEntity<List<CourierAverageRatingResponse>> getAverageRating(
@GetMapping("/performance-report")
public ResponseEntity<List<CourierPerformanceReportResponse>> getReport(
@Valid @ModelAttribute final DateRangeRequest dateRange) {
log.info("Request on: /courier-analytics/performance-report "
+ "with attributes: {}", dateRange);
List<CourierPerformanceReportResponse> report = courierAnalyticsService
.getCourierPerformanceReport(dateRange.getStartDate(),
dateRange.getEndDate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

Expand All @@ -21,6 +22,7 @@
@RequiredArgsConstructor
@RestController
@RequestMapping("/customer-analytics")
@Slf4j
public class CustomerReportController {
private final CustomerAnalyticsService customerAnalyticsService;

Expand All @@ -30,6 +32,8 @@ public class CustomerReportController {
@GetMapping("/top-spenders")
public List<CustomersTopSpendersResponse> getTopSpenders(
@Valid @ModelAttribute final DateRangePaginationRequest request) {
log.info("Request on: /customer-analytics/top-spenders "
+ "with attributes: {}", request);
return customerAnalyticsService.getTopSpenders(
request.getStartDate(),
request.getEndDate(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@
public class FulfillmentReportController {
private final FulfillmentAnalyticsService fulfillmentAnalyticsService;

@Operation(
summary = "Get average time from order placement to shipping",
description = "Returns the average time (in hours) between when"
@Operation(summary = "Get average time from order placement to shipping",
description = "Returns the average time (in hours) between when"
+ " an order was placed and when it was shipped, grouped"
+ " by the specified dimension"
)
+ " by the specified dimension")
@GetMapping("/place-to-ship-time")
public ResponseEntity<List<FulfillmentTimeResponse>> getPlaceToShipTime(
@Valid @ModelAttribute final FulfillmentPlaceToShipRequest req) {

log.info("Request on: /fulfillment-analytics/place-to-ship-time "
+ "with attributes: {}", req);

final List<FulfillmentTimeResponse> reportData =
fulfillmentAnalyticsService.getPlaceToShipTimeResponse(
req.getStartDate(),
Expand All @@ -44,22 +45,22 @@ public ResponseEntity<List<FulfillmentTimeResponse>> getPlaceToShipTime(
return ResponseEntity.ok(reportData);
}


@Operation(
summary = "Get average time from shipping to delivery",
description = "Returns the average time (in hours) between when"
@Operation(summary = "Get average time from shipping to delivery",
description = "Returns the average time (in hours) between when"
+ " an order was shipped and when it was delivered, grouped"
+ " by the specified dimension"
)
+ " by the specified dimension")
@GetMapping("/ship-to-deliver-time")
public ResponseEntity<List<FulfillmentTimeResponse>> getShipToDeliverTime(
@Valid @ModelAttribute final FulfillmentShipToDeliverRequest req) {

log.info("Request on: /fulfillment-analytics/ship-to-deliver-time "
+ "with attributes: {}", req);

final List<FulfillmentTimeResponse> reportData =
fulfillmentAnalyticsService.getShipToDeliverTimeResponse(
req.getStartDate(),
req.getEndDate(),
req.getGroupBy());
fulfillmentAnalyticsService.getShipToDeliverTimeResponse(
req.getStartDate(),
req.getEndDate(),
req.getGroupBy());
return ResponseEntity.ok(reportData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

Expand All @@ -23,6 +24,7 @@
@RequiredArgsConstructor
@RestController
@RequestMapping("/inventory-analytics")
@Slf4j
public class InventoryReportController {
private final InventoryAnalyticsService inventoryAnalyticsService;

Expand All @@ -31,8 +33,10 @@ public class InventoryReportController {
+ "the total value of inventory "
+ "grouped by product categories")
@GetMapping("/value/by-category")
public List<InventoryValueByCategoryResponse>
getInventoryValueByCategory() {
public List<InventoryValueByCategoryResponse> getInventoryValueByCategory(

) {
log.info("Request on: /inventory-analytics/value/by-category");
return inventoryAnalyticsService.getInventoryValueByCategory();
}

Expand All @@ -41,6 +45,8 @@ public class InventoryReportController {
@GetMapping("/low-stock")
public Page<LowStockProductResponse> getLowStockProducts(
@Valid @ModelAttribute final PaginationRequest paginationRequest) {
log.info("Request on: /inventory-analytics/low-stock"
+ " with attributes: {}", paginationRequest);
return inventoryAnalyticsService.getLowStockProducts(
paginationRequest.getPage(),
paginationRequest.getSize());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.springframework.http.ResponseEntity;
import java.util.List;
Expand All @@ -19,56 +20,56 @@
import com.Podzilla.analytics.api.dtos.order.OrderRegionResponse;
import com.Podzilla.analytics.api.dtos.order.OrderStatusResponse;


@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/order-analytics")
public class OrderReportController {
private final OrderAnalyticsService orderAnalyticsService;

@Operation(summary = "Get order counts and revenue by region",
description = "Returns the total number of orders"
+ "placed in each region and their corresponding average revenue")
description = "Returns the total number of orders"
+ "placed in each region and their corresponding average revenue")
@GetMapping("/by-region")
public ResponseEntity<List<OrderRegionResponse>> getOrdersByRegion(
@Valid @ModelAttribute final DateRangeRequest dateRange
) {
List<OrderRegionResponse> ordersByRegion =
orderAnalyticsService.getOrdersByRegion(
dateRange.getStartDate(),
dateRange.getEndDate()
);
@Valid @ModelAttribute final DateRangeRequest dateRange) {
log.info("Request on: /order-analytics/by-region"
+ " with attributes: {}", dateRange);
List<OrderRegionResponse> ordersByRegion = orderAnalyticsService
.getOrdersByRegion(
dateRange.getStartDate(),
dateRange.getEndDate());
return ResponseEntity.ok(ordersByRegion);
}

@Operation(summary = "Get order status counts",
description = "Returns the total number of orders"
+ "in each status (e.g., COMPLETED, SHIPPED, FAILED)")
description = "Returns the total number of orders"
+ "in each status (e.g., COMPLETED, SHIPPED, FAILED)")
@GetMapping("/status-counts")
public ResponseEntity<List<OrderStatusResponse>> getOrdersStatusCounts(
@Valid @ModelAttribute final DateRangeRequest dateRange
) {
List<OrderStatusResponse> orderStatusCounts =
orderAnalyticsService.getOrdersStatusCounts(
dateRange.getStartDate(),
dateRange.getEndDate()
);
@Valid @ModelAttribute final DateRangeRequest dateRange) {
log.info("Request on: /order-analytics/status-counts"
+ " with attributes: {}", dateRange);
List<OrderStatusResponse> orderStatusCounts = orderAnalyticsService
.getOrdersStatusCounts(
dateRange.getStartDate(),
dateRange.getEndDate());
return ResponseEntity.ok(orderStatusCounts);
}

@Operation(summary = "Get order failures",
description = "Returns the percentage of failed orders"
+ "and a list of the failure reasons"
+ "with their corresponding frequency")
description = "Returns the percentage of failed orders"
+ "and a list of the failure reasons"
+ "with their corresponding frequency")
@GetMapping("/failures")
public ResponseEntity<OrderFailureResponse> getOrdersFailures(
@Valid @ModelAttribute final DateRangeRequest dateRange
) {
OrderFailureResponse orderFailures =
orderAnalyticsService.getOrdersFailures(
dateRange.getStartDate(),
dateRange.getEndDate()
);
@Valid @ModelAttribute final DateRangeRequest dateRange) {
log.info("Request on: /order-analytics/failures"
+ " with attributes: {}", dateRange);
OrderFailureResponse orderFailures = orderAnalyticsService
.getOrdersFailures(
dateRange.getStartDate(),
dateRange.getEndDate());
return ResponseEntity.ok(orderFailures);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@RequiredArgsConstructor
@RestController

@Slf4j
@RequestMapping("/product-analytics")
public class ProductReportController {

Expand All @@ -27,6 +28,9 @@ public class ProductReportController {
public ResponseEntity<List<TopSellerResponse>> getTopSellers(
@Valid @ModelAttribute final TopSellerRequest requestDTO) {

log.info("Request on: /product-analytics/top-sellers"
+ " with attributes: {}", requestDTO);

List<TopSellerResponse> topSellersList = productAnalyticsService
.getTopSellers(requestDTO.getStartDate(),
requestDTO.getEndDate(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@
public class ProfitReportController {
private final ProfitAnalyticsService profitAnalyticsService;


@Operation(
summary = "Get profit by product category",
description = "Returns the revenue, cost, and profit metrics "
+ "grouped by product category")
@Operation(summary = "Get profit by product category",
description = "Returns the revenue, cost, and profit metrics "
+ "grouped by product category")
@GetMapping("/by-category")
public ResponseEntity<List<ProfitByCategory>> getProfitByCategory(
@Valid @ModelAttribute final DateRangeRequest request) {

List<ProfitByCategory> profitData =
profitAnalyticsService.getProfitByCategory(
log.info("Request on: /profit-analytics/by-category"
+ " with attributes: {}", request);

List<ProfitByCategory> profitData = profitAnalyticsService
.getProfitByCategory(
request.getStartDate(),
request.getEndDate());
return ResponseEntity.ok(profitData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/revenue-analytics")
Expand All @@ -26,6 +28,8 @@ public class RevenueReportController {
@GetMapping("/summary")
public ResponseEntity<List<RevenueSummaryResponse>> getRevenueSummary(
@Valid @ModelAttribute final RevenueSummaryRequest requestDTO) {
log.info("Request on: /revenue-analytics/summary"
+ " with attributes: {}", requestDTO);
return ResponseEntity.ok(revenueReportService
.getRevenueSummary(requestDTO.getStartDate(),
requestDTO.getEndDate(),
Expand All @@ -35,6 +39,8 @@ public ResponseEntity<List<RevenueSummaryResponse>> getRevenueSummary(
@GetMapping("/by-category")
public ResponseEntity<List<RevenueByCategoryResponse>> getRevenueByCategory(
@Valid @ModelAttribute final RevenueByCategoryRequest requestDTO) {
log.info("Request on: /revenue-analytics/by-category"
+ " with attributes: {}", requestDTO);
List<RevenueByCategoryResponse> summaryList = revenueReportService
.getRevenueByCategory(
requestDTO.getStartDate(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Data;
import io.swagger.v3.oas.annotations.media.Schema;

@ValidDateRange
@ValidPagination
@Getter
@Data
@AllArgsConstructor
public class DateRangePaginationRequest
implements IDateRangeRequest, IPaginationRequest {
Expand Down
Loading