catmonthmodel

This commit is contained in:
Tim
2026-03-10 19:58:26 +01:00
parent bf4b95dce9
commit d3becdef72
5 changed files with 18 additions and 28 deletions

View File

@@ -1,6 +1,6 @@
package de.htwsaar.webshop.controller;
import de.htwsaar.webshop.model.CatMonthModel;
import de.htwsaar.webshop.model.CategoryMonthModel;
import de.htwsaar.webshop.model.OrderStatus;
import de.htwsaar.webshop.service.SessionService;
import de.htwsaar.webshop.service.StatisticsService;
@@ -12,7 +12,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@@ -34,7 +33,7 @@ public class StatisticsController {
}
@RequestMapping(value = STATISTICS_VOLUME, method = RequestMethod.GET, produces = "application/json")
public ResponseEntity<CatMonthModel<Integer>> getMonthlySalesVolume(HttpServletRequest request,
public ResponseEntity<CategoryMonthModel<Integer>> getMonthlySalesVolume(HttpServletRequest request,
@RequestParam(value = PARAM_SESSION) UUID session,
@RequestParam(value = PARAM_EMAIL) String email) {
logRequest(request);
@@ -46,7 +45,7 @@ public class StatisticsController {
}
@RequestMapping(value = STATISTICS_REVENUE, method = RequestMethod.GET, produces = "application/json")
public ResponseEntity<CatMonthModel<Integer>> getMonthlyRevenue(HttpServletRequest request,
public ResponseEntity<CategoryMonthModel<Integer>> getMonthlyRevenue(HttpServletRequest request,
@RequestParam(value = PARAM_SESSION) UUID token,
@RequestParam(value = PARAM_EMAIL) String email) {
logRequest(request);

View File

@@ -16,17 +16,10 @@ public class ExpiredSessionDeleteJob {
private final SessionService sessionService;
/**
* Constructor of the class
* @param sessionService used in the class
*/
public ExpiredSessionDeleteJob(SessionService sessionService) {
this.sessionService = sessionService;
}
/**
* Method running the job calling the referring service method
*/
@Scheduled(fixedRate = MILLIS_TO_WEEK)
public void runFixedRateTask() {
log.info("Deleting expired sessions...");

View File

@@ -9,6 +9,6 @@ import java.util.Map;
@Getter
@Setter
@AllArgsConstructor
public class CatMonthModel<T extends Number> {
public class CategoryMonthModel<T extends Number> {
Map<String, Map<Long, T>> catMonthMap;
}

View File

@@ -1,16 +1,14 @@
package de.htwsaar.webshop.service;
import de.htwsaar.webshop.model.CatMonthModel;
import de.htwsaar.webshop.model.CategoryMonthModel;
import de.htwsaar.webshop.model.OrderStatus;
import java.util.Map;
import java.util.List;
import java.util.UUID;
public interface StatisticsService {
CatMonthModel<Integer> getSalesVolume();
CategoryMonthModel<Integer> getSalesVolume();
CatMonthModel<Integer> getSalesRevenue();
CategoryMonthModel<Integer> getSalesRevenue();
Map<OrderStatus, Integer> getOrderStatus();

View File

@@ -1,7 +1,7 @@
package de.htwsaar.webshop.service.impl;
import de.htwsaar.webshop.model.ArticleCategory;
import de.htwsaar.webshop.model.CatMonthModel;
import de.htwsaar.webshop.model.CategoryMonthModel;
import de.htwsaar.webshop.model.OrderStatus;
import de.htwsaar.webshop.repository.entities.OrderItem;
import de.htwsaar.webshop.service.ArticleService;
@@ -30,7 +30,7 @@ public class StatisticsServiceImpl implements StatisticsService {
}
//returns Map<unix milli timestamp, Map<Category, T>>
private <T extends Number> CatMonthModel<T> getMonthCategoryMap(Function<OrderItem, T> mappingFunction,
private <T extends Number> CategoryMonthModel<T> getMonthCategoryMap(Function<OrderItem, T> mappingFunction,
BinaryOperator<T> reduceFunction,
T defaultValue) {
Map<String, Map<Long, T>> map = new TreeMap<>();
@@ -49,16 +49,16 @@ public class StatisticsServiceImpl implements StatisticsService {
})
);
});
return new CatMonthModel<>(map);
return new CategoryMonthModel<>(map);
}
@Override
public CatMonthModel<Integer> getSalesVolume() {
public CategoryMonthModel<Integer> getSalesVolume() {
return getMonthCategoryMap(OrderItem::getAmount, Integer::sum, 0);
}
@Override
public CatMonthModel<Integer> getSalesRevenue() {
public CategoryMonthModel<Integer> getSalesRevenue() {
return getMonthCategoryMap(item -> item.getArticle().getPrice100(), Integer::sum, 0);
}