diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 750d46d..61456c6 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -19,7 +19,9 @@ import java.io.IOException; import java.util.stream.Collectors; import static org.springframework.util.StringUtils.isEmpty; -import static ru.ulstu.core.controller.Navigation.*; +import static ru.ulstu.core.controller.Navigation.CONFERENCES_PAGE; +import static ru.ulstu.core.controller.Navigation.CONFERENCE_PAGE; +import static ru.ulstu.core.controller.Navigation.REDIRECT_TO; @Controller() @@ -64,8 +66,19 @@ public class ConferenceController { return CONFERENCE_PAGE; conferenceDto.getDeadlines().add(new Deadline()); return CONFERENCE_PAGE; + } - + @PostMapping(value = "/conference", params = "removeDeadline") + public String removeDeadline(@Valid ConferenceDto conferenceDto, Errors errors, + @RequestParam(value = "removeDeadline") Integer deadlineIndex) throws IOException { + if (errors.hasErrors()) + return CONFERENCE_PAGE; + conferenceService.removeDeadline(conferenceDto, deadlineIndex); + if (conferenceDto.getDeadlines().get(deadlineIndex).getId() != null) { + conferenceDto.getRemovedDeadlineIds().add(conferenceDto.getDeadlines().get(deadlineIndex).getId()); + } + conferenceDto.getDeadlines().remove(conferenceDto.getDeadlines().get(deadlineIndex)); + return CONFERENCE_PAGE; } private void filterEmptyDeadlines(ConferenceDto conferenceDto) { diff --git a/src/main/java/ru/ulstu/conference/model/Conference.java b/src/main/java/ru/ulstu/conference/model/Conference.java index 1c824b3..faed15c 100644 --- a/src/main/java/ru/ulstu/conference/model/Conference.java +++ b/src/main/java/ru/ulstu/conference/model/Conference.java @@ -56,7 +56,6 @@ public class Conference extends BaseEntity { @OrderBy("date") private List deadlines = new ArrayList<>(); - @ManyToMany(fetch = FetchType.EAGER) @JoinTable(name = "paper_conference", joinColumns = {@JoinColumn(name = "conference_id")}, diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java index eb67d39..e5efcde 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java @@ -11,7 +11,11 @@ import ru.ulstu.user.model.UserDto; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.validation.constraints.Size; -import java.util.*; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import static ru.ulstu.core.util.StreamApiUtils.convert; @@ -33,6 +37,7 @@ public class ConferenceDto { @DateTimeFormat(pattern = "yyyy-MM-dd") private Date endDate = new Date(); private List deadlines = new ArrayList<>(); + private List removedDeadlineIds = new ArrayList<>(); private Set userIds = new HashSet<>(); private Set paperIds = new HashSet<>(); private Set papers = new HashSet<>(); @@ -40,7 +45,7 @@ public class ConferenceDto { private Integer filterUserId; public ConferenceDto() { - } + } @JsonCreator public ConferenceDto(@JsonProperty("id") Integer id, @@ -188,4 +193,13 @@ public class ConferenceDto { public void setFilterUserId(Integer filterUserId) { this.filterUserId = filterUserId; } + + public List getRemovedDeadlineIds() { + return removedDeadlineIds; + } + + public void setRemovedDeadlineIds(List removedDeadlineIds) { + this.removedDeadlineIds = removedDeadlineIds; + } + } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index c28c637..46e7ff7 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -53,20 +53,20 @@ public class ConferenceService { public Integer create(ConferenceDto conferenceDto) throws IOException { Conference newConference = copyFromDto(new Conference(), conferenceDto); newConference = conferenceRepository.save(newConference); - - return newConference.getId(); } @Transactional public Integer update(ConferenceDto conferenceDto) throws IOException { Conference conference = conferenceRepository.findOne(conferenceDto.getId()); - conferenceRepository.save(copyFromDto(conference, conferenceDto)); - return conference.getId(); } + public void removeDeadline(ConferenceDto conferenceDto, Integer deadlineIndex) throws IOException { + + } + private Conference copyFromDto(Conference conference, ConferenceDto conferenceDto) throws IOException { conference.setTitle(conferenceDto.getTitle()); conference.setDescription(conferenceDto.getDescription()); @@ -74,9 +74,9 @@ public class ConferenceService { conference.setPing(0); conference.setBeginDate(conferenceDto.getBeginDate()); conference.setEndDate(conferenceDto.getEndDate()); - + conferenceDto.getRemovedDeadlineIds() + .forEach(deadlineService::remove); conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines())); - return conference; } diff --git a/src/main/java/ru/ulstu/deadline/service/DeadlineService.java b/src/main/java/ru/ulstu/deadline/service/DeadlineService.java index 2180025..d4ff2ef 100644 --- a/src/main/java/ru/ulstu/deadline/service/DeadlineService.java +++ b/src/main/java/ru/ulstu/deadline/service/DeadlineService.java @@ -41,4 +41,10 @@ public class DeadlineService { newDeadline = deadlineRepository.save(newDeadline); return newDeadline; } + + @Transactional + public void remove(Integer deadlineId) { + deadlineRepository.delete(deadlineId); + + } } diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 08083a5..c93fc39 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -50,6 +50,7 @@
+
@@ -58,9 +59,10 @@ th:field="*{deadlines[__${rowStat.index}__].description}"/> - Удалить + +