Добавлено api пакетов

This commit is contained in:
serega6531
2019-04-29 20:39:25 +03:00
parent 9c9b7cc942
commit 2ef4f2d480
8 changed files with 49 additions and 11 deletions

View File

@@ -3,30 +3,36 @@ package ru.serega6531.packmate.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import ru.serega6531.packmate.model.Packet;
import ru.serega6531.packmate.model.Pagination;
import ru.serega6531.packmate.model.Stream;
import ru.serega6531.packmate.service.PacketService;
import ru.serega6531.packmate.service.StreamService;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
@RestController
@RequestMapping("/api/packet/")
public class PacketController {
private final PacketService service;
private final StreamService streamService;
private final PacketService packetService;
@Autowired
public PacketController(PacketService service) {
this.service = service;
public PacketController(StreamService streamService, PacketService packetService) {
this.streamService = streamService;
this.packetService = packetService;
}
@PostMapping("/all")
public List<Packet> getPackets() {
return Collections.emptyList();
}
@PostMapping("/{stream}")
public List<Packet> getStreams(@PathVariable int stream) {
return Collections.emptyList();
@PostMapping("/{streamId}")
public List<Packet> getPacketsForStream(@PathVariable int streamId, @RequestBody Pagination pagination) {
final Optional<Stream> stream = streamService.find(streamId);
if(stream.isPresent()) {
return packetService.getPacketsForStream(pagination, stream.get());
} else {
return Collections.emptyList();
}
}
}