#64 added saving in db
This commit is contained in:
parent
5bfeaff054
commit
2767403128
@ -86,7 +86,7 @@ public class ConferenceController {
|
||||
}
|
||||
|
||||
@PostMapping(value = "/conference", params = "addDeadline")
|
||||
public String addDeadline(@Valid ConferenceDto conferenceDto, Errors errors) {
|
||||
public String addDeadline(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException {
|
||||
filterEmptyDeadlines(conferenceDto);
|
||||
if (errors.hasErrors()) {
|
||||
return CONFERENCE_PAGE;
|
||||
@ -95,16 +95,6 @@ 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 {
|
||||
@ -115,6 +105,16 @@ public class ConferenceController {
|
||||
return CONFERENCE_PAGE;
|
||||
}
|
||||
|
||||
@PostMapping(value = "/conference", params = "addPaper")
|
||||
public String addPaper(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException {
|
||||
if (errors.hasErrors()) {
|
||||
return CONFERENCE_PAGE;
|
||||
}
|
||||
conferenceService.addPaper(conferenceDto);
|
||||
|
||||
return CONFERENCE_PAGE;
|
||||
}
|
||||
|
||||
@PostMapping(value = "/conference", params = "removePaper")
|
||||
public String removePaper(@Valid ConferenceDto conferenceDto, Errors errors,
|
||||
@RequestParam(value = "removePaper") Integer paperIndex) throws IOException {
|
||||
|
@ -53,7 +53,7 @@ public class Conference extends BaseEntity {
|
||||
@OrderBy("date")
|
||||
private List<Deadline> deadlines = new ArrayList<>();
|
||||
|
||||
@ManyToMany(fetch = FetchType.EAGER)
|
||||
@ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.EAGER)
|
||||
@JoinTable(name = "paper_conference",
|
||||
joinColumns = {@JoinColumn(name = "conference_id")},
|
||||
inverseJoinColumns = {@JoinColumn(name = "paper_id")})
|
||||
|
@ -111,9 +111,19 @@ public class ConferenceService {
|
||||
conferenceDto.getDeadlines().remove((int) deadlineIndex);
|
||||
}
|
||||
|
||||
public void addPaper(ConferenceDto conferenceDto) {
|
||||
Paper paper = new Paper();
|
||||
paper.setTitle(userService.getCurrentUser().getLastName() + "_" + conferenceDto.getTitle());
|
||||
paper.setStatus(Paper.PaperStatus.DRAFT);
|
||||
|
||||
conferenceDto.getPapers().add(paper);
|
||||
}
|
||||
|
||||
public void removePaper(ConferenceDto conferenceDto, Integer paperIndex) throws IOException {
|
||||
Paper removedPaper = conferenceDto.getPapers().remove((int) paperIndex);
|
||||
conferenceDto.getNotSelectedPapers().add(removedPaper);
|
||||
if (removedPaper.getId() != null) {
|
||||
conferenceDto.getNotSelectedPapers().add(removedPaper);
|
||||
}
|
||||
}
|
||||
|
||||
public void takePart(ConferenceDto conferenceDto) throws IOException {
|
||||
@ -144,7 +154,8 @@ public class ConferenceService {
|
||||
conference.setPing(0);
|
||||
conference.setBeginDate(conferenceDto.getBeginDate());
|
||||
conference.setEndDate(conferenceDto.getEndDate());
|
||||
conference.setPapers(conferenceDto.getPapers());
|
||||
conference.getPapers().clear();
|
||||
conferenceDto.getPapers().forEach(paper -> conference.getPapers().add(paper.getId() != null ? paperService.findPaperById(paper.getId()) : paperService.create(paper)));
|
||||
conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines()));
|
||||
conference.setUsers(conferenceUserService.saveOrCreate(conferenceDto.getUsers()));
|
||||
if (conferenceDto.getPaperIds() != null && !conferenceDto.getPaperIds().isEmpty()) {
|
||||
@ -173,10 +184,4 @@ public class ConferenceService {
|
||||
public List<Conference> 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);
|
||||
}
|
||||
}
|
||||
|
@ -93,6 +93,14 @@ public class PaperService {
|
||||
return newPaper.getId();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Paper create(Paper paper) {
|
||||
Paper newPaper = paperRepository.save(paper);
|
||||
paperNotificationService.sendCreateNotification(newPaper);
|
||||
eventService.createFromPaper(newPaper);
|
||||
return newPaper;
|
||||
}
|
||||
|
||||
private Paper copyFromDto(Paper paper, PaperDto paperDto) throws IOException {
|
||||
paper.setComment(paperDto.getComment());
|
||||
paper.setUrl(paperDto.getUrl());
|
||||
|
@ -131,9 +131,11 @@
|
||||
<div class="form-group">
|
||||
<label for="papers">Статьи:</label>
|
||||
<div class="paper-list form-control list-group" id="papers">
|
||||
<input th:type="hidden" th:field="*{papers}"/>
|
||||
<!--<input th:type="hidden" th:field="*{papers}"/>-->
|
||||
<div class="paper d-flex list-group-item p-0"
|
||||
th:each="paper, rowStat : *{papers}">
|
||||
<input type="hidden" th:field="*{papers[__${rowStat.index}__].id}"/>
|
||||
<input type="hidden" th:field="*{papers[__${rowStat.index}__].title}"/>
|
||||
<a class="paper-name"
|
||||
th:href="@{'/papers/paper?id=' + *{papers[__${rowStat.index}__].id} + ''}"
|
||||
th:if="*{papers[__${rowStat.index}__].id !=null}">
|
||||
|
Loading…
Reference in New Issue
Block a user