Untitled
unknown
plain_text
3 years ago
1.9 kB
9
Indexable
@Controller
public class AdminController {
@Autowired
private QuestionService questionService;
@RequestMapping(value = "/view-reports", method = RequestMethod.GET)
public String viewReports() {
return "admin-view-reports";
}
@RequestMapping(value = "/add-questions-file", method = RequestMethod.GET)
public String addQuestionsFile() {
return "admin-add-questions-file";
}
@RequestMapping(value = "/upload-questions-file", method = RequestMethod.POST)
public String uploadQuestionsFile(@RequestParam("file") MultipartFile file) {
try {
// validate the file
if (!file.getContentType().equals("application/vnd.ms-excel")) {
throw new InvalidFileException("Invalid file format");
}
// parse the file and save the questions to the database
questionService.addQuestionsFromExcel(file.getInputStream());
return "admin-upload-success";
} catch (IOException e) {
e.printStackTrace();
return "admin-upload-error";
} catch (InvalidFileException e) {
e.printStackTrace();
return "admin-upload-error";
}
}
@RequestMapping(value = "/remove-questions-file", method = RequestMethod.GET)
public String removeQuestionsFile() {
return "admin-remove-questions-file";
}
@RequestMapping(value = "/delete-questions-file", method = RequestMethod.POST)
public String deleteQuestionsFile(@RequestParam("fileName") String fileName) {
try {
questionService.deleteQuestionsFile(fileName);
return "admin-delete-success";
} catch (IOException e) {
e.printStackTrace();
return "admin-delete-error";
}
}
}
Editor is loading...