Skip to content
Snippets Groups Projects
Commit c7216f02 authored by Joshua Gill's avatar Joshua Gill
Browse files

LinkUserShop fully logged, other classes changed to no longer use autowiring for attributes

parent 79364654
No related branches found
No related tags found
2 merge requests!114LoggingService service class, new method to add a log to the "Logs" table when...,!107Issue complete
......@@ -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;
......
......@@ -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<>();
......
......@@ -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);
......
......@@ -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();
}
......
......@@ -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";
}
}
......
......@@ -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');
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment