diff --git a/src/main/java/com/nighthawk/spring_portfolio/mvc/classPeriod/ActionData.java b/src/main/java/com/nighthawk/spring_portfolio/mvc/classPeriod/ActionData.java new file mode 100644 index 0000000..7bb4e8b --- /dev/null +++ b/src/main/java/com/nighthawk/spring_portfolio/mvc/classPeriod/ActionData.java @@ -0,0 +1,64 @@ +package com.nighthawk.spring_portfolio.mvc.classPeriod; + +public class ActionData { + private String type; // Type of action (e.g., ADD_STUDENT, ADD_INSTRUCTOR) + private String id; // ID of the action (e.g., student ID, instructor ID) + private String name; // Name associated with the action (e.g., student name, instructor name) + private String email; // Email associated with the action (e.g., student email, instructor email) + + // Constructors, getters, and setters + public ActionData() { + // Default constructor + } + + public ActionData(String type, String id, String name, String email) { + this.type = type; + this.id = id; + this.name = name; + this.email = email; + } + + // Getters and setters for each field + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + // toString method for debugging or logging + @Override + public String toString() { + return "ActionData{" + + "type='" + type + '\'' + + ", id='" + id + '\'' + + ", name='" + name + '\'' + + ", email='" + email + '\'' + + '}'; + } +} diff --git a/src/main/java/com/nighthawk/spring_portfolio/mvc/classPeriod/UndoRedo.java b/src/main/java/com/nighthawk/spring_portfolio/mvc/classPeriod/UndoRedo.java new file mode 100644 index 0000000..31ec8e1 --- /dev/null +++ b/src/main/java/com/nighthawk/spring_portfolio/mvc/classPeriod/UndoRedo.java @@ -0,0 +1,55 @@ +package com.nighthawk.spring_portfolio.mvc.classPeriod; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; +import java.util.Stack; +import java.util.LinkedList; +import java.util.Queue; + +@RestController +public class UndoRedo { + private Stack undoStack; + private Stack redoStack; + private Queue actionsQueue; + + public UndoRedo() { + undoStack = new Stack<>(); + redoStack = new Stack<>(); + actionsQueue = new LinkedList<>(); + } + + @PostMapping("/addAction") + public String addAction(@RequestBody ActionData actionData) { + undoStack.push(actionData); + redoStack.clear(); // Clear redo stack on new action + actionsQueue.add(actionData); + return "Action added: " + actionData.getType(); // Example: Assuming ActionData has a getType() method + } + + @GetMapping("/undo") + public String undo() { + if (!undoStack.isEmpty()) { + ActionData actionData = undoStack.pop(); + redoStack.push(actionData); + return "Undo action: " + actionData.getType(); + } + return "No actions to undo"; + } + + @GetMapping("/redo") + public String redo() { + if (!redoStack.isEmpty()) { + ActionData actionData = redoStack.pop(); + undoStack.push(actionData); + return "Redo action: " + actionData.getType(); + } + return "No actions to redo"; + } + + @GetMapping("/getActionsQueue") + public Queue getActionsQueue() { + return actionsQueue; + } +}