Basis

Look at the object made with Alex for the Dijkstra algorithm JSON body. It seems like it may only take a basic constructor.

Differences

  • Test method in constructor
  • Test if JSON keys act as parameter argument identifiers
// imports work
import java.util.HashMap;

public class GraphRequest {
    private int source;
    private int target;
    private int[][] adjacencyList;
    // this complicated data type works; use for coordinates as well
    private HashMap<Integer,int[]> coordinates;

    public int getSource() {
        return source;
    }

    public void setSource(int source) {
        this.source = source;
    }

    public int getTarget() {
        return target;
    }

    public void setTarget(int target) {
        this.target = target;
    }

    public int[][] getAdjacencyList() {
        return adjacencyList;
    }

    public void setAdjacencyList(int[][] adjacencyList) {
        this.adjacencyList = adjacencyList;
    }

    public HashMap<Integer,int[]> getCoordinates() {
        return coordinates;
    }

    public void setCoordinates(HashMap<Integer,int[]> coordinates) {
        this.coordinates = coordinates;
    }
}

Current Test

Test implementation with this. The idea is that most of the body from the graph request can be used simultaneously to save to the user profile. Necessary for the PUT request.

NOTE: Email should be provided in JWT cookie after login to the user. If no email cookie is found, the save should return an error that can be read and returned to the user on the frontend

  • “You aren’t signed in or your authentication token expired! Please log in once again to save canvases.”
public class CanvasUpdate {
    private String email;
    private Integer[][] adj;
    private HashMap<Integer, Integer[]> coords;

    public CanvasUpdate(String email, Integer[][] adj, HashMap<Integer, Integer[]> coords) {
        this.email = email;
        this.adj = adj;
        this.coords = coords;
    }

    public void setEmail(String email) {
        this.email = email;
    }
    
    public void setAdj(Integer[][] adj) {
        this.adj = adj;
    }

    public void setCoords(HashMap<Integer, Integer[]> coords) {
        this.coords = coords;
    }

    // might break it
    public void setCoords(Integer[][] coords) {
        for (Integer i = 0; i < coords.length; i++) {
          Integer coord[] = new Integer[2];
          coord[0] = coords[i][0];
          coord[1] = coords[i][1];
          Integer nodeID = i + 1;
          this.coords.put(nodeID, coord);
        }  
      }

    public String getEmail() {
        return this.email;
    }

    public Integer[][] getAdj() {
        return this.adj;
    }

    public HashMap<Integer, Integer[]> getCoords() {
        return this.coords;
    }
}

NOTE: idk if implicit constructors with lombok will work but I wouldn’t risk it. Might as well be real

Result 1

“JSON failed to map”

This could be related to file location. To be tested

Result 2

This fixed the “JSON failed to map” error from Postman. It seems like this is how it’s intended to work with class objects, where Spring requires some separate file to be created and imported.