package ru.mtusi.messenger.controller; 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 jakarta.validation.Valid; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseStatus; import ru.mtusi.messenger.dto.CreateUserDTO; import ru.mtusi.messenger.dto.ErrorDTO; import ru.mtusi.messenger.dto.UserDTO; import ru.mtusi.messenger.security.SessionPrincipal; /** HTTP-контракт; валидация и описание операций отделены от реализации. */ @Validated @Tag( name = "Users", description = "Регистрация пользователей и доступ к профилю текущего пользователя.") @RequestMapping("${openapi.mTUSIMessenger2.base-path:}") public interface UsersApi { /** Текущий пользователь. */ @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"}) @ResponseStatus(org.springframework.http.HttpStatus.OK) UserDTO currentUser(@AuthenticationPrincipal SessionPrincipal principal); /** Создать пользователя. */ @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"}) @ResponseStatus(org.springframework.http.HttpStatus.CREATED) UserDTO registerUser( @Parameter(name = "CreateUserDTO", description = "", required = true) @Valid @RequestBody CreateUserDTO createUserDTO); }