Documented Users
This commit is contained in:
parent
576a908fcc
commit
0c673950c3
@ -1,3 +1,9 @@
|
||||
package ru.dragonestia.picker.api.repository.response;
|
||||
|
||||
public record LinkUsersWithRoomResponse(int usedSlots, int totalSlots) {}
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
@Schema(title = "Link users with room", hidden = true)
|
||||
public record LinkUsersWithRoomResponse(
|
||||
@Schema(description = "Number of users in room", example = "15") int usedSlots,
|
||||
@Schema(description = "Maximum number of users in room", example = "20") int totalSlots
|
||||
) {}
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
package ru.dragonestia.picker.api.repository.response;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import ru.dragonestia.picker.api.repository.response.type.RRoom;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Schema(title = "Linked rooms with user", hidden = true)
|
||||
public record LinkedRoomsWithUserResponse(List<RRoom.Short> rooms) {}
|
||||
|
||||
@ -1,7 +1,13 @@
|
||||
package ru.dragonestia.picker.api.repository.response;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import ru.dragonestia.picker.api.repository.response.type.RUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record RoomUserListResponse(int slots, int usedSlots, List<RUser> users) {}
|
||||
@Schema(title = "Users inside room", hidden = true)
|
||||
public record RoomUserListResponse(
|
||||
@Schema(description = "Number of users in room", example = "15") int slots,
|
||||
@Schema(description = "Maximum number of users in room", example = "20") int usedSlots,
|
||||
@Schema(description = "Users") List<RUser> users
|
||||
) {}
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
package ru.dragonestia.picker.api.repository.response;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import ru.dragonestia.picker.api.repository.response.type.RUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Schema(title = "Search user", hidden = true)
|
||||
public record SearchUserResponse(List<RUser> users) {}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package ru.dragonestia.picker.api.repository.response;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import ru.dragonestia.picker.api.repository.response.type.RUser;
|
||||
|
||||
@Schema(title = "User details", hidden = true)
|
||||
public record UserDetailsResponse(RUser user) {}
|
||||
|
||||
@ -1,13 +1,18 @@
|
||||
package ru.dragonestia.picker.api.repository.response.type;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import ru.dragonestia.picker.api.repository.details.UserDetails;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Schema(title = "User")
|
||||
public class RUser {
|
||||
|
||||
@Schema(description = "User identifier", example = "test-user")
|
||||
private String id;
|
||||
|
||||
@Schema(description = "Additional data requested (Key-Value)")
|
||||
private Map<UserDetails, String> details = new HashMap<>();
|
||||
|
||||
private RUser() {}
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
package ru.dragonestia.picker.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import ru.dragonestia.picker.api.repository.response.LinkedRoomsWithUserResponse;
|
||||
@ -14,6 +17,7 @@ import ru.dragonestia.picker.util.NamingValidator;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "Users", description = "User management")
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/users")
|
||||
@ -23,10 +27,12 @@ public class UserController {
|
||||
private final DetailsParser detailsParser;
|
||||
private final NamingValidator namingValidator;
|
||||
|
||||
@Operation(summary = "Search user by identifier")
|
||||
@GetMapping("/search")
|
||||
SearchUserResponse search(@RequestParam(name = "input") String input,
|
||||
@RequestParam(name = "requiredDetails", required = false, defaultValue = "") String detailsSeq) {
|
||||
|
||||
SearchUserResponse search(
|
||||
@Parameter(description = "User identifier input") @RequestParam(name = "input") String input,
|
||||
@Parameter(description = "Required addition user data", example = "COUNT_ROOMS") @RequestParam(name = "requiredDetails", required = false, defaultValue = "") String detailsSeq
|
||||
) {
|
||||
if (!namingValidator.validateUserId(input) || input.isEmpty()) {
|
||||
return new SearchUserResponse(List.of());
|
||||
}
|
||||
@ -34,10 +40,12 @@ public class UserController {
|
||||
return new SearchUserResponse(userService.searchUsers(input, detailsParser.parseUserDetails(detailsSeq)));
|
||||
}
|
||||
|
||||
@Operation(summary = "Get user info")
|
||||
@GetMapping("/{userId}")
|
||||
UserDetailsResponse find(@PathVariable(value = "userId") String userId,
|
||||
@RequestParam(value = "requiredDetails", required = false) String detailsSeq) {
|
||||
|
||||
UserDetailsResponse find(
|
||||
@Parameter(description = "User identifier") @PathVariable(value = "userId") String userId,
|
||||
@Parameter(description = "Required addition user data", example = "COUNT_ROOMS") @RequestParam(value = "requiredDetails", required = false) String detailsSeq
|
||||
) {
|
||||
if (!namingValidator.validateUserId(userId)) {
|
||||
return new UserDetailsResponse(new RUser(userId));
|
||||
}
|
||||
@ -45,10 +53,12 @@ public class UserController {
|
||||
return new UserDetailsResponse(userService.getUserDetails(userId, detailsParser.parseUserDetails(detailsSeq)));
|
||||
}
|
||||
|
||||
@Operation(summary = "Get rooms linked with user")
|
||||
@GetMapping("/{userId}/rooms")
|
||||
LinkedRoomsWithUserResponse roomsOf(@PathVariable(value = "userId") String userId,
|
||||
@RequestParam(value = "requiredDetails", required = false) String detailsSeq) {
|
||||
|
||||
LinkedRoomsWithUserResponse roomsOf(
|
||||
@Parameter(description = "User identifier") @PathVariable(value = "userId") String userId,
|
||||
@Parameter(description = "Required addition room data", example = "COUNT_USERS") @RequestParam(value = "requiredDetails", required = false) String detailsSeq
|
||||
) {
|
||||
if (!namingValidator.validateUserId(userId)) {
|
||||
return new LinkedRoomsWithUserResponse(List.of());
|
||||
}
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
package ru.dragonestia.picker.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -17,6 +20,7 @@ import ru.dragonestia.picker.util.NamingValidator;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Tag(name = "Users", description = "User management")
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/nodes/{nodeId}/rooms/{roomId}/users")
|
||||
@ -28,33 +32,40 @@ public class UserRoomController {
|
||||
private final NamingValidator namingValidator;
|
||||
private final DetailsParser detailsParser;
|
||||
|
||||
@Operation(summary = "Get users inside room")
|
||||
@GetMapping
|
||||
ResponseEntity<RoomUserListResponse> usersInsideRoom(@PathVariable(name = "nodeId") String nodeId,
|
||||
@PathVariable(name = "roomId") String roomId,
|
||||
@RequestParam(name = "requiredDetails", required = false, defaultValue = "") String detailsSeq) {
|
||||
|
||||
ResponseEntity<RoomUserListResponse> usersInsideRoom(
|
||||
@Parameter(description = "Node identifier") @PathVariable(name = "nodeId") String nodeId,
|
||||
@Parameter(description = "Room identifier") @PathVariable(name = "roomId") String roomId,
|
||||
@Parameter(description = "Required addition user data", example = "COUNT_ROOMS") @RequestParam(name = "requiredDetails", required = false, defaultValue = "") String detailsSeq
|
||||
) {
|
||||
var room = getNodeAndRoom(nodeId, roomId).room();
|
||||
var users = userService.getRoomUsersWithDetailsResponse(room, detailsParser.parseUserDetails(detailsSeq));
|
||||
|
||||
return ResponseEntity.ok(new RoomUserListResponse(room.getSlots().getSlots(), users.size(), users));
|
||||
}
|
||||
|
||||
@Operation(summary = "Link users with room")
|
||||
@PostMapping
|
||||
ResponseEntity<LinkUsersWithRoomResponse> linkUserWithRoom(@PathVariable(name = "nodeId") String nodeId,
|
||||
@PathVariable(name = "roomId") String roomId,
|
||||
@RequestParam(name = "userIds") String userIds,
|
||||
@RequestParam(name = "force") boolean force) {
|
||||
|
||||
ResponseEntity<LinkUsersWithRoomResponse> linkUserWithRoom(
|
||||
@Parameter(description = "Node identifier") @PathVariable(name = "nodeId") String nodeId,
|
||||
@Parameter(description = "Room identifier") @PathVariable(name = "roomId") String roomId,
|
||||
@Parameter(description = "User identifiers", example = "user1,user2,user3") @RequestParam(name = "userIds") String userIds,
|
||||
@Parameter(description = "Ignore slot limitation") @RequestParam(name = "force") boolean force
|
||||
) {
|
||||
var room = getNodeAndRoom(nodeId, roomId).room();
|
||||
var users = namingValidator.validateUserIds(Arrays.stream(userIds.split(",")).toList());
|
||||
var usedSlots = userService.linkUsersWithRoom(room, users, force);
|
||||
return ResponseEntity.ok(new LinkUsersWithRoomResponse(usedSlots, room.getSlots().getSlots()));
|
||||
}
|
||||
|
||||
@Operation(summary = "Unlink users from room")
|
||||
@DeleteMapping
|
||||
ResponseEntity<?> unlinkUsersForBucket(@PathVariable(name = "nodeId") String nodeId,
|
||||
@PathVariable(name = "roomId") String roomId,
|
||||
@RequestParam(name = "userIds") String userIds) {
|
||||
ResponseEntity<?> unlinkUsersForBucket(
|
||||
@Parameter(description = "Node identifier") @PathVariable(name = "nodeId") String nodeId,
|
||||
@Parameter(description = "Room identifier") @PathVariable(name = "roomId") String roomId,
|
||||
@Parameter(description = "User identifiers", example = "user1,user2,user3") @RequestParam(name = "userIds") String userIds
|
||||
) {
|
||||
|
||||
var room = getNodeAndRoom(nodeId, roomId).room();
|
||||
var users = namingValidator.validateUserIds(Arrays.stream(userIds.split(",")).toList());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user