feat: add API versioning , translate swagger, remove rate limiter
This commit is contained in:
+53
-47
@@ -17,16 +17,17 @@ func NewHandler(service *Service) *Handler {
|
||||
return &Handler{service: service}
|
||||
}
|
||||
|
||||
// @Summary Register
|
||||
// @Description Создание учетной записи пользователя с полями username, email, password
|
||||
// @Summary Регистрация
|
||||
// @Description Создание новой учётной записи. После успешной регистрации сразу возвращается access_token и refresh_token.
|
||||
// @Description Пароль должен содержать минимум 8 символов, заглавную букву, строчную букву и цифру.
|
||||
// @Tags auth
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param request body RegisterRequest true "Registration details"
|
||||
// @Success 201 {object} AuthResponse
|
||||
// @Failure 400 {object} ErrorResponse
|
||||
// @Failure 409 {object} ErrorResponse
|
||||
// @Router /api/auth/register [post]
|
||||
// @Param request body RegisterRequest true "Данные для регистрации"
|
||||
// @Success 201 {object} AuthResponse "Пользователь создан, токены в ответе"
|
||||
// @Failure 400 {object} ErrorResponse "Ошибка валидации полей (некорректный email, слабый пароль)"
|
||||
// @Failure 409 {object} ErrorResponse "Email уже зарегистрирован"
|
||||
// @Router /api/v1/auth/register [post]
|
||||
func (h *Handler) Register(c *gin.Context) {
|
||||
var req RegisterRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -52,16 +53,16 @@ func (h *Handler) Register(c *gin.Context) {
|
||||
c.JSON(http.StatusCreated, resp)
|
||||
}
|
||||
|
||||
// @Summary Login
|
||||
// @Description Аунтефикация пользователя с помощью email и password, возвращает JWT token
|
||||
// @Summary Вход
|
||||
// @Description Аутентификация по email и паролю. Возвращает access_token (JWT) и refresh_token.
|
||||
// @Tags auth
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param request body LoginRequest true "Login credentials"
|
||||
// @Success 200 {object} AuthResponse
|
||||
// @Failure 400 {object} ErrorResponse
|
||||
// @Failure 401 {object} ErrorResponse
|
||||
// @Router /api/auth/login [post]
|
||||
// @Param request body LoginRequest true "Email и пароль"
|
||||
// @Success 200 {object} AuthResponse "Успешный вход, токены в ответе"
|
||||
// @Failure 400 {object} ErrorResponse "Ошибка валидации полей"
|
||||
// @Failure 401 {object} ErrorResponse "Неверный email или пароль"
|
||||
// @Router /api/v1/auth/login [post]
|
||||
func (h *Handler) Login(c *gin.Context) {
|
||||
var req LoginRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -83,16 +84,17 @@ func (h *Handler) Login(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// @Summary Refresh token
|
||||
// @Description Получение ново
|
||||
// @Summary Обновление токенов
|
||||
// @Description Получение новой пары токенов по refresh_token. Старый refresh_token становится недействительным (ротация).
|
||||
// @Description Если refresh_token истёк или уже был использован — придёт 401.
|
||||
// @Tags auth
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param request body RefreshRequest true "Refresh token"
|
||||
// @Success 200 {object} AuthResponse
|
||||
// @Failure 400 {object} ErrorResponse
|
||||
// @Failure 401 {object} ErrorResponse
|
||||
// @Router /api/auth/refresh [post]
|
||||
// @Param request body RefreshRequest true "Действительный refresh_token"
|
||||
// @Success 200 {object} AuthResponse "Новая пара токенов"
|
||||
// @Failure 400 {object} ErrorResponse "Не указан refresh_token"
|
||||
// @Failure 401 {object} ErrorResponse "Refresh_token недействителен или истёк"
|
||||
// @Router /api/v1/auth/refresh [post]
|
||||
func (h *Handler) Refresh(c *gin.Context) {
|
||||
var req RefreshRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -114,16 +116,16 @@ func (h *Handler) Refresh(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// @Summary Logout
|
||||
// @Description Аннулирует refresh token
|
||||
// @Summary Выход
|
||||
// @Description Аннулирование refresh_token. После выхода повторное использование того же refresh_token вернёт 401.
|
||||
// @Tags auth
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param request body LogoutRequest true "Refresh token to invalidate"
|
||||
// @Success 200 {object} map[string]string
|
||||
// @Failure 400 {object} ErrorResponse
|
||||
// @Failure 401 {object} ErrorResponse
|
||||
// @Router /api/auth/logout [post]
|
||||
// @Param request body LogoutRequest true "Refresh_token для аннулирования"
|
||||
// @Success 200 {object} map[string]string "{"message": "logged out successfully"}"
|
||||
// @Failure 400 {object} ErrorResponse "Не указан refresh_token"
|
||||
// @Failure 401 {object} ErrorResponse "Refresh_token не найден или уже аннулирован"
|
||||
// @Router /api/v1/auth/logout [post]
|
||||
func (h *Handler) Logout(c *gin.Context) {
|
||||
var req LogoutRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
@@ -144,15 +146,16 @@ func (h *Handler) Logout(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"message": "logged out successfully"})
|
||||
}
|
||||
|
||||
// @Summary Get current user
|
||||
// @Description Получить профиль авторизованного пользователя
|
||||
// @Summary Профиль пользователя
|
||||
// @Description Получение профиля текущего авторизованного пользователя.
|
||||
// @Description **Требуется:** заголовок `Authorization: Bearer <token>`.
|
||||
// @Tags auth
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security Bearer
|
||||
// @Success 200 {object} UserResponse
|
||||
// @Failure 401 {object} ErrorResponse
|
||||
// @Router /api/auth/me [get]
|
||||
// @Success 200 {object} UserResponse "Данные пользователя"
|
||||
// @Failure 401 {object} ErrorResponse "Токен не указан или недействителен"
|
||||
// @Router /api/v1/auth/me [get]
|
||||
func (h *Handler) Me(c *gin.Context) {
|
||||
userID := api.GetUserID(c)
|
||||
if userID == "" {
|
||||
@@ -174,17 +177,19 @@ func (h *Handler) Me(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, UserResponse{User: *user})
|
||||
}
|
||||
|
||||
// @Summary Change password
|
||||
// @Description Изменить текущий password пользователя
|
||||
// @Summary Смена пароля
|
||||
// @Description Изменение пароля текущего пользователя. Требуется указать старый и новый пароль.
|
||||
// @Description **Требуется:** заголовок `Authorization: Bearer <token>`.
|
||||
// @Description Пароль должен содержать минимум 8 символов, заглавную букву, строчную букву и цифру.
|
||||
// @Tags auth
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security Bearer
|
||||
// @Param request body PasswordChangeRequest true "Password change details"
|
||||
// @Success 200 {object} map[string]string
|
||||
// @Failure 400 {object} ErrorResponse
|
||||
// @Failure 401 {object} ErrorResponse
|
||||
// @Router /api/auth/password [put]
|
||||
// @Param request body PasswordChangeRequest true "Старый и новый пароль"
|
||||
// @Success 200 {object} map[string]string "{"message": "password changed successfully"}"
|
||||
// @Failure 400 {object} ErrorResponse "Ошибка валидации: неверный старый пароль, слабый новый или совпадают"
|
||||
// @Failure 401 {object} ErrorResponse "Токен не указан или недействителен"
|
||||
// @Router /api/v1/auth/password [put]
|
||||
func (h *Handler) ChangePassword(c *gin.Context) {
|
||||
userID := api.GetUserID(c)
|
||||
if userID == "" {
|
||||
@@ -216,17 +221,18 @@ func (h *Handler) ChangePassword(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"message": "password changed successfully"})
|
||||
}
|
||||
|
||||
// @Summary Update profile
|
||||
// @Description Обновить username текущего пользователя
|
||||
// @Summary Обновление профиля
|
||||
// @Description Обновление username текущего пользователя.
|
||||
// @Description **Требуется:** заголовок `Authorization: Bearer <token>`.
|
||||
// @Tags auth
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security Bearer
|
||||
// @Param request body UpdateProfileRequest true "Profile update"
|
||||
// @Success 200 {object} UserResponse
|
||||
// @Failure 400 {object} ErrorResponse
|
||||
// @Failure 401 {object} ErrorResponse
|
||||
// @Router /api/auth/me [put]
|
||||
// @Param request body UpdateProfileRequest true "Новый username"
|
||||
// @Success 200 {object} UserResponse "Обновлённый профиль"
|
||||
// @Failure 400 {object} ErrorResponse "Ошибка валидации: username от 3 до 30 символов"
|
||||
// @Failure 401 {object} ErrorResponse "Токен не указан или недействителен"
|
||||
// @Router /api/v1/auth/me [put]
|
||||
func (h *Handler) UpdateProfile(c *gin.Context) {
|
||||
userID := api.GetUserID(c)
|
||||
if userID == "" {
|
||||
|
||||
Reference in New Issue
Block a user