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

UserSocialSave fully logged

parent 11230f19
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
package com.example.clientproject.services; package com.example.clientproject.services;
import com.example.clientproject.data.socials.SocialsRepo; import com.example.clientproject.data.socials.SocialsRepo;
import com.example.clientproject.service.LoggingService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.servlet.http.HttpSession;
@Service @Service
public class UserSocialSave { public class UserSocialSave {
@Autowired
JdbcTemplate jdbc; JdbcTemplate jdbc;
@Autowired
SocialsRepo socialRepo; SocialsRepo socialRepo;
LoggingService loggingService;
public UserSocialSave(JdbcTemplate jdbc, SocialsRepo socialRepo, LoggingService loggingService) {
this.jdbc = jdbc;
this.socialRepo = socialRepo;
this.loggingService = loggingService;
}
private String queryGenerator(int shopId, String socialPlatform, String socialName){ private String queryGenerator(int shopId, String socialPlatform, String socialName){
String query; String query;
...@@ -23,23 +30,59 @@ public class UserSocialSave { ...@@ -23,23 +30,59 @@ public class UserSocialSave {
return query; return query;
} }
public void updateSocials(UserSocialDTO usDTO){ public void updateSocials(UserSocialDTO usDTO, HttpSession session){
int shopId = usDTO.getShopId(); int shopId = usDTO.getShopId();
String query; String query;
query = queryGenerator(shopId, "Instagram", usDTO.getInstagram()); query = queryGenerator(shopId, "Instagram", usDTO.getInstagram());
jdbc.execute(query); jdbc.execute(query);
// Log the changes
loggingService.logEvent(
"Social Updated",
session,
"Social updated for Shop Id: " + shopId +
" in UserSocialSave.updateSocials()"
);
query = queryGenerator(shopId, "Facebook", usDTO.getFacebook()); query = queryGenerator(shopId, "Facebook", usDTO.getFacebook());
jdbc.execute(query); jdbc.execute(query);
// Log the changes
loggingService.logEvent(
"Social Updated",
session,
"Social updated for Shop Id: " + shopId +
" in UserSocialSave.updateSocials()"
);
query = queryGenerator(shopId, "Twitter", usDTO.getTwitter()); query = queryGenerator(shopId, "Twitter", usDTO.getTwitter());
jdbc.execute(query); jdbc.execute(query);
// Log the changes
loggingService.logEvent(
"Social Updated",
session,
"Social updated for Shop Id: " + shopId +
" in UserSocialSave.updateSocials()"
);
query = queryGenerator(shopId, "TikTok", usDTO.getTiktok()); query = queryGenerator(shopId, "TikTok", usDTO.getTiktok());
jdbc.execute(query); jdbc.execute(query);
query = "UPDATE Shops SET Shop_Website = '" + // Log the changes
loggingService.logEvent(
"Social Updated",
session,
"Social updated for Shop Id: " + shopId +
" in UserSocialSave.updateSocials()"
);
query = "UPDATE mydb.Shops SET Shop_Website = '" +
usDTO.getShopUrl() + usDTO.getShopUrl() +
"' WHERE Shop_Id = " + shopId; "' WHERE Shop_Id = " + shopId;
jdbc.execute(query); jdbc.execute(query);
// Log the changes
loggingService.logEvent(
"ShopWebsite Updated",
session,
"Shop Website updated for Shop Id: " + shopId +
" in UserSocialSave.updateSocials()"
);
} }
} }
...@@ -46,7 +46,7 @@ public class UpdateSocials { ...@@ -46,7 +46,7 @@ public class UpdateSocials {
if(!isLinked){ if(!isLinked){
throw new ForbiddenErrorException("User not authenticated"); throw new ForbiddenErrorException("User not authenticated");
} }
save.updateSocials(userSocialDTO); save.updateSocials(userSocialDTO, session);
return "OK"; return "OK";
} }
} }
...@@ -353,4 +353,5 @@ INSERT INTO Events (Event_Name) VALUES ('Stamp Board Updated'); ...@@ -353,4 +353,5 @@ INSERT INTO Events (Event_Name) VALUES ('Stamp Board Updated');
INSERT INTO Events (Event_Name) VALUES ('Reward Deleted'); INSERT INTO Events (Event_Name) VALUES ('Reward Deleted');
INSERT INTO Events (Event_Name) VALUES ('Shop Updated'); INSERT INTO Events (Event_Name) VALUES ('Shop Updated');
INSERT INTO Events (Event_Name) VALUES ('UserShopLink Deleted'); INSERT INTO Events (Event_Name) VALUES ('UserShopLink Deleted');
INSERT INTO Events (Event_Name) VALUES ('UserShopLink Inserted'); INSERT INTO Events (Event_Name) VALUES ('UserShopLink Inserted');
\ No newline at end of file INSERT INTO Events (Event_Name) VALUES ('ShopWebsite Updated');
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment