#64 added method addPaper

This commit is contained in:
Nightblade73 2019-04-22 11:13:04 +04:00
parent b6ced3ce1a
commit 5bfeaff054
4 changed files with 28 additions and 4 deletions

View File

@ -95,6 +95,16 @@ public class ConferenceController {
return CONFERENCE_PAGE; 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") @PostMapping(value = "/conference", params = "removeDeadline")
public String removeDeadline(@Valid ConferenceDto conferenceDto, Errors errors, public String removeDeadline(@Valid ConferenceDto conferenceDto, Errors errors,
@RequestParam(value = "removeDeadline") Integer deadlineIndex) throws IOException { @RequestParam(value = "removeDeadline") Integer deadlineIndex) throws IOException {

View File

@ -149,7 +149,7 @@ public class ConferenceService {
conference.setUsers(conferenceUserService.saveOrCreate(conferenceDto.getUsers())); conference.setUsers(conferenceUserService.saveOrCreate(conferenceDto.getUsers()));
if (conferenceDto.getPaperIds() != null && !conferenceDto.getPaperIds().isEmpty()) { if (conferenceDto.getPaperIds() != null && !conferenceDto.getPaperIds().isEmpty()) {
conferenceDto.getPaperIds().forEach(paperId -> conferenceDto.getPaperIds().forEach(paperId ->
conference.getPapers().add(paperService.findEntityById(paperId))); conference.getPapers().add(paperService.findPaperById(paperId)));
} }
return conference; return conference;
} }
@ -173,4 +173,10 @@ public class ConferenceService {
public List<Conference> findAllActive() { public List<Conference> findAllActive() {
return conferenceRepository.findAllActive(new Date()); 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);
}
} }

View File

@ -223,7 +223,7 @@ public class PaperService {
return new PaperDto(paperRepository.findOne(paperId)); return new PaperDto(paperRepository.findOne(paperId));
} }
public Paper findEntityById(Integer paperId) { public Paper findPaperById(Integer paperId) {
return paperRepository.findOne(paperId); return paperRepository.findOne(paperId);
} }

View File

@ -135,7 +135,15 @@
<div class="paper d-flex list-group-item p-0" <div class="paper d-flex list-group-item p-0"
th:each="paper, rowStat : *{papers}"> th:each="paper, rowStat : *{papers}">
<a class="paper-name" <a class="paper-name"
th:href="@{'/papers/paper?id=' + *{papers[__${rowStat.index}__].id} + ''}"> th:href="@{'/papers/paper?id=' + *{papers[__${rowStat.index}__].id} + ''}"
th:if="*{papers[__${rowStat.index}__].id !=null}">
<span th:text="*{papers[__${rowStat.index}__].title}">
Имя статьи
</span>
<img class="icon-paper" src="/img/conference/paper.png"/>
</a>
<a class="paper-name"
th:unless="*{papers[__${rowStat.index}__].id !=null}">
<span th:text="*{papers[__${rowStat.index}__].title}"> <span th:text="*{papers[__${rowStat.index}__].title}">
Имя статьи Имя статьи
</span> </span>
@ -156,7 +164,7 @@
</option> </option>
</select> </select>
<button id="add-paper" class="btn btn-primary" <button id="add-paper" class="btn btn-primary"
type="button"> type="submit" name="addPaper">
Добавить статью Добавить статью
</button> </button>
</div> </div>