|
|
@ -1,19 +1,17 @@
|
|
|
|
package ru.ulstu.paper.controller;
|
|
|
|
package ru.ulstu.paper.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
import org.springframework.ui.Model;
|
|
|
|
|
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
|
import org.springframework.validation.BindingResult;
|
|
|
|
import org.springframework.validation.Errors;
|
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.PutMapping;
|
|
|
|
import org.springframework.web.bind.annotation.PutMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
|
|
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|
|
|
import ru.ulstu.core.model.response.Response;
|
|
|
|
import ru.ulstu.core.model.response.Response;
|
|
|
|
import ru.ulstu.paper.model.PaperDto;
|
|
|
|
import ru.ulstu.paper.model.PaperDto;
|
|
|
|
import ru.ulstu.paper.model.PaperFilterDto;
|
|
|
|
import ru.ulstu.paper.model.PaperFilterDto;
|
|
|
@ -40,25 +38,23 @@ public class PaperController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GetMapping("/paper")
|
|
|
|
@GetMapping("/paper")
|
|
|
|
public void getPapers(ModelMap modelMap, @RequestParam(value="id") Integer id) {
|
|
|
|
public void getPapers(ModelMap modelMap, @RequestParam(value = "id") Integer id) {
|
|
|
|
if (id != null && id > 0) {
|
|
|
|
if (id != null && id > 0) {
|
|
|
|
modelMap.put("paper", paperService.findOneDto(id));
|
|
|
|
modelMap.put("paperDto", paperService.findOneDto(id));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
modelMap.put("paper", new PaperDto());
|
|
|
|
modelMap.put("paperDto", new PaperDto());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/paper")
|
|
|
|
@PostMapping("/paper")
|
|
|
|
public String createPaper(@ModelAttribute PaperDto paperDto) throws IOException {
|
|
|
|
public String save(@Valid PaperDto paperDto, Errors errors) throws IOException {
|
|
|
|
paperService.create(paperDto);
|
|
|
|
if (errors.hasErrors()) {
|
|
|
|
|
|
|
|
return "/papers/paper";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
paperService.save(paperDto);
|
|
|
|
return "redirect:/papers/papers";
|
|
|
|
return "redirect:/papers/papers";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@PutMapping
|
|
|
|
|
|
|
|
public Response<Integer> updatePaper(@RequestBody @Valid PaperDto paperDto) throws IOException {
|
|
|
|
|
|
|
|
return new Response<>(paperService.update(paperDto));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@DeleteMapping("/{paper-id}")
|
|
|
|
@DeleteMapping("/{paper-id}")
|
|
|
|
public Response<Boolean> delete(@PathVariable("paper-id") Integer paperId) throws IOException {
|
|
|
|
public Response<Boolean> delete(@PathVariable("paper-id") Integer paperId) throws IOException {
|
|
|
|
paperService.delete(paperId);
|
|
|
|
paperService.delete(paperId);
|
|
|
|