implemented entity controller
This commit is contained in:
parent
3df58d31b6
commit
8361b52d81
@ -2,7 +2,10 @@ package ru.dragonestia.picker.controller;
|
|||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import ru.dragonestia.picker.model.entity.EntityId;
|
||||||
|
import ru.dragonestia.picker.service.EntityService;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -11,18 +14,26 @@ import java.util.Map;
|
|||||||
@RequestMapping("/entities")
|
@RequestMapping("/entities")
|
||||||
public class EntityController {
|
public class EntityController {
|
||||||
|
|
||||||
|
private final EntityService entityService;
|
||||||
|
|
||||||
@GetMapping("/search")
|
@GetMapping("/search")
|
||||||
List<String> search(@RequestParam String input) {
|
List<String> search(@RequestParam String input) {
|
||||||
throw new UnsupportedOperationException("Not implemented");
|
return entityService.searchEntities(EntityId.of(input)).stream().map(id -> id.getId().getValue()).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/target/rooms")
|
@GetMapping("/target/rooms")
|
||||||
List<String> find(@RequestParam String id) {
|
List<String> find(@RequestParam String id) {
|
||||||
throw new UnsupportedOperationException("Not implemented");
|
return entityService.getEntityRooms(EntityId.of(id)).stream()
|
||||||
|
.map(room -> room.getId().getValue())
|
||||||
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/list/rooms")
|
@GetMapping("/list/rooms")
|
||||||
Map<String, List<String>> roomsOf(@RequestParam List<String> id) {
|
Map<String, List<String>> roomsOf(@RequestParam List<String> id) {
|
||||||
throw new UnsupportedOperationException("Not implemented");
|
var map = new HashMap<String, List<String>>();
|
||||||
|
for (var userId: id) {
|
||||||
|
map.put(userId, find(userId));
|
||||||
|
}
|
||||||
|
return map;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,12 @@ package ru.dragonestia.picker.controller;
|
|||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import ru.dragonestia.picker.exception.DoesNotExistsException;
|
||||||
|
import ru.dragonestia.picker.model.entity.EntityId;
|
||||||
|
import ru.dragonestia.picker.model.instance.InstanceId;
|
||||||
|
import ru.dragonestia.picker.model.room.RoomId;
|
||||||
|
import ru.dragonestia.picker.service.EntityService;
|
||||||
|
import ru.dragonestia.picker.service.RoomService;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -11,9 +17,14 @@ import java.util.List;
|
|||||||
@RequestMapping("/instances/{instanceId}/rooms/{roomId}/users")
|
@RequestMapping("/instances/{instanceId}/rooms/{roomId}/users")
|
||||||
public class EntityRoomController {
|
public class EntityRoomController {
|
||||||
|
|
||||||
|
private final RoomService roomService;
|
||||||
|
private final EntityService entityService;
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
List<String> entitiesInsideRoom(@PathVariable String instanceId, @PathVariable String roomId) {
|
List<String> entitiesInsideRoom(@PathVariable String instanceId, @PathVariable String roomId) {
|
||||||
throw new UnsupportedOperationException("Not implemented");
|
var room = roomService.find(InstanceId.of(instanceId), RoomId.of(roomId))
|
||||||
|
.orElseThrow(() -> DoesNotExistsException.forRoom(RoomId.of(roomId)));
|
||||||
|
return entityService.getRoomEntities(room).stream().map(id -> id.getId().getValue()).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@ -21,13 +32,19 @@ public class EntityRoomController {
|
|||||||
@PathVariable String roomId,
|
@PathVariable String roomId,
|
||||||
@RequestParam List<String> entities,
|
@RequestParam List<String> entities,
|
||||||
@RequestParam(defaultValue = "false") boolean force) {
|
@RequestParam(defaultValue = "false") boolean force) {
|
||||||
throw new UnsupportedOperationException("Not implemented");
|
var room = roomService.find(InstanceId.of(instanceId), RoomId.of(roomId))
|
||||||
|
.orElseThrow(() -> DoesNotExistsException.forRoom(RoomId.of(roomId)));
|
||||||
|
entityService.linkEntitiesWithRoom(room, entities.stream().map(EntityId::of).toList(), force);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@DeleteMapping
|
@DeleteMapping
|
||||||
ResponseEntity<Void> unlinkEntitiesForBucket(@PathVariable String instanceId,
|
ResponseEntity<Void> unlinkEntitiesForBucket(@PathVariable String instanceId,
|
||||||
@PathVariable String roomId,
|
@PathVariable String roomId,
|
||||||
@RequestParam List<String> entities) {
|
@RequestParam List<String> entities) {
|
||||||
throw new UnsupportedOperationException("Not implemented");
|
var room = roomService.find(InstanceId.of(instanceId), RoomId.of(roomId))
|
||||||
|
.orElseThrow(() -> DoesNotExistsException.forRoom(RoomId.of(roomId)));
|
||||||
|
entityService.unlinkEntitiesFromRoom(room, entities.stream().map(EntityId::of).toList());
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user