This commit is contained in:
2026-10-06 14:32:54 +03:00
parent 65003b6119
commit b95197a6fc
75 changed files with 4403 additions and 28 deletions
@@ -0,0 +1,118 @@
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.10.0).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package ru.mtusi.messenger.controller;
import ru.mtusi.messenger.dto.SessionDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Generated;
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.10.0")
@Validated
@Tag(name = "Auth", description = "Аутентификация: вход по Basic и выдача/отзыв сессионного Bearer-токена.")
@RequestMapping("${openapi.mTUSIMessenger2.base-path:}")
public interface AuthApi {
/**
* POST /api/v1/auth/sessions : Вход: Basic username:password; выдаёт сессию
*
* @return Успех (status code 201)
* or Неверный запрос (status code 400)
* or Нет действительной аутентификации (status code 401)
* or Ограничение частоты запросов (status code 429)
* or Зависимость недоступна (status code 503)
* or Неожиданная ошибка без внутренних деталей (status code 500)
*/
@Operation(
operationId = "createSession",
summary = "Вход: Basic username:password; выдаёт сессию",
tags = { "Auth" },
responses = {
@ApiResponse(responseCode = "201", description = "Успех", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = SessionDTO.class))
}),
@ApiResponse(responseCode = "400", description = "Неверный запрос", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = Error.class))
}),
@ApiResponse(responseCode = "401", description = "Нет действительной аутентификации", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = Error.class))
}),
@ApiResponse(responseCode = "429", description = "Ограничение частоты запросов", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = Error.class))
}),
@ApiResponse(responseCode = "503", description = "Зависимость недоступна", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = Error.class))
}),
@ApiResponse(responseCode = "500", description = "Неожиданная ошибка без внутренних деталей", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = Error.class))
})
},
security = {
@SecurityRequirement(name = "basicAuth")
}
)
@RequestMapping(
method = RequestMethod.POST,
value = "/api/v1/auth/sessions",
produces = { "application/json" }
)
ResponseEntity<SessionDTO> createSession(
);
/**
* DELETE /api/v1/auth/sessions/current : Отозвать текущую сессию
*
* @return Успех (status code 204)
* or Нет действительной аутентификации (status code 401)
* or Ограничение частоты запросов (status code 429)
* or Зависимость недоступна (status code 503)
* or Неожиданная ошибка без внутренних деталей (status code 500)
*/
@Operation(
operationId = "revokeSession",
summary = "Отозвать текущую сессию",
tags = { "Auth" },
responses = {
@ApiResponse(responseCode = "204", description = "Успех"),
@ApiResponse(responseCode = "401", description = "Нет действительной аутентификации", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = Error.class))
}),
@ApiResponse(responseCode = "429", description = "Ограничение частоты запросов", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = Error.class))
}),
@ApiResponse(responseCode = "503", description = "Зависимость недоступна", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = Error.class))
}),
@ApiResponse(responseCode = "500", description = "Неожиданная ошибка без внутренних деталей", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = Error.class))
})
},
security = {
@SecurityRequirement(name = "bearerAuth")
}
)
@RequestMapping(
method = RequestMethod.DELETE,
value = "/api/v1/auth/sessions/current",
produces = { "application/json" }
)
ResponseEntity<Void> revokeSession(
);
}
@@ -0,0 +1,28 @@
package ru.mtusi.messenger.controller;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
import ru.mtusi.messenger.dto.SessionDTO;
import ru.mtusi.messenger.service.AuthService;
@RestController
@RequiredArgsConstructor
public class AuthController implements AuthApi {
private final AuthService authService;
private final HttpServletRequest request;
@Override
public ResponseEntity<SessionDTO> createSession() {
return ResponseEntity.status(HttpStatus.CREATED).body(authService.login(request.getHeader(HttpHeaders.AUTHORIZATION)));
}
@Override
public ResponseEntity<Void> revokeSession() {
authService.logout();
return ResponseEntity.noContent().build();
}
}
@@ -0,0 +1,35 @@
package ru.mtusi.messenger.controller;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.RestController;
import ru.mtusi.messenger.dto.ChatDTO;
import ru.mtusi.messenger.dto.ChatPageDTO;
import ru.mtusi.messenger.security.SessionPrincipal;
import ru.mtusi.messenger.service.ChatService;
import java.util.UUID;
@RestController
@RequiredArgsConstructor
public class ChatController implements ChatsApi {
private final ChatService chatService;
@Override
public ResponseEntity<ChatDTO> createChat(ChatDTO chatDTO, @AuthenticationPrincipal SessionPrincipal principal) {
return ResponseEntity.status(HttpStatus.CREATED)
.body(chatService.createChat(principal.userId(), chatDTO));
}
@Override
public ResponseEntity<ChatDTO> getChat(UUID chatId , @AuthenticationPrincipal SessionPrincipal principal) {
return ResponseEntity.ok(chatService.getChat(principal.userId(), chatId));
}
@Override
public ResponseEntity<ChatPageDTO> listChats(Integer limit, String cursor , @AuthenticationPrincipal SessionPrincipal principal) {
return ResponseEntity.ok(chatService.listChats(principal.userId(), limit, cursor));
}
}
@@ -0,0 +1,215 @@
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.10.0).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package ru.mtusi.messenger.controller;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import ru.mtusi.messenger.dto.ChatDTO;
import ru.mtusi.messenger.dto.ChatPageDTO;
import ru.mtusi.messenger.dto.ErrorDTO;
import java.util.UUID;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import jakarta.annotation.Generated;
import ru.mtusi.messenger.security.SessionPrincipal;
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.10.0")
@Validated
@Tag(name = "Chats", description = "Управление чатами и доступ к чатам текущего пользователя.")
@RequestMapping("${openapi.mTUSIMessenger2.base-path:}")
public interface ChatsApi {
/**
* POST /api/v1/chats : Создать чат; вызывающий должен входить в member_ids
*
* @param chatDTO (required)
* @return Успех (status code 201)
* or Неверный запрос (status code 400)
* or Нет действительной аутентификации (status code 401)
* or Объект отсутствует или недоступен (status code 404)
* or Конфликт (status code 409)
* or Ограничение частоты запросов (status code 429)
* or Зависимость недоступна (status code 503)
* or Неожиданная ошибка без внутренних деталей (status code 500)
*/
@Operation(
operationId = "createChat",
summary = "Создать чат; вызывающий должен входить в member_ids",
tags = { "Chats" },
responses = {
@ApiResponse(responseCode = "201", description = "Успех", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ChatDTO.class))
}),
@ApiResponse(responseCode = "400", description = "Неверный запрос", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "401", description = "Нет действительной аутентификации", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "404", description = "Объект отсутствует или недоступен", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "409", description = "Конфликт", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "429", description = "Ограничение частоты запросов", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "503", description = "Зависимость недоступна", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "500", description = "Неожиданная ошибка без внутренних деталей", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
})
},
security = {
@SecurityRequirement(name = "bearerAuth")
}
)
@RequestMapping(
method = RequestMethod.POST,
value = "/api/v1/chats",
produces = { "application/json" },
consumes = { "application/json" }
)
ResponseEntity<ChatDTO> createChat(
@Parameter(name = "CreateChatDTO", description = "", required = true) @Valid @RequestBody ChatDTO chatDTO, @AuthenticationPrincipal SessionPrincipal principal
);
/**
* GET /api/v1/chats/{chat_id} : Получить доступный чат
*
* @param chatId (required)
* @return Успех (status code 200)
* or Неверный запрос (status code 400)
* or Нет действительной аутентификации (status code 401)
* or Объект отсутствует или недоступен (status code 404)
* or Конфликт (status code 409)
* or Ограничение частоты запросов (status code 429)
* or Зависимость недоступна (status code 503)
* or Неожиданная ошибка без внутренних деталей (status code 500)
*/
@Operation(
operationId = "getChat",
summary = "Получить доступный чат",
tags = { "Chats" },
responses = {
@ApiResponse(responseCode = "200", description = "Успех", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ChatDTO.class))
}),
@ApiResponse(responseCode = "400", description = "Неверный запрос", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "401", description = "Нет действительной аутентификации", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "404", description = "Объект отсутствует или недоступен", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "409", description = "Конфликт", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "429", description = "Ограничение частоты запросов", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "503", description = "Зависимость недоступна", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "500", description = "Неожиданная ошибка без внутренних деталей", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
})
},
security = {
@SecurityRequirement(name = "bearerAuth")
}
)
@RequestMapping(
method = RequestMethod.GET,
value = "/api/v1/chats/{chat_id}",
produces = { "application/json" }
)
ResponseEntity<ChatDTO> getChat(
@Parameter(name = "chat_id", description = "", required = true, in = ParameterIn.PATH) @PathVariable("chat_id") UUID chatId,
@AuthenticationPrincipal SessionPrincipal principal
);
/**
* GET /api/v1/chats : Чаты текущего пользователя
*
* @param limit (optional, default to 50)
* @param cursor (optional)
* @return Успех (status code 200)
* or Неверный запрос (status code 400)
* or Нет действительной аутентификации (status code 401)
* or Объект отсутствует или недоступен (status code 404)
* or Конфликт (status code 409)
* or Ограничение частоты запросов (status code 429)
* or Зависимость недоступна (status code 503)
* or Неожиданная ошибка без внутренних деталей (status code 500)
*/
@Operation(
operationId = "listChats",
summary = "Чаты текущего пользователя",
tags = { "Chats" },
responses = {
@ApiResponse(responseCode = "200", description = "Успех", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ChatPageDTO.class))
}),
@ApiResponse(responseCode = "400", description = "Неверный запрос", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "401", description = "Нет действительной аутентификации", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "404", description = "Объект отсутствует или недоступен", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "409", description = "Конфликт", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "429", description = "Ограничение частоты запросов", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "503", description = "Зависимость недоступна", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "500", description = "Неожиданная ошибка без внутренних деталей", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
})
},
security = {
@SecurityRequirement(name = "bearerAuth")
}
)
@RequestMapping(
method = RequestMethod.GET,
value = "/api/v1/chats",
produces = { "application/json" }
)
ResponseEntity<ChatPageDTO> listChats(
@Min(1) @Max(100) @Parameter(name = "limit", description = "", in = ParameterIn.QUERY) @Valid @RequestParam(value = "limit", required = false, defaultValue = "50") Integer limit,
@Size(min = 1) @Parameter(name = "cursor", description = "", in = ParameterIn.QUERY) @Valid @RequestParam(value = "cursor", required = false) String cursor,
@AuthenticationPrincipal SessionPrincipal principal
);
}
@@ -0,0 +1,89 @@
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.10.0).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package ru.mtusi.messenger.controller;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Generated;
import ru.mtusi.messenger.dto.HealthDTO;
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.10.0")
@Validated
@Tag(name = "Health", description = "Проверки живости и готовности процесса. Публичные, без аутентификации.")
@RequestMapping("${openapi.mTUSIMessenger2.base-path:}")
public interface HealthApi {
/**
* GET /health/live : Процесс жив
*
* @return Успех (status code 200)
* or Неожиданная ошибка без внутренних деталей (status code 500)
*/
@Operation(
operationId = "liveness",
summary = "Процесс жив",
tags = { "Health" },
responses = {
@ApiResponse(responseCode = "200", description = "Успех", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = HealthDTO.class))
}),
@ApiResponse(responseCode = "500", description = "Неожиданная ошибка без внутренних деталей", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = Error.class))
})
}
)
@RequestMapping(
method = RequestMethod.GET,
value = "/health/live",
produces = { "application/json" }
)
ResponseEntity<HealthDTO> liveness(
);
/**
* GET /health/ready : Готов принимать трафик
*
* @return Успех (status code 200)
* or Зависимость недоступна (status code 503)
* or Неожиданная ошибка без внутренних деталей (status code 500)
*/
@Operation(
operationId = "readiness",
summary = "Готов принимать трафик",
tags = { "Health" },
responses = {
@ApiResponse(responseCode = "200", description = "Успех", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = HealthDTO.class))
}),
@ApiResponse(responseCode = "503", description = "Зависимость недоступна", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = Error.class))
}),
@ApiResponse(responseCode = "500", description = "Неожиданная ошибка без внутренних деталей", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = Error.class))
})
}
)
@RequestMapping(
method = RequestMethod.GET,
value = "/health/ready",
produces = { "application/json" }
)
ResponseEntity<HealthDTO> readiness(
);
}
@@ -0,0 +1,26 @@
package ru.mtusi.messenger.controller;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
import ru.mtusi.messenger.dto.HealthDTO;
@RestController
public class HealthController implements HealthApi {
private static final HealthDTO OK = createOk();
@Override
public ResponseEntity<HealthDTO> liveness() {
return ResponseEntity.ok(OK);
}
@Override
public ResponseEntity<HealthDTO> readiness() {
return ResponseEntity.ok(OK);
}
private static HealthDTO createOk() {
HealthDTO h = new HealthDTO();
h.setStatus(HealthDTO.StatusEnum.OK);
return h;
}
}
@@ -0,0 +1,29 @@
package ru.mtusi.messenger.controller;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.RestController;
import ru.mtusi.messenger.dto.MessageDTO;
import ru.mtusi.messenger.dto.MessagePageDTO;
import ru.mtusi.messenger.security.SessionPrincipal;
import ru.mtusi.messenger.service.MessageService;
import java.util.UUID;
@RestController
@RequiredArgsConstructor
public class MessageController implements MessagesApi {
private final MessageService messageService;
@Override
public ResponseEntity<MessageDTO> createMessage(UUID chatId, MessageDTO messageDTO, @AuthenticationPrincipal SessionPrincipal principal) {
return ResponseEntity.status(HttpStatus.CREATED).body(messageService.createMessage(principal.userId(), chatId, messageDTO));
}
@Override
public ResponseEntity<MessagePageDTO> listMessages(UUID chatId, Integer limit, String cursor, @AuthenticationPrincipal SessionPrincipal principal) {
return ResponseEntity.ok(messageService.listMessages(principal.userId(), chatId, limit, cursor));
}
}
@@ -0,0 +1,135 @@
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.10.0).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package ru.mtusi.messenger.controller;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import ru.mtusi.messenger.dto.MessageDTO;
import ru.mtusi.messenger.dto.ErrorDTO;
import ru.mtusi.messenger.dto.MessagePageDTO;
import ru.mtusi.messenger.security.SessionPrincipal;
import java.util.UUID;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import jakarta.annotation.Generated;
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.10.0")
@Validated
@Tag(name = "Messages", description = "Отправка и чтение сообщений внутри доступного чата.")
@RequestMapping("${openapi.mTUSIMessenger2.base-path:}")
public interface MessagesApi {
@Operation(
operationId = "createMessage",
summary = "Отправить сообщение",
tags = { "Messages" },
responses = {
@ApiResponse(responseCode = "201", description = "Успех", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = MessageDTO.class))
}),
@ApiResponse(responseCode = "400", description = "Неверный запрос", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "401", description = "Нет действительной аутентификации", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "404", description = "Объект отсутствует или недоступен", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "409", description = "Конфликт", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "429", description = "Ограничение частоты запросов", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "503", description = "Зависимость недоступна", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "500", description = "Неожиданная ошибка без внутренних деталей", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
})
},
security = {
@SecurityRequirement(name = "bearerAuth")
}
)
@RequestMapping(
method = RequestMethod.POST,
value = "/api/v1/chats/{chat_id}/messages",
produces = { "application/json" },
consumes = { "application/json" }
)
ResponseEntity<MessageDTO> createMessage(
@Parameter(name = "chat_id", description = "", required = true, in = ParameterIn.PATH)
@PathVariable("chat_id") UUID chatId,
@Parameter(name = "MessageDTO", description = "", required = true)
@Valid @RequestBody MessageDTO messageDTO,
@AuthenticationPrincipal SessionPrincipal principal
);
@Operation(
operationId = "listMessages",
summary = "Сообщения по (created_at, id) по возрастанию",
tags = { "Messages" },
responses = {
@ApiResponse(responseCode = "200", description = "Успех", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = MessagePageDTO.class))
}),
@ApiResponse(responseCode = "400", description = "Неверный запрос", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "401", description = "Нет действительной аутентификации", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "404", description = "Объект отсутствует или недоступен", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "409", description = "Конфликт", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "429", description = "Ограничение частоты запросов", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "503", description = "Зависимость недоступна", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "500", description = "Неожиданная ошибка без внутренних деталей", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
})
},
security = {
@SecurityRequirement(name = "bearerAuth")
}
)
@RequestMapping(
method = RequestMethod.GET,
value = "/api/v1/chats/{chat_id}/messages",
produces = { "application/json" }
)
ResponseEntity<MessagePageDTO> listMessages(
@Parameter(name = "chat_id", description = "", required = true, in = ParameterIn.PATH)
@PathVariable("chat_id") UUID chatId,
@Min(1) @Max(100)
@Parameter(name = "limit", description = "", in = ParameterIn.QUERY)
@Valid @RequestParam(value = "limit", required = false, defaultValue = "50") Integer limit,
@Size(min = 1)
@Parameter(name = "cursor", description = "", in = ParameterIn.QUERY)
@Valid @RequestParam(value = "cursor", required = false) String cursor,
@AuthenticationPrincipal SessionPrincipal principal
);
}
@@ -0,0 +1,26 @@
package ru.mtusi.messenger.controller;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.RestController;
import ru.mtusi.messenger.dto.UserDTO;
import ru.mtusi.messenger.security.SessionPrincipal;
import ru.mtusi.messenger.service.UserService;
@RestController
@RequiredArgsConstructor
public class UserController implements UsersApi {
private final UserService userService;
@Override
public ResponseEntity<UserDTO> currentUser(@AuthenticationPrincipal SessionPrincipal principal) {
return ResponseEntity.ok(userService.currentUser(principal.userId()));
}
@Override
public ResponseEntity<UserDTO> registerUser(UserDTO userDTO) {
return ResponseEntity.status(HttpStatus.CREATED).body(userService.registerUser(userDTO));
}
}
@@ -0,0 +1,136 @@
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.10.0).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package ru.mtusi.messenger.controller;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import ru.mtusi.messenger.dto.ErrorDTO;
import ru.mtusi.messenger.dto.UserDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import jakarta.annotation.Generated;
import ru.mtusi.messenger.security.SessionPrincipal;
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.10.0")
@Validated
@Tag(name = "Users", description = "Регистрация пользователей и доступ к профилю текущего пользователя.")
@RequestMapping("${openapi.mTUSIMessenger2.base-path:}")
public interface UsersApi {
/**
* GET /api/v1/users/me : Текущий пользователь
*
* @return Успех (status code 200)
* or Неверный запрос (status code 400)
* or Нет действительной аутентификации (status code 401)
* or Объект отсутствует или недоступен (status code 404)
* or Конфликт (status code 409)
* or Ограничение частоты запросов (status code 429)
* or Зависимость недоступна (status code 503)
* or Неожиданная ошибка без внутренних деталей (status code 500)
*/
@Operation(
operationId = "currentUser",
summary = "Текущий пользователь",
tags = { "Users" },
responses = {
@ApiResponse(responseCode = "200", description = "Успех", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = UserDTO.class))
}),
@ApiResponse(responseCode = "400", description = "Неверный запрос", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "401", description = "Нет действительной аутентификации", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "404", description = "Объект отсутствует или недоступен", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "409", description = "Конфликт", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "429", description = "Ограничение частоты запросов", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "503", description = "Зависимость недоступна", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "500", description = "Неожиданная ошибка без внутренних деталей", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
})
},
security = {
@SecurityRequirement(name = "bearerAuth")
}
)
@RequestMapping(
method = RequestMethod.GET,
value = "/api/v1/users/me",
produces = { "application/json" }
)
ResponseEntity<UserDTO> currentUser(
@AuthenticationPrincipal SessionPrincipal principal
);
/**
* POST /api/v1/users : Создать пользователя
*
* @param userDTO (required)
* @return Успех (status code 201)
* or Неверный запрос (status code 400)
* or Конфликт (status code 409)
* or Ограничение частоты запросов (status code 429)
* or Зависимость недоступна (status code 503)
* or Неожиданная ошибка без внутренних деталей (status code 500)
*/
@Operation(
operationId = "registerUser",
summary = "Создать пользователя",
tags = { "Users" },
responses = {
@ApiResponse(responseCode = "201", description = "Успех", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = UserDTO.class))
}),
@ApiResponse(responseCode = "400", description = "Неверный запрос", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "409", description = "Конфликт", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "429", description = "Ограничение частоты запросов", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "503", description = "Зависимость недоступна", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
}),
@ApiResponse(responseCode = "500", description = "Неожиданная ошибка без внутренних деталей", content = {
@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorDTO.class))
})
}
)
@RequestMapping(
method = RequestMethod.POST,
value = "/api/v1/users",
produces = { "application/json" },
consumes = { "application/json" }
)
ResponseEntity<UserDTO> registerUser(
@Parameter(name = "UserDTO", description = "", required = true) @Valid @RequestBody UserDTO userDTO
);
}