From b623402aa8f8cdbba6a9317f288fbf0ae79bafdb Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 19 Apr 2019 14:39:07 +0400 Subject: [PATCH] #69 changed method getConference in controller --- .../controller/ConferenceController.java | 19 ++----------------- .../conference/service/ConferenceService.java | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index dc57bce..6867be5 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -15,12 +15,10 @@ import ru.ulstu.conference.model.ConferenceFilterDto; import ru.ulstu.conference.model.ConferenceUser; import ru.ulstu.conference.service.ConferenceService; import ru.ulstu.deadline.model.Deadline; -import ru.ulstu.paper.model.Paper; import springfox.documentation.annotations.ApiIgnore; import javax.validation.Valid; import java.io.IOException; -import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -49,14 +47,9 @@ public class ConferenceController { @GetMapping("/conference") public void getConference(ModelMap modelMap, @RequestParam(value = "id") Integer id) { if (id != null && id > 0) { - ConferenceDto conferenceDto = conferenceService.findOneDto(id); - conferenceDto.setNotSelectedPapers(getNotSelectPapers(conferenceDto.getPaperIds())); - conferenceDto.setDisabledTakePart(isCurrentUserParticipant(conferenceDto.getUsers())); - modelMap.put("conferenceDto", conferenceDto); + modelMap.put("conferenceDto", conferenceService.getExistConferenceById(id)); } else { - ConferenceDto conferenceDto = new ConferenceDto(); - conferenceDto.setNotSelectedPapers(getNotSelectPapers(new ArrayList())); - modelMap.put("conferenceDto", conferenceDto); + modelMap.put("conferenceDto", conferenceService.getNewConference()); } } @@ -116,14 +109,6 @@ public class ConferenceController { return CONFERENCE_PAGE; } - public List getNotSelectPapers(List paperIds) { - return conferenceService.getConferencePapers(paperIds); - } - - public boolean isCurrentUserParticipant(List conferenceUsers) { - return conferenceService.isCurrentUserParticipant(conferenceUsers); - } - @ModelAttribute("allParticipation") public List getAllParticipation() { return conferenceService.getAllParticipations(); diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 1bfdebd..6295d5c 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -13,6 +13,7 @@ import ru.ulstu.paper.service.PaperService; import ru.ulstu.user.service.UserService; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -41,6 +42,19 @@ public class ConferenceService { this.userService = userService; } + public ConferenceDto getExistConferenceById(Integer id) { + ConferenceDto conferenceDto = findOneDto(id); + conferenceDto.setNotSelectedPapers(getNotSelectPapers(conferenceDto.getPaperIds())); + conferenceDto.setDisabledTakePart(isCurrentUserParticipant(conferenceDto.getUsers())); + return conferenceDto; + } + + public ConferenceDto getNewConference() { + ConferenceDto conferenceDto = new ConferenceDto(); + conferenceDto.setNotSelectedPapers(getNotSelectPapers(new ArrayList())); + return conferenceDto; + } + public List findAll() { return conferenceRepository.findAll(); @@ -103,7 +117,7 @@ public class ConferenceService { conferenceDto.setDisabledTakePart(true); } - public List getConferencePapers(List paperIds) { + public List getNotSelectPapers(List paperIds) { return paperService.findAllNotSelect(paperIds); }