#59 added filtration

This commit is contained in:
Nightblade73 2019-04-19 17:36:46 +04:00
parent e2b49689d5
commit 34033fac5f
4 changed files with 47 additions and 1 deletions

View File

@ -15,10 +15,13 @@ import ru.ulstu.conference.model.ConferenceFilterDto;
import ru.ulstu.conference.model.ConferenceUser; import ru.ulstu.conference.model.ConferenceUser;
import ru.ulstu.conference.service.ConferenceService; import ru.ulstu.conference.service.ConferenceService;
import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.user.model.User;
import springfox.documentation.annotations.ApiIgnore; import springfox.documentation.annotations.ApiIgnore;
import javax.validation.Valid; import javax.validation.Valid;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -44,6 +47,13 @@ public class ConferenceController {
modelMap.put("filteredConferences", new ConferenceFilterDto(conferenceService.findAllDto())); modelMap.put("filteredConferences", new ConferenceFilterDto(conferenceService.findAllDto()));
} }
@PostMapping("/conferences")
public void filterConferences(@Valid ConferenceFilterDto conferenceFilterDto, ModelMap modelMap) {
modelMap.put("filteredConferences", new ConferenceFilterDto(conferenceService.filter(conferenceFilterDto),
conferenceFilterDto.getFilterUserId(),
conferenceFilterDto.getYear()));
}
@GetMapping("/conference") @GetMapping("/conference")
public void getConference(ModelMap modelMap, @RequestParam(value = "id") Integer id) { public void getConference(ModelMap modelMap, @RequestParam(value = "id") Integer id) {
if (id != null && id > 0) { if (id != null && id > 0) {
@ -119,6 +129,20 @@ public class ConferenceController {
return conferenceService.getAllDeposit(); return conferenceService.getAllDeposit();
} }
@ModelAttribute("allUsers")
public List<User> getAllUsers() {
return conferenceService.getAllUsers();
}
@ModelAttribute("allYears")
public List<Integer> getAllYears() {
List<Integer> years = new ArrayList<>();
for (int i = Calendar.getInstance().get(Calendar.YEAR); i > 2010; i--) {
years.add(i);
}
return years;
}
private void filterEmptyDeadlines(ConferenceDto conferenceDto) { private void filterEmptyDeadlines(ConferenceDto conferenceDto) {
conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream() conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream()
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))

View File

@ -1,7 +1,14 @@
package ru.ulstu.conference.repository; package ru.ulstu.conference.repository;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import ru.ulstu.conference.model.Conference; import ru.ulstu.conference.model.Conference;
import ru.ulstu.user.model.User;
import java.util.List;
public interface ConferenceRepository extends JpaRepository<Conference, Integer> { public interface ConferenceRepository extends JpaRepository<Conference, Integer> {
@Query("SELECT c FROM Conference c LEFT JOIN c.users u WHERE (:user IS NULL OR u.user = :user) AND (YEAR(c.beginDate) = :year OR :year IS NULL)")
List<Conference> filter(@Param("user") User user, @Param("year") Integer year);
} }

View File

@ -5,11 +5,13 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import ru.ulstu.conference.model.Conference; import ru.ulstu.conference.model.Conference;
import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.model.ConferenceDto;
import ru.ulstu.conference.model.ConferenceFilterDto;
import ru.ulstu.conference.model.ConferenceUser; import ru.ulstu.conference.model.ConferenceUser;
import ru.ulstu.conference.repository.ConferenceRepository; import ru.ulstu.conference.repository.ConferenceRepository;
import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.deadline.service.DeadlineService;
import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.Paper;
import ru.ulstu.paper.service.PaperService; import ru.ulstu.paper.service.PaperService;
import ru.ulstu.user.model.User;
import ru.ulstu.user.service.UserService; import ru.ulstu.user.service.UserService;
import java.io.IOException; import java.io.IOException;
@ -121,6 +123,10 @@ public class ConferenceService {
return paperService.findAllNotSelect(paperIds); return paperService.findAllNotSelect(paperIds);
} }
public List<User> getAllUsers() {
return userService.findAll();
}
public List<ConferenceUser.Participation> getAllParticipations() { public List<ConferenceUser.Participation> getAllParticipations() {
return Arrays.asList(ConferenceUser.Participation.values()); return Arrays.asList(ConferenceUser.Participation.values());
} }
@ -150,4 +156,11 @@ public class ConferenceService {
public boolean isCurrentUserParticipant(List<ConferenceUser> conferenceUsers) { public boolean isCurrentUserParticipant(List<ConferenceUser> conferenceUsers) {
return conferenceUsers.stream().anyMatch(participant -> participant.getUser().equals(userService.getCurrentUser())); return conferenceUsers.stream().anyMatch(participant -> participant.getUser().equals(userService.getCurrentUser()));
} }
public List<ConferenceDto> filter(ConferenceFilterDto conferenceFilterDto) {
return convert(conferenceRepository.filter(
conferenceFilterDto.getFilterUserId() == null ? null : userService.findById(conferenceFilterDto.getFilterUserId()),
conferenceFilterDto.getYear()), ConferenceDto::new);
}
} }

View File

@ -11,7 +11,9 @@ body {
color: white; color: white;
} }
.filter .dropdown {
margin-bottom: 10px;
}
.form-group textarea { .form-group textarea {