From 5bfeaff0540659a3c4d364da3827158d13917c1b Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Mon, 22 Apr 2019 11:13:04 +0400 Subject: [PATCH] #64 added method addPaper --- .../conference/controller/ConferenceController.java | 10 ++++++++++ .../ulstu/conference/service/ConferenceService.java | 8 +++++++- .../java/ru/ulstu/paper/service/PaperService.java | 2 +- .../resources/templates/conferences/conference.html | 12 ++++++++++-- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index a416345..cf5017d 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -95,6 +95,16 @@ public class ConferenceController { return CONFERENCE_PAGE; } + @PostMapping(value = "/conference", params = "addPaper") + public String addPaper(@Valid ConferenceDto conferenceDto, Errors errors) { + if (errors.hasErrors()) { + return CONFERENCE_PAGE; + } + conferenceService.addPaper(conferenceDto); + + return CONFERENCE_PAGE; + } + @PostMapping(value = "/conference", params = "removeDeadline") public String removeDeadline(@Valid ConferenceDto conferenceDto, Errors errors, @RequestParam(value = "removeDeadline") Integer deadlineIndex) throws IOException { diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index e5ce29f..f918812 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -149,7 +149,7 @@ public class ConferenceService { conference.setUsers(conferenceUserService.saveOrCreate(conferenceDto.getUsers())); if (conferenceDto.getPaperIds() != null && !conferenceDto.getPaperIds().isEmpty()) { conferenceDto.getPaperIds().forEach(paperId -> - conference.getPapers().add(paperService.findEntityById(paperId))); + conference.getPapers().add(paperService.findPaperById(paperId))); } return conference; } @@ -173,4 +173,10 @@ public class ConferenceService { public List findAllActive() { return conferenceRepository.findAllActive(new Date()); } + + public void addPaper(ConferenceDto conferenceDto) { + Paper paper = new Paper(); + paper.setTitle(userService.getCurrentUser().getLastName() + "_" + conferenceDto.getTitle()); + conferenceDto.getPapers().add(paper); + } } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 1633c07..85db4ed 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -223,7 +223,7 @@ public class PaperService { return new PaperDto(paperRepository.findOne(paperId)); } - public Paper findEntityById(Integer paperId) { + public Paper findPaperById(Integer paperId) { return paperRepository.findOne(paperId); } diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 184f5b5..8425fac 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -135,7 +135,15 @@