From c7216f02c2c34fc7be5bea37b84fc56368a4498f Mon Sep 17 00:00:00 2001 From: c2038058 <gillj8@cardiff.ac.uk> Date: Fri, 10 Dec 2021 11:49:36 +0000 Subject: [PATCH] LinkUserShop fully logged, other classes changed to no longer use autowiring for attributes --- .../services/BusinessRegisterSaver.java | 2 +- .../services/DashboardStampLoader.java | 9 ++++++--- .../services/GetStampBoardIdFromRewardId.java | 7 +++++-- .../clientproject/services/LinkUserShop.java | 19 +++++++++++++++++-- .../web/restControllers/UpdateStaff.java | 2 +- src/main/resources/database/schema.sql | 1 + 6 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/example/clientproject/services/BusinessRegisterSaver.java b/src/main/java/com/example/clientproject/services/BusinessRegisterSaver.java index 0cb5979..27e6cae 100644 --- a/src/main/java/com/example/clientproject/services/BusinessRegisterSaver.java +++ b/src/main/java/com/example/clientproject/services/BusinessRegisterSaver.java @@ -123,7 +123,7 @@ public class BusinessRegisterSaver { System.out.println(tagsLowerList); business.getBusinessTags().forEach(x-> System.out.println(x)); - linkShop.linkUserShop(shop.getShopId(), userId, 2L); + linkShop.linkUserShop(shop.getShopId(), userId, 2L, session); for(String t: business.getBusinessTags()){ Tags tag; diff --git a/src/main/java/com/example/clientproject/services/DashboardStampLoader.java b/src/main/java/com/example/clientproject/services/DashboardStampLoader.java index c2c264c..9cb3e52 100644 --- a/src/main/java/com/example/clientproject/services/DashboardStampLoader.java +++ b/src/main/java/com/example/clientproject/services/DashboardStampLoader.java @@ -14,13 +14,16 @@ import java.util.*; @Service public class DashboardStampLoader { - @Autowired UsersRepo userRepo; - @Autowired ShopsRepo shopsRepo; - @Autowired UserFavouriteToggle toggleFavourite; + public DashboardStampLoader(UsersRepo userRepo, ShopsRepo shopsRepo, UserFavouriteToggle toggleFavourite) { + this.userRepo = userRepo; + this.shopsRepo = shopsRepo; + this.toggleFavourite = toggleFavourite; + } + public Map<String, Object> getData(int userId) throws Exception { List<Map<String, Object>> combinedInfo = new ArrayList<>(); diff --git a/src/main/java/com/example/clientproject/services/GetStampBoardIdFromRewardId.java b/src/main/java/com/example/clientproject/services/GetStampBoardIdFromRewardId.java index ec93834..0221bbe 100644 --- a/src/main/java/com/example/clientproject/services/GetStampBoardIdFromRewardId.java +++ b/src/main/java/com/example/clientproject/services/GetStampBoardIdFromRewardId.java @@ -9,14 +9,17 @@ import java.util.Map; @Service public class GetStampBoardIdFromRewardId { - @Autowired JdbcTemplate jdbc; + public GetStampBoardIdFromRewardId(JdbcTemplate jdbc) { + this.jdbc = jdbc; + } + /** * @param rewardId the rewardId of the stampBoardId you want to retrieve */ public int getStampBoardId(Integer rewardId){ - String query = "SELECT Stamp_Board_Id FROM rewards WHERE Reward_Id = " + rewardId + ";"; + String query = "SELECT Stamp_Board_Id FROM mydb.rewards WHERE Reward_Id = " + rewardId + ";"; try{ List<Map<String, Object>> rs = jdbc.queryForList(query); diff --git a/src/main/java/com/example/clientproject/services/LinkUserShop.java b/src/main/java/com/example/clientproject/services/LinkUserShop.java index 66c3eee..c458d7d 100644 --- a/src/main/java/com/example/clientproject/services/LinkUserShop.java +++ b/src/main/java/com/example/clientproject/services/LinkUserShop.java @@ -8,8 +8,11 @@ import com.example.clientproject.data.userPermissions.UserPermissions; import com.example.clientproject.data.userPermissions.UserPermissionsRepo; import com.example.clientproject.data.users.Users; import com.example.clientproject.data.users.UsersRepo; +import com.example.clientproject.service.LoggingService; import org.springframework.stereotype.Service; +import javax.servlet.http.HttpSession; + @Service public class LinkUserShop { @@ -17,18 +20,21 @@ public class LinkUserShop { ShopsRepo shopsRepo; AdminTypesRepo adminTypesRepo; UserPermissionsRepo userPermissionsRepo; + LoggingService loggingService; public LinkUserShop(UsersRepo aUsersRepo, ShopsRepo aShopsRepo, AdminTypesRepo anAdminTypesRepo, - UserPermissionsRepo aUserPermissionsRepo){ + UserPermissionsRepo aUserPermissionsRepo, + LoggingService aLoggingService){ userRepo = aUsersRepo; shopsRepo = aShopsRepo; adminTypesRepo = anAdminTypesRepo; userPermissionsRepo = aUserPermissionsRepo; + loggingService = aLoggingService; } - public void linkUserShop(long shopId, long userID, long adminTypeId){ + public void linkUserShop(long shopId, long userID, long adminTypeId, HttpSession session){ try { Users user = userRepo.findById(userID).get(); Shops shop = shopsRepo.getById(shopId); @@ -37,6 +43,15 @@ public class LinkUserShop { UserPermissions link = new UserPermissions(user, shop, adminType); userPermissionsRepo.save(link); + // Log the change + loggingService.logEvent( + "New User Permission", + session, + "New User Permission added for User: " + user.getUserId() + + " with Shop: " + shop.getShopId() + + " with Admin Type: " + adminType.getAdminTypeId() + + " in LinkUserShop.linkUserShop()" + ); }catch(Exception e){ e.printStackTrace(); } diff --git a/src/main/java/com/example/clientproject/web/restControllers/UpdateStaff.java b/src/main/java/com/example/clientproject/web/restControllers/UpdateStaff.java index 943c7b2..aa6226c 100644 --- a/src/main/java/com/example/clientproject/web/restControllers/UpdateStaff.java +++ b/src/main/java/com/example/clientproject/web/restControllers/UpdateStaff.java @@ -63,7 +63,7 @@ public class UpdateStaff { userPermRepo.delete(userPerm); return "USER REMOVED"; }else{ - linkUser.linkUserShop(usf.getShopId(),userId, 1L); + linkUser.linkUserShop(usf.getShopId(),userId, 1L, session); return "OK"; } } diff --git a/src/main/resources/database/schema.sql b/src/main/resources/database/schema.sql index cca3a74..8804064 100644 --- a/src/main/resources/database/schema.sql +++ b/src/main/resources/database/schema.sql @@ -348,3 +348,4 @@ INSERT INTO Events (Event_Name) VALUES ('New Reward'); INSERT INTO Events (Event_Name) VALUES ('New Tag'); INSERT INTO Events (Event_Name) VALUES ('New Shop Tag Link'); INSERT INTO Events (Event_Name) VALUES ('New Social'); +INSERT INTO Events (Event_Name) VALUES ('New User Permission'); -- GitLab