Добавлены DTO для всех entity

This commit is contained in:
serega6531
2020-12-29 14:36:17 +03:00
parent 19ccd3f200
commit 625848cf23
17 changed files with 179 additions and 46 deletions

View File

@@ -5,13 +5,14 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ru.serega6531.packmate.model.Packet;
import ru.serega6531.packmate.model.Stream;
import ru.serega6531.packmate.model.pojo.PacketDto;
import ru.serega6531.packmate.service.StreamService;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/api/packet/")
@@ -25,10 +26,12 @@ public class PacketController {
}
@PostMapping("/{streamId}")
public List<Packet> getPacketsForStream(@PathVariable long streamId) {
public List<PacketDto> getPacketsForStream(@PathVariable long streamId) {
final Optional<Stream> stream = streamService.find(streamId);
if (stream.isPresent()) {
return stream.get().getPackets();
return stream.get().getPackets().stream()
.map(streamService::packetToDto)
.collect(Collectors.toList());
} else {
return Collections.emptyList();
}