diff --git a/src/main/java/com/example/clientproject/services/RecommendationGenerator.java b/src/main/java/com/example/clientproject/services/RecommendationGenerator.java index 320f171c28fe0b91c0c44a29ce4912b9add86af2..1fc7207e6672e7a922b9b111aef1ee98b5a4718a 100644 --- a/src/main/java/com/example/clientproject/services/RecommendationGenerator.java +++ b/src/main/java/com/example/clientproject/services/RecommendationGenerator.java @@ -22,22 +22,20 @@ import java.util.*; @Service public class RecommendationGenerator { - public JWTUtils jwtUtils; - public UserFavouriteToggle favouriteToggle; - public StampBoardsRepo stampBoardsRepo; - public UserStampBoardsRepo userStampBoardsRepo; - - @Autowired + JWTUtils jwtUtils; + UserFavouriteToggle favouriteToggle; + StampBoardsRepo stampBoardsRepo; + UserStampBoardsRepo userStampBoardsRepo; UsersRepo usersRepo; - - @Autowired ShopsRepo shopsRepo; - public RecommendationGenerator(JWTUtils jwt, UserFavouriteToggle uft, StampBoardsRepo sbr, UserStampBoardsRepo usbr){ - jwtUtils = jwt; - favouriteToggle = uft; - stampBoardsRepo = sbr; - userStampBoardsRepo = usbr; + public RecommendationGenerator(JWTUtils jwtUtils, UserFavouriteToggle favouriteToggle, StampBoardsRepo stampBoardsRepo, UserStampBoardsRepo userStampBoardsRepo, UsersRepo usersRepo, ShopsRepo shopsRepo) { + this.jwtUtils = jwtUtils; + this.favouriteToggle = favouriteToggle; + this.stampBoardsRepo = stampBoardsRepo; + this.userStampBoardsRepo = userStampBoardsRepo; + this.usersRepo = usersRepo; + this.shopsRepo = shopsRepo; } public List<Shops> getRecommendations(HttpSession session, List<Shops> shopsToRecommend) throws Exception { diff --git a/src/main/java/com/example/clientproject/services/ShopActiveService.java b/src/main/java/com/example/clientproject/services/ShopActiveService.java index 9c7ed39f7d9a89735d8ac115058908508407bf1a..8ec00b70ce19b1a66c564ca6dad53ba0667d73d1 100644 --- a/src/main/java/com/example/clientproject/services/ShopActiveService.java +++ b/src/main/java/com/example/clientproject/services/ShopActiveService.java @@ -1,25 +1,31 @@ package com.example.clientproject.services; +import com.example.clientproject.service.LoggingService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Service; +import javax.servlet.http.HttpSession; import java.util.List; import java.util.Map; @Service public class ShopActiveService { - @Autowired JdbcTemplate jdbc; + LoggingService loggingService; + public ShopActiveService(JdbcTemplate jdbc, LoggingService loggingService) { + this.jdbc = jdbc; + this.loggingService = loggingService; + } /** * @param shopId - uses shopId to select which shop will have its active field checked * @return - an int of Shop activity 1 = active || 0 = not active */ public int isShopActive(Integer shopId){ - String query = "SELECT Shop_Active FROM shops WHERE Shop_Id = " + shopId + ";"; + String query = "SELECT Shop_Active FROM mydb.shops WHERE Shop_Id = " + shopId + ";"; try{ List<Map<String, Object>> rs = jdbc.queryForList(query); @@ -35,10 +41,18 @@ public class ShopActiveService { * @param active - will either be 1 or 0 and will update shops "Shop_Active" field accordingly */ - public void updateShopActive(Integer shopId, Integer active){ + public void updateShopActive(Integer shopId, Integer active, HttpSession session){ if(active == 0 || active == 1){ //only allows active values of 0 or 1 - String query = "UPDATE shops SET Shop_Active = " + active + " WHERE Shop_Id = " + shopId + ";"; + String query = "UPDATE mydb.shops SET Shop_Active = " + active + " WHERE Shop_Id = " + shopId + ";"; jdbc.execute(query); + // Log the change + loggingService.logEvent( + "Shop Update", + session, + "Update to Shop: " + shopId + + " with field: Shop_Active with value: " + active + + " in ShopActiveService.updateShopActive()" + ); } } diff --git a/src/main/java/com/example/clientproject/web/restControllers/ToggleShopActive.java b/src/main/java/com/example/clientproject/web/restControllers/ToggleShopActive.java index 49629f6948e99e57d90e8b7dd3e1ef0a31d64938..8ee236a6b88f20a08f027e45ff990c7ae4048955 100644 --- a/src/main/java/com/example/clientproject/web/restControllers/ToggleShopActive.java +++ b/src/main/java/com/example/clientproject/web/restControllers/ToggleShopActive.java @@ -45,9 +45,9 @@ public class ToggleShopActive { if (shopPermissionLevel == 2 || shopPermissionLevel == 3) { System.out.println("shop is being deleted"); if(shopActiveService.isShopActive(shopId) == 0){//if shop is currently un-active - shopActiveService.updateShopActive(shopId, 1);//enables shop + shopActiveService.updateShopActive(shopId, 1, session);//enables shop } else if(shopActiveService.isShopActive(shopId) == 1){//if shop is currently active - shopActiveService.updateShopActive(shopId, 0);//disables shop + shopActiveService.updateShopActive(shopId, 0, session);//disables shop } else { System.out.println("an error has occured updating shop activity, shop may potentially have an active value other than 1 or 0"); } diff --git a/src/test/java/com/example/clientproject/data/ShopActivityTests.java b/src/test/java/com/example/clientproject/data/ShopActivityTests.java index 0bcd3f054ff2799950772ecc7870561c5023785e..32ebb627dc0cfbf1bde6989bcfc89804c2b33d45 100644 --- a/src/test/java/com/example/clientproject/data/ShopActivityTests.java +++ b/src/test/java/com/example/clientproject/data/ShopActivityTests.java @@ -37,7 +37,7 @@ public class ShopActivityTests { @Test public void activeShopsDecreasedBy1AfterMethodCalled(){ List<Shops> activeShopsListBeforeChange = shopsRepo.findActiveShops(); - shopActiveService.updateShopActive(6, 0); + shopActiveService.updateShopActive(6, 0, null); List<Shops> activeShopsListAfterChange = shopsRepo.findActiveShops(); assertEquals(activeShopsListBeforeChange.size()-1, activeShopsListAfterChange.size()); //size after change should be equal to size before change minus one