diff --git a/src/main/java/com/opinionowl/opinionowl/controllers/APIController.java b/src/main/java/com/opinionowl/opinionowl/controllers/APIController.java index f02a564..fb6cde8 100644 --- a/src/main/java/com/opinionowl/opinionowl/controllers/APIController.java +++ b/src/main/java/com/opinionowl/opinionowl/controllers/APIController.java @@ -8,50 +8,62 @@ import com.opinionowl.opinionowl.repos.SurveyRepository; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; -import org.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.core.type.TypeReference; import java.io.BufferedReader; import java.io.IOException; import java.util.*; +/** + * Version 1 of the API layer for Opinion Owl + */ @RestController @RequestMapping("/api/v1") public class APIController { - // @Autowired - // SurveyRepository sRepo; @Autowired SurveyRepository surveyRepo; + /** + *
Api call to handle the survey answers by a user.
+ *API Call to post a generated survey by the user. A survey generated JSON is required from the client
+ *+ * json = { + * title: "title", + * textQuestions: ["question 1", "question 2"], + * radioQuestions: { + * "question 1": ["radio 1", "radio 2"], + * "question 2": ["radio 1", "radio 2", "radio 3"] + * }, + * numericRanges: { + * "question 1": [1, 11], + * "question 2": [1, 5] + * } + * } + *+ * @param request HttpServletRequest request from the client + * @return 200 if api was a success + * @throws IOException + */ @PostMapping("/createSurvey") - public int createSurvey(HttpServletRequest request, HttpServletResponse response) throws IOException { + public int createSurvey(HttpServletRequest request) throws IOException { System.out.println("createSurvey() API"); // read the json sent by the client BufferedReader reader = request.getReader(); diff --git a/src/main/java/com/opinionowl/opinionowl/controllers/PageController.java b/src/main/java/com/opinionowl/opinionowl/controllers/PageController.java index 588b137..70b641e 100644 --- a/src/main/java/com/opinionowl/opinionowl/controllers/PageController.java +++ b/src/main/java/com/opinionowl/opinionowl/controllers/PageController.java @@ -7,18 +7,24 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; - -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Optional; +/** + * Route controller for Opinion Owl pages + */ @Controller public class PageController { @Autowired SurveyRepository surveyRepo; + /** + *
Home route that gets all the surveys in the database, sends it to the model and directs the user to the home page
+ * @param model Model, the client Model + * @return String, the html template + */ @GetMapping("/") public String getHomePage(Model model) { ListRoute for the create survey page
+ * @param model Model, the client Model + * @return String ,the html template + */ @GetMapping("/createSurvey") public String getCreateSurveyPage(Model model) { return "createSurvey"; } + /** + *Route to direct the client to the answer survey page, given a survey id to pass the Survey object to the Model
+ *