#69 added method take part in conference
This commit is contained in:
parent
8564f2cf34
commit
7e4d8d4918
@ -104,6 +104,15 @@ public class ConferenceController {
|
||||
return CONFERENCE_PAGE;
|
||||
}
|
||||
|
||||
@PostMapping(value = "/conference", params = "takePart")
|
||||
public String takePart(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException {
|
||||
if (errors.hasErrors()) {
|
||||
return CONFERENCE_PAGE;
|
||||
}
|
||||
conferenceService.takePart(conferenceDto);
|
||||
return CONFERENCE_PAGE;
|
||||
}
|
||||
|
||||
public List<Paper> getNotSelectPapers(List<Integer> paperIds) {
|
||||
return conferenceService.getConferencePapers(paperIds);
|
||||
}
|
||||
|
@ -23,9 +23,7 @@ import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Entity
|
||||
@Table(name = "conference")
|
||||
@ -66,7 +64,8 @@ public class Conference extends BaseEntity {
|
||||
@JoinTable(name = "users_conference",
|
||||
joinColumns = {@JoinColumn(name = "conference_id")},
|
||||
inverseJoinColumns = {@JoinColumn(name = "users_id")})
|
||||
private Set<UserConference> users = new HashSet<>();
|
||||
@Fetch(FetchMode.SUBSELECT)
|
||||
private List<UserConference> users = new ArrayList<>();
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
@ -132,11 +131,11 @@ public class Conference extends BaseEntity {
|
||||
this.papers = papers;
|
||||
}
|
||||
|
||||
public Set<UserConference> getUsers() {
|
||||
public List<UserConference> getUsers() {
|
||||
return users;
|
||||
}
|
||||
|
||||
public void setUsers(Set<UserConference> users) {
|
||||
public void setUsers(List<UserConference> users) {
|
||||
this.users = users;
|
||||
}
|
||||
}
|
||||
|
@ -13,9 +13,7 @@ import javax.persistence.TemporalType;
|
||||
import javax.validation.constraints.Size;
|
||||
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;
|
||||
|
||||
@ -38,11 +36,11 @@ public class ConferenceDto {
|
||||
private Date endDate = new Date();
|
||||
private List<Deadline> deadlines = new ArrayList<>();
|
||||
private List<Integer> removedDeadlineIds = new ArrayList<>();
|
||||
private Set<Integer> userIds = new HashSet<>();
|
||||
private List<Integer> userIds = new ArrayList<>();
|
||||
private List<Integer> paperIds = new ArrayList<>();
|
||||
private List<Paper> papers = new ArrayList<>();
|
||||
private List<Paper> notSelectedPapers = new ArrayList<>();
|
||||
private Set<UserConference> users = new HashSet<>();
|
||||
private List<UserConference> users = new ArrayList<>();
|
||||
private Integer filterUserId;
|
||||
|
||||
public ConferenceDto() {
|
||||
@ -57,9 +55,9 @@ public class ConferenceDto {
|
||||
@JsonProperty("beginDate") Date beginDate,
|
||||
@JsonProperty("endDate") Date endDate,
|
||||
@JsonProperty("deadlines") List<Deadline> deadlines,
|
||||
@JsonProperty("userIds") Set<Integer> userIds,
|
||||
@JsonProperty("userIds") List<Integer> userIds,
|
||||
@JsonProperty("paperIds") List<Integer> paperIds,
|
||||
@JsonProperty("users") Set<UserConference> users,
|
||||
@JsonProperty("users") List<UserConference> users,
|
||||
@JsonProperty("papers") List<Paper> papers,
|
||||
@JsonProperty("notSelectedPapers") List<Paper> notSelectedPapers) {
|
||||
this.id = id;
|
||||
@ -157,11 +155,11 @@ public class ConferenceDto {
|
||||
this.deadlines = deadlines;
|
||||
}
|
||||
|
||||
public Set<Integer> getUserIds() {
|
||||
public List<Integer> getUserIds() {
|
||||
return userIds;
|
||||
}
|
||||
|
||||
public void setUserIds(Set<Integer> userIds) {
|
||||
public void setUserIds(List<Integer> userIds) {
|
||||
this.userIds = userIds;
|
||||
}
|
||||
|
||||
@ -181,11 +179,11 @@ public class ConferenceDto {
|
||||
this.papers = papers;
|
||||
}
|
||||
|
||||
public Set<UserConference> getUsers() {
|
||||
public List<UserConference> getUsers() {
|
||||
return users;
|
||||
}
|
||||
|
||||
public void setUsers(Set<UserConference> users) {
|
||||
public void setUsers(List<UserConference> users) {
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,7 @@
|
||||
package ru.ulstu.conference.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import ru.ulstu.user.model.UserConference;
|
||||
|
||||
public interface ConferenceUserRepository extends JpaRepository<UserConference, Integer> {
|
||||
}
|
@ -9,6 +9,8 @@ import ru.ulstu.conference.repository.ConferenceRepository;
|
||||
import ru.ulstu.deadline.service.DeadlineService;
|
||||
import ru.ulstu.paper.model.Paper;
|
||||
import ru.ulstu.paper.service.PaperService;
|
||||
import ru.ulstu.user.model.UserConference;
|
||||
import ru.ulstu.user.service.UserService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@ -21,17 +23,24 @@ public class ConferenceService {
|
||||
private final static int MAX_DISPLAY_SIZE = 40;
|
||||
|
||||
private final ConferenceRepository conferenceRepository;
|
||||
private final ConferenceUserService conferenceUserService;
|
||||
private final DeadlineService deadlineService;
|
||||
private final PaperService paperService;
|
||||
private final UserService userService;
|
||||
|
||||
public ConferenceService(ConferenceRepository conferenceRepository,
|
||||
ConferenceUserService conferenceUserService,
|
||||
DeadlineService deadlineService,
|
||||
PaperService paperService) {
|
||||
PaperService paperService,
|
||||
UserService userService) {
|
||||
this.conferenceRepository = conferenceRepository;
|
||||
this.conferenceUserService = conferenceUserService;
|
||||
this.deadlineService = deadlineService;
|
||||
this.paperService = paperService;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
|
||||
public List<Conference> findAll() {
|
||||
return conferenceRepository.findAll();
|
||||
}
|
||||
@ -88,6 +97,10 @@ public class ConferenceService {
|
||||
conferenceDto.getNotSelectedPapers().add(removedPaper);
|
||||
}
|
||||
|
||||
public void takePart(ConferenceDto conferenceDto) throws IOException {
|
||||
conferenceDto.getUsers().add(new UserConference("test", "test", userService.getCurrentUser()));
|
||||
}
|
||||
|
||||
public List<Paper> getConferencePapers(List<Integer> paperIds) {
|
||||
return paperService.findAllNotSelect(paperIds);
|
||||
}
|
||||
@ -101,6 +114,8 @@ public class ConferenceService {
|
||||
conference.setEndDate(conferenceDto.getEndDate());
|
||||
conference.setPapers(conferenceDto.getPapers());
|
||||
conference.setDeadlines(deadlineService.saveOrCreate(conferenceDto.getDeadlines()));
|
||||
conferenceDto.getUsers().forEach(user -> userService.findById(user.getUser().getId()));
|
||||
conference.setUsers(conferenceUserService.saveOrCreate(conferenceDto.getUsers()));
|
||||
if (conferenceDto.getPaperIds() != null && !conferenceDto.getPaperIds().isEmpty()) {
|
||||
conferenceDto.getPaperIds().forEach(paperId ->
|
||||
conference.getPapers().add(paperService.findEntityById(paperId)));
|
||||
|
@ -0,0 +1,48 @@
|
||||
package ru.ulstu.conference.service;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.ulstu.conference.repository.ConferenceUserRepository;
|
||||
import ru.ulstu.user.model.UserConference;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class ConferenceUserService {
|
||||
|
||||
private final ConferenceUserRepository conferenceUserRepository;
|
||||
|
||||
public ConferenceUserService(ConferenceUserRepository conferenceUserRepository) {
|
||||
this.conferenceUserRepository = conferenceUserRepository;
|
||||
}
|
||||
|
||||
public List<UserConference> saveOrCreate(List<UserConference> users) {
|
||||
return users
|
||||
.stream()
|
||||
.map(user -> {
|
||||
return user.getId() != null ? update(user) : create(user);
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public UserConference update(UserConference user) {
|
||||
UserConference updateUser = conferenceUserRepository.findOne(user.getId());
|
||||
updateUser.setDeposit(user.getDeposit());
|
||||
updateUser.setParticipation(user.getParticipation());
|
||||
conferenceUserRepository.save(updateUser);
|
||||
return updateUser;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public UserConference create(UserConference user) {
|
||||
UserConference newUser = new UserConference();
|
||||
newUser.setDeposit(user.getDeposit());
|
||||
newUser.setParticipation(user.getParticipation());
|
||||
newUser.setUser(user.getUser());
|
||||
newUser = conferenceUserRepository.save(newUser);
|
||||
return newUser;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package ru.ulstu.user.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import ru.ulstu.core.model.BaseEntity;
|
||||
|
||||
import javax.persistence.Column;
|
||||
@ -25,4 +27,49 @@ public class UserConference extends BaseEntity {
|
||||
@JoinColumn(name = "users_id")
|
||||
private User user;
|
||||
|
||||
public UserConference() {
|
||||
}
|
||||
|
||||
public UserConference(String participation, String deposit, User user) {
|
||||
this.participation = participation;
|
||||
this.deposit = deposit;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@JsonCreator
|
||||
public UserConference(@JsonProperty("id") Integer id,
|
||||
@JsonProperty("participation") String participation,
|
||||
@JsonProperty("deposit") String deposit,
|
||||
@JsonProperty("user") User user) {
|
||||
this.setId(id);
|
||||
this.participation = participation;
|
||||
this.deposit = deposit;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
|
||||
public String getParticipation() {
|
||||
return participation;
|
||||
}
|
||||
|
||||
public void setParticipation(String participation) {
|
||||
this.participation = participation;
|
||||
}
|
||||
|
||||
public String getDeposit() {
|
||||
return deposit;
|
||||
}
|
||||
|
||||
public void setDeposit(String deposit) {
|
||||
this.deposit = deposit;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -97,23 +97,28 @@
|
||||
<div class="form-group">
|
||||
<label for="members">Участники:</label>
|
||||
<div class="member-list form-control list-group" id="members">
|
||||
<div class="member d-flex list-group-item justify-content-between p-1">
|
||||
<input class="member-name" readonly="true"/>
|
||||
<select class="member-participation">
|
||||
очная
|
||||
<input th:type="hidden" th:value="*{users}"/>
|
||||
<div class="member d-flex list-group-item justify-content-between p-1"
|
||||
th:each="user, rowStat : *{users}">
|
||||
<input type="hidden" th:field="*{users[__${rowStat.index}__].id}"/>
|
||||
<input type="hidden" th:field="*{users[__${rowStat.index}__].user.id}"/>
|
||||
<input class="member-name" readonly="true"
|
||||
th:field="*{users[__${rowStat.index}__].user.lastName}"/>
|
||||
<select class="member-participation"
|
||||
th:field="*{users[__${rowStat.index}__].participation}">
|
||||
|
||||
</select>
|
||||
<select class="member-deposit">
|
||||
статья
|
||||
<select class="member-deposit"
|
||||
th:field="*{users[__${rowStat.index}__].deposit}">
|
||||
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group d-flex justify-content-end">
|
||||
<button id="take-part" class="btn btn-primary"
|
||||
type="button">
|
||||
Принять участие
|
||||
</button>
|
||||
<input id="take-part" class="btn btn-primary"
|
||||
type="submit" name="takePart" value="Принять участие"/>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
|
Loading…
Reference in New Issue
Block a user