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

Addition of method to get event object based on a string, replaced import on...

Addition of method to get event object based on a string, replaced import on main logging function with a string rather than event directly
parent 9a45cff0
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.service;
import com.example.clientproject.data.events.Events;
import com.example.clientproject.data.events.EventsRepo;
import com.example.clientproject.data.logs.Logs;
import com.example.clientproject.data.logs.LogsRepo;
import com.example.clientproject.service.Utils.JWTUtils;
......@@ -9,13 +10,15 @@ import org.springframework.stereotype.Service;
import javax.servlet.http.HttpSession;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Optional;
/**
* Service for all logging based methods
* Service for all logging related methods
*/
@Service
public class LoggingService {
LogsRepo logsRepo;
EventsRepo eventsRepo;
JWTUtils jwtUtils;
/**
......@@ -23,18 +26,23 @@ public class LoggingService {
* @param aLogsRepo - object of type LogsRepo
* @param aJWTUtils - object of type JWTUtils
*/
public LoggingService(LogsRepo aLogsRepo, JWTUtils aJWTUtils) {
public LoggingService(LogsRepo aLogsRepo, EventsRepo aEventRepo, JWTUtils aJWTUtils) {
jwtUtils = aJWTUtils;
eventsRepo = aEventRepo;
logsRepo = aLogsRepo;
}
public Optional<Events> findEventByName(String eventName) {
return eventsRepo.findByEventName(eventName);
}
/**
* Method for logging an event
* @param event - the event
* @param session - the session
* @param details - details of the event
*/
public void logEvent(Events event, HttpSession session, String details) {
public void logEvent(String event, HttpSession session, String details) {
// Instantiate a flagging variable
boolean superAdminStatus;
// If the session attribute "superAdmin" doesn't exist (super admin not logged in)
......@@ -56,7 +64,7 @@ public class LoggingService {
LocalDateTime.now().format(formatter),
superAdminStatus,
jwtUtils.getLoggedInUserRow(session).get(),
event
findEventByName(event).get()
);
// Save the new log
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment