|
15 | 15 | import ru.practicum.ewm.event.dto.EventShortDto; |
16 | 16 | import ru.practicum.ewm.event.mapper.EventMapper; |
17 | 17 | import ru.practicum.ewm.event.model.Event; |
| 18 | +import ru.practicum.ewm.event.model.EventState; |
18 | 19 | import ru.practicum.ewm.event.repository.EventRepository; |
19 | 20 | import ru.practicum.ewm.exception.NotFoundException; |
20 | 21 |
|
@@ -87,20 +88,36 @@ public List<CompilationDto> getCompilations(Boolean pinned, int from, int size) |
87 | 88 | } |
88 | 89 | return compilations.stream() |
89 | 90 | .map(comp -> { |
| 91 | +// Set<EventShortDto> eventDtos = comp.getEvents().stream() |
| 92 | +// .map(event -> EventMapper.toEventShortDto(event, 0L, 0L)) |
| 93 | +// .collect(Collectors.toSet()); |
90 | 94 | Set<EventShortDto> eventDtos = comp.getEvents().stream() |
| 95 | + .filter(event -> event.getState() == EventState.PUBLISHED) |
91 | 96 | .map(event -> EventMapper.toEventShortDto(event, 0L, 0L)) |
92 | 97 | .collect(Collectors.toSet()); |
93 | 98 | return CompilationMapper.toCompilationDto(comp, eventDtos); |
94 | 99 | }) |
95 | 100 | .collect(Collectors.toList()); |
96 | 101 | } |
97 | 102 |
|
| 103 | +// @Override |
| 104 | +// @Transactional(readOnly = true) |
| 105 | +// public CompilationDto getCompilation(Long compId) { |
| 106 | +// Compilation compilation = compilationRepository.findById(compId) |
| 107 | +// .orElseThrow(() -> new NotFoundException("Подборка с id=" + compId + " не найдена")); |
| 108 | +// Set<EventShortDto> eventDtos = compilation.getEvents().stream() |
| 109 | +// .map(event -> EventMapper.toEventShortDto(event, 0L, 0L)) |
| 110 | +// .collect(Collectors.toSet()); |
| 111 | +// return CompilationMapper.toCompilationDto(compilation, eventDtos); |
| 112 | +// } |
| 113 | + |
98 | 114 | @Override |
99 | 115 | @Transactional(readOnly = true) |
100 | 116 | public CompilationDto getCompilation(Long compId) { |
101 | 117 | Compilation compilation = compilationRepository.findById(compId) |
102 | 118 | .orElseThrow(() -> new NotFoundException("Подборка с id=" + compId + " не найдена")); |
103 | 119 | Set<EventShortDto> eventDtos = compilation.getEvents().stream() |
| 120 | + .filter(event -> event.getState() == EventState.PUBLISHED) |
104 | 121 | .map(event -> EventMapper.toEventShortDto(event, 0L, 0L)) |
105 | 122 | .collect(Collectors.toSet()); |
106 | 123 | return CompilationMapper.toCompilationDto(compilation, eventDtos); |
|
0 commit comments