catmonthmodel
This commit is contained in:
@@ -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,9 +33,9 @@ public class StatisticsController {
|
||||
}
|
||||
|
||||
@RequestMapping(value = STATISTICS_VOLUME, method = RequestMethod.GET, produces = "application/json")
|
||||
public ResponseEntity<CatMonthModel<Integer>> getMonthlySalesVolume(HttpServletRequest request,
|
||||
@RequestParam(value = PARAM_SESSION) UUID session,
|
||||
@RequestParam(value = PARAM_EMAIL) String email) {
|
||||
public ResponseEntity<CategoryMonthModel<Integer>> getMonthlySalesVolume(HttpServletRequest request,
|
||||
@RequestParam(value = PARAM_SESSION) UUID session,
|
||||
@RequestParam(value = PARAM_EMAIL) String email) {
|
||||
logRequest(request);
|
||||
if (!sessionService.isAdmin(session, email)) {
|
||||
log.warn("Invalid session requesting Admin {}", session);
|
||||
@@ -46,9 +45,9 @@ public class StatisticsController {
|
||||
}
|
||||
|
||||
@RequestMapping(value = STATISTICS_REVENUE, method = RequestMethod.GET, produces = "application/json")
|
||||
public ResponseEntity<CatMonthModel<Integer>> getMonthlyRevenue(HttpServletRequest request,
|
||||
@RequestParam(value = PARAM_SESSION) UUID token,
|
||||
@RequestParam(value = PARAM_EMAIL) String email) {
|
||||
public ResponseEntity<CategoryMonthModel<Integer>> getMonthlyRevenue(HttpServletRequest request,
|
||||
@RequestParam(value = PARAM_SESSION) UUID token,
|
||||
@RequestParam(value = PARAM_EMAIL) String email) {
|
||||
logRequest(request);
|
||||
if (!sessionService.isAdmin(token, email)) {
|
||||
log.warn("Invalid session requesting Admin {}", token);
|
||||
|
||||
@@ -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...");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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,9 +30,9 @@ public class StatisticsServiceImpl implements StatisticsService {
|
||||
}
|
||||
|
||||
//returns Map<unix milli timestamp, Map<Category, T>>
|
||||
private <T extends Number> CatMonthModel<T> getMonthCategoryMap(Function<OrderItem, T> mappingFunction,
|
||||
BinaryOperator<T> reduceFunction,
|
||||
T defaultValue) {
|
||||
private <T extends Number> CategoryMonthModel<T> getMonthCategoryMap(Function<OrderItem, T> mappingFunction,
|
||||
BinaryOperator<T> reduceFunction,
|
||||
T defaultValue) {
|
||||
Map<String, Map<Long, T>> map = new TreeMap<>();
|
||||
for (ArticleCategory value : ArticleCategory.values()) {
|
||||
map.put(value.loc, 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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user