From b34f9ba27ff6843951a764905d827a8a62ed9f2c Mon Sep 17 00:00:00 2001 From: Yinnii Date: Fri, 11 Oct 2024 15:59:56 +0200 Subject: [PATCH] use multivaluemap instead of requestparam --- .../controller/TmitocarServiceController.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tmitocar-service/src/main/java/services/tmitocar/controller/TmitocarServiceController.java b/tmitocar-service/src/main/java/services/tmitocar/controller/TmitocarServiceController.java index e367bfa..5aad6c4 100644 --- a/tmitocar-service/src/main/java/services/tmitocar/controller/TmitocarServiceController.java +++ b/tmitocar-service/src/main/java/services/tmitocar/controller/TmitocarServiceController.java @@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; +import org.springframework.util.MultiValueMap; import com.google.gson.Gson; @@ -478,16 +479,24 @@ public ResponseEntity getAnalyzedText(@PathVariable("label1") String lab @ApiResponse(responseCode = "500", description = "Response failed.") }) @PostMapping(value = "/compareText", produces = MediaType.APPLICATION_JSON) - public ResponseEntity compareText(@RequestParam("label1") String label1, @RequestParam("label2") String label2, @RequestParam("file") MultipartFile file, - @RequestParam("type") String type, @RequestParam("template") String template, - @RequestParam("wordSpec") String wordSpec,@RequestParam("email") String email,@RequestParam("courseId") int courseId, @RequestParam("sbfmURL") String sbfmURL) throws ParseException, IOException { + public ResponseEntity compareText(@RequestParam MultiValueMap fileMp, @RequestParam("file") MultipartFile file) throws ParseException, IOException { + String label1 = fileMp.getFirst("label1"); + String label2 = fileMp.getFirst("label2"); + String type = fileMp.getFirst("type"); + String template = fileMp.getFirst("template"); + String wordSpec = fileMp.getFirst("wordSpec"); + String email = fileMp.getFirst("email"); + Integer courseId = Integer.parseInt(fileMp.getFirst("courseId")); + String sbfmURL = fileMp.getFirst("sbfmURL"); + + if (service.isActive.getOrDefault(label1, false)) { JSONObject err = new JSONObject(); err.put("errorMessage", "User: " + label1 + " currently busy."); err.put("error", true); return ResponseEntity.status(HttpStatus.NOT_FOUND).body(err.toJSONString()); } - + File templatePath = new File("tmitocar/templates/" + template); if (!templatePath.exists()){ JSONObject err = new JSONObject();