feat: add API versioning , translate swagger, remove rate limiter
This commit is contained in:
+10
-9
@@ -12,7 +12,6 @@ import (
|
|||||||
docs "gitea.d3m0k1d.ru/HellreigN/Control-plane/docs"
|
docs "gitea.d3m0k1d.ru/HellreigN/Control-plane/docs"
|
||||||
"gitea.d3m0k1d.ru/HellreigN/Control-plane/internal/auth"
|
"gitea.d3m0k1d.ru/HellreigN/Control-plane/internal/auth"
|
||||||
"gitea.d3m0k1d.ru/HellreigN/Control-plane/internal/config"
|
"gitea.d3m0k1d.ru/HellreigN/Control-plane/internal/config"
|
||||||
"gitea.d3m0k1d.ru/HellreigN/Control-plane/internal/middleware"
|
|
||||||
"gitea.d3m0k1d.ru/HellreigN/Control-plane/internal/org"
|
"gitea.d3m0k1d.ru/HellreigN/Control-plane/internal/org"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/pressly/goose/v3"
|
"github.com/pressly/goose/v3"
|
||||||
@@ -24,13 +23,16 @@ import (
|
|||||||
|
|
||||||
// @title AegisGuard API
|
// @title AegisGuard API
|
||||||
// @version 1.0
|
// @version 1.0
|
||||||
// @description API для AegisGuard control plane
|
// @description API системы управления AegisGuard. Позволяет управлять пользователями и организациями.
|
||||||
|
// @description Все защищённые эндпоинты требуют заголовок `Authorization: Bearer <token>`.
|
||||||
|
// @description Токен получается при регистрации или входе.
|
||||||
// @schemes http
|
// @schemes http
|
||||||
|
// @BasePath /api/v1
|
||||||
//
|
//
|
||||||
// @securityDefinitions.apikey Bearer
|
// @securityDefinitions.apikey Bearer
|
||||||
// @in header
|
// @in header
|
||||||
// @name Authorization
|
// @name Authorization
|
||||||
// @description Type "Bearer" followed by a space and the JWT token.
|
// @description Введите `Bearer <token>`, где token — access_token из ответа /auth/login или /auth/register
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cfg, err := config.Load()
|
cfg, err := config.Load()
|
||||||
@@ -70,7 +72,6 @@ func main() {
|
|||||||
orgSvc := org.NewService(orgRepo)
|
orgSvc := org.NewService(orgRepo)
|
||||||
orgHandler := org.NewHandler(orgSvc)
|
orgHandler := org.NewHandler(orgSvc)
|
||||||
|
|
||||||
loginLimiter := middleware.NewRateLimiter(10, time.Minute)
|
|
||||||
authMW := auth.AuthMiddleware([]byte(cfg.JWTSecret))
|
authMW := auth.AuthMiddleware([]byte(cfg.JWTSecret))
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@@ -91,17 +92,18 @@ func main() {
|
|||||||
|
|
||||||
docs.SwaggerInfo.Title = "AegisGuard API"
|
docs.SwaggerInfo.Title = "AegisGuard API"
|
||||||
docs.SwaggerInfo.Version = "1.0"
|
docs.SwaggerInfo.Version = "1.0"
|
||||||
docs.SwaggerInfo.Description = "API for AegisGuard"
|
docs.SwaggerInfo.Description = "API системы управления AegisGuard. Позволяет управлять пользователями и организациями."
|
||||||
docs.SwaggerInfo.Schemes = []string{"http"}
|
docs.SwaggerInfo.Schemes = []string{"http"}
|
||||||
|
docs.SwaggerInfo.BasePath = "/api/v1"
|
||||||
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||||
r.GET("/health", func(c *gin.Context) {
|
r.GET("/health", func(c *gin.Context) {
|
||||||
c.JSON(200, gin.H{"status": "ok"})
|
c.JSON(200, gin.H{"status": "ok"})
|
||||||
})
|
})
|
||||||
|
|
||||||
api := r.Group("/api/auth")
|
api := r.Group("/api/v1/auth")
|
||||||
{
|
{
|
||||||
api.POST("/register", handler.Register)
|
api.POST("/register", handler.Register)
|
||||||
api.POST("/login", loginLimiter.Middleware(), handler.Login)
|
api.POST("/login", handler.Login)
|
||||||
api.POST("/refresh", handler.Refresh)
|
api.POST("/refresh", handler.Refresh)
|
||||||
api.POST("/logout", handler.Logout)
|
api.POST("/logout", handler.Logout)
|
||||||
api.GET("/me", authMW, handler.Me)
|
api.GET("/me", authMW, handler.Me)
|
||||||
@@ -109,7 +111,7 @@ func main() {
|
|||||||
api.PUT("/password", authMW, handler.ChangePassword)
|
api.PUT("/password", authMW, handler.ChangePassword)
|
||||||
}
|
}
|
||||||
|
|
||||||
orgs := r.Group("/api/organizations", authMW)
|
orgs := r.Group("/api/v1/organizations", authMW)
|
||||||
{
|
{
|
||||||
orgs.POST("", orgHandler.Create)
|
orgs.POST("", orgHandler.Create)
|
||||||
orgs.GET("", orgHandler.List)
|
orgs.GET("", orgHandler.List)
|
||||||
@@ -144,7 +146,6 @@ func main() {
|
|||||||
log.Fatalf("server forced to shutdown: %v", err)
|
log.Fatalf("server forced to shutdown: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
loginLimiter.Stop()
|
|
||||||
_ = sqlDB.Close()
|
_ = sqlDB.Close()
|
||||||
|
|
||||||
log.Println("server stopped")
|
log.Println("server stopped")
|
||||||
|
|||||||
+98
-78
@@ -15,9 +15,9 @@ const docTemplate = `{
|
|||||||
"host": "{{.Host}}",
|
"host": "{{.Host}}",
|
||||||
"basePath": "{{.BasePath}}",
|
"basePath": "{{.BasePath}}",
|
||||||
"paths": {
|
"paths": {
|
||||||
"/api/auth/login": {
|
"/api/v1/auth/login": {
|
||||||
"post": {
|
"post": {
|
||||||
"description": "Authenticate user with email and password, returns JWT token",
|
"description": "Аутентификация по email и паролю. Возвращает access_token (JWT) и refresh_token.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -27,10 +27,10 @@ const docTemplate = `{
|
|||||||
"tags": [
|
"tags": [
|
||||||
"auth"
|
"auth"
|
||||||
],
|
],
|
||||||
"summary": "Login",
|
"summary": "Вход",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"description": "Login credentials",
|
"description": "Email и пароль",
|
||||||
"name": "request",
|
"name": "request",
|
||||||
"in": "body",
|
"in": "body",
|
||||||
"required": true,
|
"required": true,
|
||||||
@@ -41,19 +41,19 @@ const docTemplate = `{
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "Успешный вход, токены в ответе",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.AuthResponse"
|
"$ref": "#/definitions/auth.AuthResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Ошибка валидации полей",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
"description": "Unauthorized",
|
"description": "Неверный email или пароль",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
@@ -61,9 +61,9 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/api/auth/logout": {
|
"/api/v1/auth/logout": {
|
||||||
"post": {
|
"post": {
|
||||||
"description": "Invalidate a refresh token (logout)",
|
"description": "Аннулирование refresh_token. После выхода повторное использование того же refresh_token вернёт 401.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -73,10 +73,10 @@ const docTemplate = `{
|
|||||||
"tags": [
|
"tags": [
|
||||||
"auth"
|
"auth"
|
||||||
],
|
],
|
||||||
"summary": "Logout",
|
"summary": "Выход",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"description": "Refresh token to invalidate",
|
"description": "Refresh_token для аннулирования",
|
||||||
"name": "request",
|
"name": "request",
|
||||||
"in": "body",
|
"in": "body",
|
||||||
"required": true,
|
"required": true,
|
||||||
@@ -87,7 +87,7 @@ const docTemplate = `{
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "{\"message\": \"logged out successfully\"}",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": {
|
"additionalProperties": {
|
||||||
@@ -96,13 +96,13 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Не указан refresh_token",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
"description": "Unauthorized",
|
"description": "Refresh_token не найден или уже аннулирован",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
@@ -110,14 +110,14 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/api/auth/me": {
|
"/api/v1/auth/me": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
{
|
{
|
||||||
"Bearer": []
|
"Bearer": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Get authenticated user's profile",
|
"description": "Получение профиля текущего авторизованного пользователя.\n**Требуется:** заголовок ` + "`" + `Authorization: Bearer \u003ctoken\u003e` + "`" + `.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -127,16 +127,16 @@ const docTemplate = `{
|
|||||||
"tags": [
|
"tags": [
|
||||||
"auth"
|
"auth"
|
||||||
],
|
],
|
||||||
"summary": "Get current user",
|
"summary": "Профиль пользователя",
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "Данные пользователя",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.UserResponse"
|
"$ref": "#/definitions/auth.UserResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
"description": "Unauthorized",
|
"description": "Токен не указан или недействителен",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
@@ -149,7 +149,7 @@ const docTemplate = `{
|
|||||||
"Bearer": []
|
"Bearer": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Update current user's username",
|
"description": "Обновление username текущего пользователя.\n**Требуется:** заголовок ` + "`" + `Authorization: Bearer \u003ctoken\u003e` + "`" + `.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -159,10 +159,10 @@ const docTemplate = `{
|
|||||||
"tags": [
|
"tags": [
|
||||||
"auth"
|
"auth"
|
||||||
],
|
],
|
||||||
"summary": "Update profile",
|
"summary": "Обновление профиля",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"description": "Profile update",
|
"description": "Новый username",
|
||||||
"name": "request",
|
"name": "request",
|
||||||
"in": "body",
|
"in": "body",
|
||||||
"required": true,
|
"required": true,
|
||||||
@@ -173,19 +173,19 @@ const docTemplate = `{
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "Обновлённый профиль",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.UserResponse"
|
"$ref": "#/definitions/auth.UserResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Ошибка валидации: username от 3 до 30 символов",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
"description": "Unauthorized",
|
"description": "Токен не указан или недействителен",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
@@ -193,14 +193,14 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/api/auth/password": {
|
"/api/v1/auth/password": {
|
||||||
"put": {
|
"put": {
|
||||||
"security": [
|
"security": [
|
||||||
{
|
{
|
||||||
"Bearer": []
|
"Bearer": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Change current user's password",
|
"description": "Изменение пароля текущего пользователя. Требуется указать старый и новый пароль.\n**Требуется:** заголовок ` + "`" + `Authorization: Bearer \u003ctoken\u003e` + "`" + `.\nПароль должен содержать минимум 8 символов, заглавную букву, строчную букву и цифру.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -210,10 +210,10 @@ const docTemplate = `{
|
|||||||
"tags": [
|
"tags": [
|
||||||
"auth"
|
"auth"
|
||||||
],
|
],
|
||||||
"summary": "Change password",
|
"summary": "Смена пароля",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"description": "Password change details",
|
"description": "Старый и новый пароль",
|
||||||
"name": "request",
|
"name": "request",
|
||||||
"in": "body",
|
"in": "body",
|
||||||
"required": true,
|
"required": true,
|
||||||
@@ -224,7 +224,7 @@ const docTemplate = `{
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "{\"message\": \"password changed successfully\"}",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": {
|
"additionalProperties": {
|
||||||
@@ -233,13 +233,13 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Ошибка валидации: неверный старый пароль, слабый новый или совпадают",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
"description": "Unauthorized",
|
"description": "Токен не указан или недействителен",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
@@ -247,9 +247,9 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/api/auth/refresh": {
|
"/api/v1/auth/refresh": {
|
||||||
"post": {
|
"post": {
|
||||||
"description": "Get a new access token using a refresh token",
|
"description": "Получение новой пары токенов по refresh_token. Старый refresh_token становится недействительным (ротация).\nЕсли refresh_token истёк или уже был использован — придёт 401.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -259,10 +259,10 @@ const docTemplate = `{
|
|||||||
"tags": [
|
"tags": [
|
||||||
"auth"
|
"auth"
|
||||||
],
|
],
|
||||||
"summary": "Refresh token",
|
"summary": "Обновление токенов",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"description": "Refresh token",
|
"description": "Действительный refresh_token",
|
||||||
"name": "request",
|
"name": "request",
|
||||||
"in": "body",
|
"in": "body",
|
||||||
"required": true,
|
"required": true,
|
||||||
@@ -273,19 +273,19 @@ const docTemplate = `{
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "Новая пара токенов",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.AuthResponse"
|
"$ref": "#/definitions/auth.AuthResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Не указан refresh_token",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
"description": "Unauthorized",
|
"description": "Refresh_token недействителен или истёк",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
@@ -293,9 +293,9 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/api/auth/register": {
|
"/api/v1/auth/register": {
|
||||||
"post": {
|
"post": {
|
||||||
"description": "Create user account with username, email, password",
|
"description": "Создание новой учётной записи. После успешной регистрации сразу возвращается access_token и refresh_token.\nПароль должен содержать минимум 8 символов, заглавную букву, строчную букву и цифру.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -305,10 +305,10 @@ const docTemplate = `{
|
|||||||
"tags": [
|
"tags": [
|
||||||
"auth"
|
"auth"
|
||||||
],
|
],
|
||||||
"summary": "Register",
|
"summary": "Регистрация",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"description": "Registration details",
|
"description": "Данные для регистрации",
|
||||||
"name": "request",
|
"name": "request",
|
||||||
"in": "body",
|
"in": "body",
|
||||||
"required": true,
|
"required": true,
|
||||||
@@ -319,19 +319,19 @@ const docTemplate = `{
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"201": {
|
"201": {
|
||||||
"description": "Created",
|
"description": "Пользователь создан, токены в ответе",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.AuthResponse"
|
"$ref": "#/definitions/auth.AuthResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Ошибка валидации полей (некорректный email, слабый пароль)",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"409": {
|
"409": {
|
||||||
"description": "Conflict",
|
"description": "Email уже зарегистрирован",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
@@ -339,14 +339,14 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/api/organizations": {
|
"/api/v1/organizations": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
{
|
{
|
||||||
"Bearer": []
|
"Bearer": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Get all organizations",
|
"description": "Получение списка всех организаций с пагинацией.\n**Требуется:** заголовок ` + "`" + `Authorization: Bearer \u003ctoken\u003e` + "`" + `.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -356,16 +356,30 @@ const docTemplate = `{
|
|||||||
"tags": [
|
"tags": [
|
||||||
"organizations"
|
"organizations"
|
||||||
],
|
],
|
||||||
"summary": "List organizations",
|
"summary": "Список организаций",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Количество записей на странице (по умолчанию 20)",
|
||||||
|
"name": "limit",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Смещение от начала списка (по умолчанию 0)",
|
||||||
|
"name": "offset",
|
||||||
|
"in": "query"
|
||||||
|
}
|
||||||
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "Список организаций",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/org.OrgListResponse"
|
"$ref": "#/definitions/org.OrgListResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Внутренняя ошибка сервера",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/org.ErrorResponse"
|
"$ref": "#/definitions/org.ErrorResponse"
|
||||||
}
|
}
|
||||||
@@ -378,7 +392,7 @@ const docTemplate = `{
|
|||||||
"Bearer": []
|
"Bearer": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Create a new organization",
|
"description": "Создание новой организации. slug используется в URL и должен быть уникальным.\n**Требуется:** заголовок ` + "`" + `Authorization: Bearer \u003ctoken\u003e` + "`" + `.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -388,10 +402,10 @@ const docTemplate = `{
|
|||||||
"tags": [
|
"tags": [
|
||||||
"organizations"
|
"organizations"
|
||||||
],
|
],
|
||||||
"summary": "Create organization",
|
"summary": "Создание организации",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"description": "Organization details",
|
"description": "Название и slug организации",
|
||||||
"name": "request",
|
"name": "request",
|
||||||
"in": "body",
|
"in": "body",
|
||||||
"required": true,
|
"required": true,
|
||||||
@@ -402,19 +416,19 @@ const docTemplate = `{
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"201": {
|
"201": {
|
||||||
"description": "Created",
|
"description": "Организация создана",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/org.OrgResponse"
|
"$ref": "#/definitions/org.OrgResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Ошибка валидации полей",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/org.ErrorResponse"
|
"$ref": "#/definitions/org.ErrorResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"409": {
|
"409": {
|
||||||
"description": "Conflict",
|
"description": "Slug уже занят",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/org.ErrorResponse"
|
"$ref": "#/definitions/org.ErrorResponse"
|
||||||
}
|
}
|
||||||
@@ -422,14 +436,14 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/api/organizations/{id}": {
|
"/api/v1/organizations/{id}": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
{
|
{
|
||||||
"Bearer": []
|
"Bearer": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Get organization details",
|
"description": "Получение информации об организации по её ID.\n**Требуется:** заголовок ` + "`" + `Authorization: Bearer \u003ctoken\u003e` + "`" + `.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -439,11 +453,11 @@ const docTemplate = `{
|
|||||||
"tags": [
|
"tags": [
|
||||||
"organizations"
|
"organizations"
|
||||||
],
|
],
|
||||||
"summary": "Get organization by ID",
|
"summary": "Получить организацию",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Organization ID",
|
"description": "UUID организации",
|
||||||
"name": "id",
|
"name": "id",
|
||||||
"in": "path",
|
"in": "path",
|
||||||
"required": true
|
"required": true
|
||||||
@@ -451,13 +465,13 @@ const docTemplate = `{
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "Данные организации",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/org.OrgResponse"
|
"$ref": "#/definitions/org.OrgResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"404": {
|
"404": {
|
||||||
"description": "Not Found",
|
"description": "Организация не найдена",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/org.ErrorResponse"
|
"$ref": "#/definitions/org.ErrorResponse"
|
||||||
}
|
}
|
||||||
@@ -470,7 +484,7 @@ const docTemplate = `{
|
|||||||
"Bearer": []
|
"Bearer": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Update organization name",
|
"description": "Обновление названия организации. slug изменить нельзя.\n**Требуется:** заголовок ` + "`" + `Authorization: Bearer \u003ctoken\u003e` + "`" + `.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -480,17 +494,17 @@ const docTemplate = `{
|
|||||||
"tags": [
|
"tags": [
|
||||||
"organizations"
|
"organizations"
|
||||||
],
|
],
|
||||||
"summary": "Update organization",
|
"summary": "Обновление организации",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Organization ID",
|
"description": "UUID организации",
|
||||||
"name": "id",
|
"name": "id",
|
||||||
"in": "path",
|
"in": "path",
|
||||||
"required": true
|
"required": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"description": "New organization details",
|
"description": "Новое название организации",
|
||||||
"name": "request",
|
"name": "request",
|
||||||
"in": "body",
|
"in": "body",
|
||||||
"required": true,
|
"required": true,
|
||||||
@@ -501,19 +515,19 @@ const docTemplate = `{
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "Обновлённая организация",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/org.OrgResponse"
|
"$ref": "#/definitions/org.OrgResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Ошибка валидации полей",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/org.ErrorResponse"
|
"$ref": "#/definitions/org.ErrorResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"404": {
|
"404": {
|
||||||
"description": "Not Found",
|
"description": "Организация не найдена",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/org.ErrorResponse"
|
"$ref": "#/definitions/org.ErrorResponse"
|
||||||
}
|
}
|
||||||
@@ -526,7 +540,7 @@ const docTemplate = `{
|
|||||||
"Bearer": []
|
"Bearer": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Delete an organization",
|
"description": "Безвозвратное удаление организации по её ID.\n**Требуется:** заголовок ` + "`" + `Authorization: Bearer \u003ctoken\u003e` + "`" + `.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -536,11 +550,11 @@ const docTemplate = `{
|
|||||||
"tags": [
|
"tags": [
|
||||||
"organizations"
|
"organizations"
|
||||||
],
|
],
|
||||||
"summary": "Delete organization",
|
"summary": "Удаление организации",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Organization ID",
|
"description": "UUID организации",
|
||||||
"name": "id",
|
"name": "id",
|
||||||
"in": "path",
|
"in": "path",
|
||||||
"required": true
|
"required": true
|
||||||
@@ -548,7 +562,7 @@ const docTemplate = `{
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "{\"message\": \"organization deleted\"}",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": {
|
"additionalProperties": {
|
||||||
@@ -557,7 +571,7 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"404": {
|
"404": {
|
||||||
"description": "Not Found",
|
"description": "Организация не найдена",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/org.ErrorResponse"
|
"$ref": "#/definitions/org.ErrorResponse"
|
||||||
}
|
}
|
||||||
@@ -747,6 +761,12 @@ const docTemplate = `{
|
|||||||
"org.OrgListResponse": {
|
"org.OrgListResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"limit": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"offset": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
"organizations": {
|
"organizations": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
@@ -803,7 +823,7 @@ const docTemplate = `{
|
|||||||
},
|
},
|
||||||
"securityDefinitions": {
|
"securityDefinitions": {
|
||||||
"Bearer": {
|
"Bearer": {
|
||||||
"description": "Type \"Bearer\" followed by a space and the JWT token.",
|
"description": "Введите ` + "`" + `Bearer \u003ctoken\u003e` + "`" + `, где token — access_token из ответа /auth/login или /auth/register",
|
||||||
"type": "apiKey",
|
"type": "apiKey",
|
||||||
"name": "Authorization",
|
"name": "Authorization",
|
||||||
"in": "header"
|
"in": "header"
|
||||||
@@ -815,10 +835,10 @@ const docTemplate = `{
|
|||||||
var SwaggerInfo = &swag.Spec{
|
var SwaggerInfo = &swag.Spec{
|
||||||
Version: "1.0",
|
Version: "1.0",
|
||||||
Host: "",
|
Host: "",
|
||||||
BasePath: "",
|
BasePath: "/api/v1",
|
||||||
Schemes: []string{"http"},
|
Schemes: []string{"http"},
|
||||||
Title: "AegisGuard API",
|
Title: "AegisGuard API",
|
||||||
Description: "API for AegisGuard control plane",
|
Description: "API системы управления AegisGuard. Позволяет управлять пользователями и организациями.\nВсе защищённые эндпоинты требуют заголовок `Authorization: Bearer <token>`.\nТокен получается при регистрации или входе.",
|
||||||
InfoInstanceName: "swagger",
|
InfoInstanceName: "swagger",
|
||||||
SwaggerTemplate: docTemplate,
|
SwaggerTemplate: docTemplate,
|
||||||
LeftDelim: "{{",
|
LeftDelim: "{{",
|
||||||
|
|||||||
+98
-77
@@ -4,15 +4,16 @@
|
|||||||
],
|
],
|
||||||
"swagger": "2.0",
|
"swagger": "2.0",
|
||||||
"info": {
|
"info": {
|
||||||
"description": "API for AegisGuard control plane",
|
"description": "API системы управления AegisGuard. Позволяет управлять пользователями и организациями.\nВсе защищённые эндпоинты требуют заголовок `Authorization: Bearer \u003ctoken\u003e`.\nТокен получается при регистрации или входе.",
|
||||||
"title": "AegisGuard API",
|
"title": "AegisGuard API",
|
||||||
"contact": {},
|
"contact": {},
|
||||||
"version": "1.0"
|
"version": "1.0"
|
||||||
},
|
},
|
||||||
|
"basePath": "/api/v1",
|
||||||
"paths": {
|
"paths": {
|
||||||
"/api/auth/login": {
|
"/api/v1/auth/login": {
|
||||||
"post": {
|
"post": {
|
||||||
"description": "Authenticate user with email and password, returns JWT token",
|
"description": "Аутентификация по email и паролю. Возвращает access_token (JWT) и refresh_token.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -22,10 +23,10 @@
|
|||||||
"tags": [
|
"tags": [
|
||||||
"auth"
|
"auth"
|
||||||
],
|
],
|
||||||
"summary": "Login",
|
"summary": "Вход",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"description": "Login credentials",
|
"description": "Email и пароль",
|
||||||
"name": "request",
|
"name": "request",
|
||||||
"in": "body",
|
"in": "body",
|
||||||
"required": true,
|
"required": true,
|
||||||
@@ -36,19 +37,19 @@
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "Успешный вход, токены в ответе",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.AuthResponse"
|
"$ref": "#/definitions/auth.AuthResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Ошибка валидации полей",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
"description": "Unauthorized",
|
"description": "Неверный email или пароль",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
@@ -56,9 +57,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/api/auth/logout": {
|
"/api/v1/auth/logout": {
|
||||||
"post": {
|
"post": {
|
||||||
"description": "Invalidate a refresh token (logout)",
|
"description": "Аннулирование refresh_token. После выхода повторное использование того же refresh_token вернёт 401.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -68,10 +69,10 @@
|
|||||||
"tags": [
|
"tags": [
|
||||||
"auth"
|
"auth"
|
||||||
],
|
],
|
||||||
"summary": "Logout",
|
"summary": "Выход",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"description": "Refresh token to invalidate",
|
"description": "Refresh_token для аннулирования",
|
||||||
"name": "request",
|
"name": "request",
|
||||||
"in": "body",
|
"in": "body",
|
||||||
"required": true,
|
"required": true,
|
||||||
@@ -82,7 +83,7 @@
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "{\"message\": \"logged out successfully\"}",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": {
|
"additionalProperties": {
|
||||||
@@ -91,13 +92,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Не указан refresh_token",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
"description": "Unauthorized",
|
"description": "Refresh_token не найден или уже аннулирован",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
@@ -105,14 +106,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/api/auth/me": {
|
"/api/v1/auth/me": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
{
|
{
|
||||||
"Bearer": []
|
"Bearer": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Get authenticated user's profile",
|
"description": "Получение профиля текущего авторизованного пользователя.\n**Требуется:** заголовок `Authorization: Bearer \u003ctoken\u003e`.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -122,16 +123,16 @@
|
|||||||
"tags": [
|
"tags": [
|
||||||
"auth"
|
"auth"
|
||||||
],
|
],
|
||||||
"summary": "Get current user",
|
"summary": "Профиль пользователя",
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "Данные пользователя",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.UserResponse"
|
"$ref": "#/definitions/auth.UserResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
"description": "Unauthorized",
|
"description": "Токен не указан или недействителен",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
@@ -144,7 +145,7 @@
|
|||||||
"Bearer": []
|
"Bearer": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Update current user's username",
|
"description": "Обновление username текущего пользователя.\n**Требуется:** заголовок `Authorization: Bearer \u003ctoken\u003e`.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -154,10 +155,10 @@
|
|||||||
"tags": [
|
"tags": [
|
||||||
"auth"
|
"auth"
|
||||||
],
|
],
|
||||||
"summary": "Update profile",
|
"summary": "Обновление профиля",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"description": "Profile update",
|
"description": "Новый username",
|
||||||
"name": "request",
|
"name": "request",
|
||||||
"in": "body",
|
"in": "body",
|
||||||
"required": true,
|
"required": true,
|
||||||
@@ -168,19 +169,19 @@
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "Обновлённый профиль",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.UserResponse"
|
"$ref": "#/definitions/auth.UserResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Ошибка валидации: username от 3 до 30 символов",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
"description": "Unauthorized",
|
"description": "Токен не указан или недействителен",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
@@ -188,14 +189,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/api/auth/password": {
|
"/api/v1/auth/password": {
|
||||||
"put": {
|
"put": {
|
||||||
"security": [
|
"security": [
|
||||||
{
|
{
|
||||||
"Bearer": []
|
"Bearer": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Change current user's password",
|
"description": "Изменение пароля текущего пользователя. Требуется указать старый и новый пароль.\n**Требуется:** заголовок `Authorization: Bearer \u003ctoken\u003e`.\nПароль должен содержать минимум 8 символов, заглавную букву, строчную букву и цифру.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -205,10 +206,10 @@
|
|||||||
"tags": [
|
"tags": [
|
||||||
"auth"
|
"auth"
|
||||||
],
|
],
|
||||||
"summary": "Change password",
|
"summary": "Смена пароля",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"description": "Password change details",
|
"description": "Старый и новый пароль",
|
||||||
"name": "request",
|
"name": "request",
|
||||||
"in": "body",
|
"in": "body",
|
||||||
"required": true,
|
"required": true,
|
||||||
@@ -219,7 +220,7 @@
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "{\"message\": \"password changed successfully\"}",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": {
|
"additionalProperties": {
|
||||||
@@ -228,13 +229,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Ошибка валидации: неверный старый пароль, слабый новый или совпадают",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
"description": "Unauthorized",
|
"description": "Токен не указан или недействителен",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
@@ -242,9 +243,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/api/auth/refresh": {
|
"/api/v1/auth/refresh": {
|
||||||
"post": {
|
"post": {
|
||||||
"description": "Get a new access token using a refresh token",
|
"description": "Получение новой пары токенов по refresh_token. Старый refresh_token становится недействительным (ротация).\nЕсли refresh_token истёк или уже был использован — придёт 401.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -254,10 +255,10 @@
|
|||||||
"tags": [
|
"tags": [
|
||||||
"auth"
|
"auth"
|
||||||
],
|
],
|
||||||
"summary": "Refresh token",
|
"summary": "Обновление токенов",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"description": "Refresh token",
|
"description": "Действительный refresh_token",
|
||||||
"name": "request",
|
"name": "request",
|
||||||
"in": "body",
|
"in": "body",
|
||||||
"required": true,
|
"required": true,
|
||||||
@@ -268,19 +269,19 @@
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "Новая пара токенов",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.AuthResponse"
|
"$ref": "#/definitions/auth.AuthResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Не указан refresh_token",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"401": {
|
"401": {
|
||||||
"description": "Unauthorized",
|
"description": "Refresh_token недействителен или истёк",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
@@ -288,9 +289,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/api/auth/register": {
|
"/api/v1/auth/register": {
|
||||||
"post": {
|
"post": {
|
||||||
"description": "Create user account with username, email, password",
|
"description": "Создание новой учётной записи. После успешной регистрации сразу возвращается access_token и refresh_token.\nПароль должен содержать минимум 8 символов, заглавную букву, строчную букву и цифру.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -300,10 +301,10 @@
|
|||||||
"tags": [
|
"tags": [
|
||||||
"auth"
|
"auth"
|
||||||
],
|
],
|
||||||
"summary": "Register",
|
"summary": "Регистрация",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"description": "Registration details",
|
"description": "Данные для регистрации",
|
||||||
"name": "request",
|
"name": "request",
|
||||||
"in": "body",
|
"in": "body",
|
||||||
"required": true,
|
"required": true,
|
||||||
@@ -314,19 +315,19 @@
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"201": {
|
"201": {
|
||||||
"description": "Created",
|
"description": "Пользователь создан, токены в ответе",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.AuthResponse"
|
"$ref": "#/definitions/auth.AuthResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Ошибка валидации полей (некорректный email, слабый пароль)",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"409": {
|
"409": {
|
||||||
"description": "Conflict",
|
"description": "Email уже зарегистрирован",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/auth.ErrorResponse"
|
"$ref": "#/definitions/auth.ErrorResponse"
|
||||||
}
|
}
|
||||||
@@ -334,14 +335,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/api/organizations": {
|
"/api/v1/organizations": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
{
|
{
|
||||||
"Bearer": []
|
"Bearer": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Get all organizations",
|
"description": "Получение списка всех организаций с пагинацией.\n**Требуется:** заголовок `Authorization: Bearer \u003ctoken\u003e`.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -351,16 +352,30 @@
|
|||||||
"tags": [
|
"tags": [
|
||||||
"organizations"
|
"organizations"
|
||||||
],
|
],
|
||||||
"summary": "List organizations",
|
"summary": "Список организаций",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Количество записей на странице (по умолчанию 20)",
|
||||||
|
"name": "limit",
|
||||||
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "integer",
|
||||||
|
"description": "Смещение от начала списка (по умолчанию 0)",
|
||||||
|
"name": "offset",
|
||||||
|
"in": "query"
|
||||||
|
}
|
||||||
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "Список организаций",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/org.OrgListResponse"
|
"$ref": "#/definitions/org.OrgListResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"500": {
|
"500": {
|
||||||
"description": "Internal Server Error",
|
"description": "Внутренняя ошибка сервера",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/org.ErrorResponse"
|
"$ref": "#/definitions/org.ErrorResponse"
|
||||||
}
|
}
|
||||||
@@ -373,7 +388,7 @@
|
|||||||
"Bearer": []
|
"Bearer": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Create a new organization",
|
"description": "Создание новой организации. slug используется в URL и должен быть уникальным.\n**Требуется:** заголовок `Authorization: Bearer \u003ctoken\u003e`.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -383,10 +398,10 @@
|
|||||||
"tags": [
|
"tags": [
|
||||||
"organizations"
|
"organizations"
|
||||||
],
|
],
|
||||||
"summary": "Create organization",
|
"summary": "Создание организации",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"description": "Organization details",
|
"description": "Название и slug организации",
|
||||||
"name": "request",
|
"name": "request",
|
||||||
"in": "body",
|
"in": "body",
|
||||||
"required": true,
|
"required": true,
|
||||||
@@ -397,19 +412,19 @@
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"201": {
|
"201": {
|
||||||
"description": "Created",
|
"description": "Организация создана",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/org.OrgResponse"
|
"$ref": "#/definitions/org.OrgResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Ошибка валидации полей",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/org.ErrorResponse"
|
"$ref": "#/definitions/org.ErrorResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"409": {
|
"409": {
|
||||||
"description": "Conflict",
|
"description": "Slug уже занят",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/org.ErrorResponse"
|
"$ref": "#/definitions/org.ErrorResponse"
|
||||||
}
|
}
|
||||||
@@ -417,14 +432,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/api/organizations/{id}": {
|
"/api/v1/organizations/{id}": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
{
|
{
|
||||||
"Bearer": []
|
"Bearer": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Get organization details",
|
"description": "Получение информации об организации по её ID.\n**Требуется:** заголовок `Authorization: Bearer \u003ctoken\u003e`.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -434,11 +449,11 @@
|
|||||||
"tags": [
|
"tags": [
|
||||||
"organizations"
|
"organizations"
|
||||||
],
|
],
|
||||||
"summary": "Get organization by ID",
|
"summary": "Получить организацию",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Organization ID",
|
"description": "UUID организации",
|
||||||
"name": "id",
|
"name": "id",
|
||||||
"in": "path",
|
"in": "path",
|
||||||
"required": true
|
"required": true
|
||||||
@@ -446,13 +461,13 @@
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "Данные организации",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/org.OrgResponse"
|
"$ref": "#/definitions/org.OrgResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"404": {
|
"404": {
|
||||||
"description": "Not Found",
|
"description": "Организация не найдена",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/org.ErrorResponse"
|
"$ref": "#/definitions/org.ErrorResponse"
|
||||||
}
|
}
|
||||||
@@ -465,7 +480,7 @@
|
|||||||
"Bearer": []
|
"Bearer": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Update organization name",
|
"description": "Обновление названия организации. slug изменить нельзя.\n**Требуется:** заголовок `Authorization: Bearer \u003ctoken\u003e`.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -475,17 +490,17 @@
|
|||||||
"tags": [
|
"tags": [
|
||||||
"organizations"
|
"organizations"
|
||||||
],
|
],
|
||||||
"summary": "Update organization",
|
"summary": "Обновление организации",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Organization ID",
|
"description": "UUID организации",
|
||||||
"name": "id",
|
"name": "id",
|
||||||
"in": "path",
|
"in": "path",
|
||||||
"required": true
|
"required": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"description": "New organization details",
|
"description": "Новое название организации",
|
||||||
"name": "request",
|
"name": "request",
|
||||||
"in": "body",
|
"in": "body",
|
||||||
"required": true,
|
"required": true,
|
||||||
@@ -496,19 +511,19 @@
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "Обновлённая организация",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/org.OrgResponse"
|
"$ref": "#/definitions/org.OrgResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"400": {
|
"400": {
|
||||||
"description": "Bad Request",
|
"description": "Ошибка валидации полей",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/org.ErrorResponse"
|
"$ref": "#/definitions/org.ErrorResponse"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"404": {
|
"404": {
|
||||||
"description": "Not Found",
|
"description": "Организация не найдена",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/org.ErrorResponse"
|
"$ref": "#/definitions/org.ErrorResponse"
|
||||||
}
|
}
|
||||||
@@ -521,7 +536,7 @@
|
|||||||
"Bearer": []
|
"Bearer": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Delete an organization",
|
"description": "Безвозвратное удаление организации по её ID.\n**Требуется:** заголовок `Authorization: Bearer \u003ctoken\u003e`.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
],
|
],
|
||||||
@@ -531,11 +546,11 @@
|
|||||||
"tags": [
|
"tags": [
|
||||||
"organizations"
|
"organizations"
|
||||||
],
|
],
|
||||||
"summary": "Delete organization",
|
"summary": "Удаление организации",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Organization ID",
|
"description": "UUID организации",
|
||||||
"name": "id",
|
"name": "id",
|
||||||
"in": "path",
|
"in": "path",
|
||||||
"required": true
|
"required": true
|
||||||
@@ -543,7 +558,7 @@
|
|||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
"description": "OK",
|
"description": "{\"message\": \"organization deleted\"}",
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": {
|
"additionalProperties": {
|
||||||
@@ -552,7 +567,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"404": {
|
"404": {
|
||||||
"description": "Not Found",
|
"description": "Организация не найдена",
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/org.ErrorResponse"
|
"$ref": "#/definitions/org.ErrorResponse"
|
||||||
}
|
}
|
||||||
@@ -742,6 +757,12 @@
|
|||||||
"org.OrgListResponse": {
|
"org.OrgListResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"limit": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"offset": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
"organizations": {
|
"organizations": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
@@ -798,7 +819,7 @@
|
|||||||
},
|
},
|
||||||
"securityDefinitions": {
|
"securityDefinitions": {
|
||||||
"Bearer": {
|
"Bearer": {
|
||||||
"description": "Type \"Bearer\" followed by a space and the JWT token.",
|
"description": "Введите `Bearer \u003ctoken\u003e`, где token — access_token из ответа /auth/login или /auth/register",
|
||||||
"type": "apiKey",
|
"type": "apiKey",
|
||||||
"name": "Authorization",
|
"name": "Authorization",
|
||||||
"in": "header"
|
"in": "header"
|
||||||
|
|||||||
+119
-77
@@ -1,3 +1,4 @@
|
|||||||
|
basePath: /api/v1
|
||||||
definitions:
|
definitions:
|
||||||
auth.AuthResponse:
|
auth.AuthResponse:
|
||||||
properties:
|
properties:
|
||||||
@@ -125,6 +126,10 @@ definitions:
|
|||||||
type: object
|
type: object
|
||||||
org.OrgListResponse:
|
org.OrgListResponse:
|
||||||
properties:
|
properties:
|
||||||
|
limit:
|
||||||
|
type: integer
|
||||||
|
offset:
|
||||||
|
type: integer
|
||||||
organizations:
|
organizations:
|
||||||
items:
|
items:
|
||||||
$ref: '#/definitions/org.Organization'
|
$ref: '#/definitions/org.Organization'
|
||||||
@@ -162,17 +167,21 @@ definitions:
|
|||||||
type: object
|
type: object
|
||||||
info:
|
info:
|
||||||
contact: {}
|
contact: {}
|
||||||
description: API for AegisGuard control plane
|
description: |-
|
||||||
|
API системы управления AegisGuard. Позволяет управлять пользователями и организациями.
|
||||||
|
Все защищённые эндпоинты требуют заголовок `Authorization: Bearer <token>`.
|
||||||
|
Токен получается при регистрации или входе.
|
||||||
title: AegisGuard API
|
title: AegisGuard API
|
||||||
version: "1.0"
|
version: "1.0"
|
||||||
paths:
|
paths:
|
||||||
/api/auth/login:
|
/api/v1/auth/login:
|
||||||
post:
|
post:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
description: Authenticate user with email and password, returns JWT token
|
description: Аутентификация по email и паролю. Возвращает access_token (JWT)
|
||||||
|
и refresh_token.
|
||||||
parameters:
|
parameters:
|
||||||
- description: Login credentials
|
- description: Email и пароль
|
||||||
in: body
|
in: body
|
||||||
name: request
|
name: request
|
||||||
required: true
|
required: true
|
||||||
@@ -182,27 +191,28 @@ paths:
|
|||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: OK
|
description: Успешный вход, токены в ответе
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/auth.AuthResponse'
|
$ref: '#/definitions/auth.AuthResponse'
|
||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: Ошибка валидации полей
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/auth.ErrorResponse'
|
$ref: '#/definitions/auth.ErrorResponse'
|
||||||
"401":
|
"401":
|
||||||
description: Unauthorized
|
description: Неверный email или пароль
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/auth.ErrorResponse'
|
$ref: '#/definitions/auth.ErrorResponse'
|
||||||
summary: Login
|
summary: Вход
|
||||||
tags:
|
tags:
|
||||||
- auth
|
- auth
|
||||||
/api/auth/logout:
|
/api/v1/auth/logout:
|
||||||
post:
|
post:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
description: Invalidate a refresh token (logout)
|
description: Аннулирование refresh_token. После выхода повторное использование
|
||||||
|
того же refresh_token вернёт 401.
|
||||||
parameters:
|
parameters:
|
||||||
- description: Refresh token to invalidate
|
- description: Refresh_token для аннулирования
|
||||||
in: body
|
in: body
|
||||||
name: request
|
name: request
|
||||||
required: true
|
required: true
|
||||||
@@ -212,49 +222,53 @@ paths:
|
|||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: OK
|
description: '{"message": "logged out successfully"}'
|
||||||
schema:
|
schema:
|
||||||
additionalProperties:
|
additionalProperties:
|
||||||
type: string
|
type: string
|
||||||
type: object
|
type: object
|
||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: Не указан refresh_token
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/auth.ErrorResponse'
|
$ref: '#/definitions/auth.ErrorResponse'
|
||||||
"401":
|
"401":
|
||||||
description: Unauthorized
|
description: Refresh_token не найден или уже аннулирован
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/auth.ErrorResponse'
|
$ref: '#/definitions/auth.ErrorResponse'
|
||||||
summary: Logout
|
summary: Выход
|
||||||
tags:
|
tags:
|
||||||
- auth
|
- auth
|
||||||
/api/auth/me:
|
/api/v1/auth/me:
|
||||||
get:
|
get:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
description: Get authenticated user's profile
|
description: |-
|
||||||
|
Получение профиля текущего авторизованного пользователя.
|
||||||
|
**Требуется:** заголовок `Authorization: Bearer <token>`.
|
||||||
produces:
|
produces:
|
||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: OK
|
description: Данные пользователя
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/auth.UserResponse'
|
$ref: '#/definitions/auth.UserResponse'
|
||||||
"401":
|
"401":
|
||||||
description: Unauthorized
|
description: Токен не указан или недействителен
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/auth.ErrorResponse'
|
$ref: '#/definitions/auth.ErrorResponse'
|
||||||
security:
|
security:
|
||||||
- Bearer: []
|
- Bearer: []
|
||||||
summary: Get current user
|
summary: Профиль пользователя
|
||||||
tags:
|
tags:
|
||||||
- auth
|
- auth
|
||||||
put:
|
put:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
description: Update current user's username
|
description: |-
|
||||||
|
Обновление username текущего пользователя.
|
||||||
|
**Требуется:** заголовок `Authorization: Bearer <token>`.
|
||||||
parameters:
|
parameters:
|
||||||
- description: Profile update
|
- description: Новый username
|
||||||
in: body
|
in: body
|
||||||
name: request
|
name: request
|
||||||
required: true
|
required: true
|
||||||
@@ -264,29 +278,32 @@ paths:
|
|||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: OK
|
description: Обновлённый профиль
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/auth.UserResponse'
|
$ref: '#/definitions/auth.UserResponse'
|
||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: 'Ошибка валидации: username от 3 до 30 символов'
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/auth.ErrorResponse'
|
$ref: '#/definitions/auth.ErrorResponse'
|
||||||
"401":
|
"401":
|
||||||
description: Unauthorized
|
description: Токен не указан или недействителен
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/auth.ErrorResponse'
|
$ref: '#/definitions/auth.ErrorResponse'
|
||||||
security:
|
security:
|
||||||
- Bearer: []
|
- Bearer: []
|
||||||
summary: Update profile
|
summary: Обновление профиля
|
||||||
tags:
|
tags:
|
||||||
- auth
|
- auth
|
||||||
/api/auth/password:
|
/api/v1/auth/password:
|
||||||
put:
|
put:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
description: Change current user's password
|
description: |-
|
||||||
|
Изменение пароля текущего пользователя. Требуется указать старый и новый пароль.
|
||||||
|
**Требуется:** заголовок `Authorization: Bearer <token>`.
|
||||||
|
Пароль должен содержать минимум 8 символов, заглавную букву, строчную букву и цифру.
|
||||||
parameters:
|
parameters:
|
||||||
- description: Password change details
|
- description: Старый и новый пароль
|
||||||
in: body
|
in: body
|
||||||
name: request
|
name: request
|
||||||
required: true
|
required: true
|
||||||
@@ -296,31 +313,34 @@ paths:
|
|||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: OK
|
description: '{"message": "password changed successfully"}'
|
||||||
schema:
|
schema:
|
||||||
additionalProperties:
|
additionalProperties:
|
||||||
type: string
|
type: string
|
||||||
type: object
|
type: object
|
||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: 'Ошибка валидации: неверный старый пароль, слабый новый или
|
||||||
|
совпадают'
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/auth.ErrorResponse'
|
$ref: '#/definitions/auth.ErrorResponse'
|
||||||
"401":
|
"401":
|
||||||
description: Unauthorized
|
description: Токен не указан или недействителен
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/auth.ErrorResponse'
|
$ref: '#/definitions/auth.ErrorResponse'
|
||||||
security:
|
security:
|
||||||
- Bearer: []
|
- Bearer: []
|
||||||
summary: Change password
|
summary: Смена пароля
|
||||||
tags:
|
tags:
|
||||||
- auth
|
- auth
|
||||||
/api/auth/refresh:
|
/api/v1/auth/refresh:
|
||||||
post:
|
post:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
description: Get a new access token using a refresh token
|
description: |-
|
||||||
|
Получение новой пары токенов по refresh_token. Старый refresh_token становится недействительным (ротация).
|
||||||
|
Если refresh_token истёк или уже был использован — придёт 401.
|
||||||
parameters:
|
parameters:
|
||||||
- description: Refresh token
|
- description: Действительный refresh_token
|
||||||
in: body
|
in: body
|
||||||
name: request
|
name: request
|
||||||
required: true
|
required: true
|
||||||
@@ -330,27 +350,29 @@ paths:
|
|||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: OK
|
description: Новая пара токенов
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/auth.AuthResponse'
|
$ref: '#/definitions/auth.AuthResponse'
|
||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: Не указан refresh_token
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/auth.ErrorResponse'
|
$ref: '#/definitions/auth.ErrorResponse'
|
||||||
"401":
|
"401":
|
||||||
description: Unauthorized
|
description: Refresh_token недействителен или истёк
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/auth.ErrorResponse'
|
$ref: '#/definitions/auth.ErrorResponse'
|
||||||
summary: Refresh token
|
summary: Обновление токенов
|
||||||
tags:
|
tags:
|
||||||
- auth
|
- auth
|
||||||
/api/auth/register:
|
/api/v1/auth/register:
|
||||||
post:
|
post:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
description: Create user account with username, email, password
|
description: |-
|
||||||
|
Создание новой учётной записи. После успешной регистрации сразу возвращается access_token и refresh_token.
|
||||||
|
Пароль должен содержать минимум 8 символов, заглавную букву, строчную букву и цифру.
|
||||||
parameters:
|
parameters:
|
||||||
- description: Registration details
|
- description: Данные для регистрации
|
||||||
in: body
|
in: body
|
||||||
name: request
|
name: request
|
||||||
required: true
|
required: true
|
||||||
@@ -360,47 +382,60 @@ paths:
|
|||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
"201":
|
"201":
|
||||||
description: Created
|
description: Пользователь создан, токены в ответе
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/auth.AuthResponse'
|
$ref: '#/definitions/auth.AuthResponse'
|
||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: Ошибка валидации полей (некорректный email, слабый пароль)
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/auth.ErrorResponse'
|
$ref: '#/definitions/auth.ErrorResponse'
|
||||||
"409":
|
"409":
|
||||||
description: Conflict
|
description: Email уже зарегистрирован
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/auth.ErrorResponse'
|
$ref: '#/definitions/auth.ErrorResponse'
|
||||||
summary: Register
|
summary: Регистрация
|
||||||
tags:
|
tags:
|
||||||
- auth
|
- auth
|
||||||
/api/organizations:
|
/api/v1/organizations:
|
||||||
get:
|
get:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
description: Get all organizations
|
description: |-
|
||||||
|
Получение списка всех организаций с пагинацией.
|
||||||
|
**Требуется:** заголовок `Authorization: Bearer <token>`.
|
||||||
|
parameters:
|
||||||
|
- description: Количество записей на странице (по умолчанию 20)
|
||||||
|
in: query
|
||||||
|
name: limit
|
||||||
|
type: integer
|
||||||
|
- description: Смещение от начала списка (по умолчанию 0)
|
||||||
|
in: query
|
||||||
|
name: offset
|
||||||
|
type: integer
|
||||||
produces:
|
produces:
|
||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: OK
|
description: Список организаций
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/org.OrgListResponse'
|
$ref: '#/definitions/org.OrgListResponse'
|
||||||
"500":
|
"500":
|
||||||
description: Internal Server Error
|
description: Внутренняя ошибка сервера
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/org.ErrorResponse'
|
$ref: '#/definitions/org.ErrorResponse'
|
||||||
security:
|
security:
|
||||||
- Bearer: []
|
- Bearer: []
|
||||||
summary: List organizations
|
summary: Список организаций
|
||||||
tags:
|
tags:
|
||||||
- organizations
|
- organizations
|
||||||
post:
|
post:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
description: Create a new organization
|
description: |-
|
||||||
|
Создание новой организации. slug используется в URL и должен быть уникальным.
|
||||||
|
**Требуется:** заголовок `Authorization: Bearer <token>`.
|
||||||
parameters:
|
parameters:
|
||||||
- description: Organization details
|
- description: Название и slug организации
|
||||||
in: body
|
in: body
|
||||||
name: request
|
name: request
|
||||||
required: true
|
required: true
|
||||||
@@ -410,29 +445,31 @@ paths:
|
|||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
"201":
|
"201":
|
||||||
description: Created
|
description: Организация создана
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/org.OrgResponse'
|
$ref: '#/definitions/org.OrgResponse'
|
||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: Ошибка валидации полей
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/org.ErrorResponse'
|
$ref: '#/definitions/org.ErrorResponse'
|
||||||
"409":
|
"409":
|
||||||
description: Conflict
|
description: Slug уже занят
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/org.ErrorResponse'
|
$ref: '#/definitions/org.ErrorResponse'
|
||||||
security:
|
security:
|
||||||
- Bearer: []
|
- Bearer: []
|
||||||
summary: Create organization
|
summary: Создание организации
|
||||||
tags:
|
tags:
|
||||||
- organizations
|
- organizations
|
||||||
/api/organizations/{id}:
|
/api/v1/organizations/{id}:
|
||||||
delete:
|
delete:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
description: Delete an organization
|
description: |-
|
||||||
|
Безвозвратное удаление организации по её ID.
|
||||||
|
**Требуется:** заголовок `Authorization: Bearer <token>`.
|
||||||
parameters:
|
parameters:
|
||||||
- description: Organization ID
|
- description: UUID организации
|
||||||
in: path
|
in: path
|
||||||
name: id
|
name: id
|
||||||
required: true
|
required: true
|
||||||
@@ -441,26 +478,28 @@ paths:
|
|||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: OK
|
description: '{"message": "organization deleted"}'
|
||||||
schema:
|
schema:
|
||||||
additionalProperties:
|
additionalProperties:
|
||||||
type: string
|
type: string
|
||||||
type: object
|
type: object
|
||||||
"404":
|
"404":
|
||||||
description: Not Found
|
description: Организация не найдена
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/org.ErrorResponse'
|
$ref: '#/definitions/org.ErrorResponse'
|
||||||
security:
|
security:
|
||||||
- Bearer: []
|
- Bearer: []
|
||||||
summary: Delete organization
|
summary: Удаление организации
|
||||||
tags:
|
tags:
|
||||||
- organizations
|
- organizations
|
||||||
get:
|
get:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
description: Get organization details
|
description: |-
|
||||||
|
Получение информации об организации по её ID.
|
||||||
|
**Требуется:** заголовок `Authorization: Bearer <token>`.
|
||||||
parameters:
|
parameters:
|
||||||
- description: Organization ID
|
- description: UUID организации
|
||||||
in: path
|
in: path
|
||||||
name: id
|
name: id
|
||||||
required: true
|
required: true
|
||||||
@@ -469,29 +508,31 @@ paths:
|
|||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: OK
|
description: Данные организации
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/org.OrgResponse'
|
$ref: '#/definitions/org.OrgResponse'
|
||||||
"404":
|
"404":
|
||||||
description: Not Found
|
description: Организация не найдена
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/org.ErrorResponse'
|
$ref: '#/definitions/org.ErrorResponse'
|
||||||
security:
|
security:
|
||||||
- Bearer: []
|
- Bearer: []
|
||||||
summary: Get organization by ID
|
summary: Получить организацию
|
||||||
tags:
|
tags:
|
||||||
- organizations
|
- organizations
|
||||||
put:
|
put:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
description: Update organization name
|
description: |-
|
||||||
|
Обновление названия организации. slug изменить нельзя.
|
||||||
|
**Требуется:** заголовок `Authorization: Bearer <token>`.
|
||||||
parameters:
|
parameters:
|
||||||
- description: Organization ID
|
- description: UUID организации
|
||||||
in: path
|
in: path
|
||||||
name: id
|
name: id
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
- description: New organization details
|
- description: Новое название организации
|
||||||
in: body
|
in: body
|
||||||
name: request
|
name: request
|
||||||
required: true
|
required: true
|
||||||
@@ -501,27 +542,28 @@ paths:
|
|||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: OK
|
description: Обновлённая организация
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/org.OrgResponse'
|
$ref: '#/definitions/org.OrgResponse'
|
||||||
"400":
|
"400":
|
||||||
description: Bad Request
|
description: Ошибка валидации полей
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/org.ErrorResponse'
|
$ref: '#/definitions/org.ErrorResponse'
|
||||||
"404":
|
"404":
|
||||||
description: Not Found
|
description: Организация не найдена
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/org.ErrorResponse'
|
$ref: '#/definitions/org.ErrorResponse'
|
||||||
security:
|
security:
|
||||||
- Bearer: []
|
- Bearer: []
|
||||||
summary: Update organization
|
summary: Обновление организации
|
||||||
tags:
|
tags:
|
||||||
- organizations
|
- organizations
|
||||||
schemes:
|
schemes:
|
||||||
- http
|
- http
|
||||||
securityDefinitions:
|
securityDefinitions:
|
||||||
Bearer:
|
Bearer:
|
||||||
description: Type "Bearer" followed by a space and the JWT token.
|
description: Введите `Bearer <token>`, где token — access_token из ответа /auth/login
|
||||||
|
или /auth/register
|
||||||
in: header
|
in: header
|
||||||
name: Authorization
|
name: Authorization
|
||||||
type: apiKey
|
type: apiKey
|
||||||
|
|||||||
+53
-47
@@ -17,16 +17,17 @@ func NewHandler(service *Service) *Handler {
|
|||||||
return &Handler{service: service}
|
return &Handler{service: service}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Register
|
// @Summary Регистрация
|
||||||
// @Description Создание учетной записи пользователя с полями username, email, password
|
// @Description Создание новой учётной записи. После успешной регистрации сразу возвращается access_token и refresh_token.
|
||||||
|
// @Description Пароль должен содержать минимум 8 символов, заглавную букву, строчную букву и цифру.
|
||||||
// @Tags auth
|
// @Tags auth
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param request body RegisterRequest true "Registration details"
|
// @Param request body RegisterRequest true "Данные для регистрации"
|
||||||
// @Success 201 {object} AuthResponse
|
// @Success 201 {object} AuthResponse "Пользователь создан, токены в ответе"
|
||||||
// @Failure 400 {object} ErrorResponse
|
// @Failure 400 {object} ErrorResponse "Ошибка валидации полей (некорректный email, слабый пароль)"
|
||||||
// @Failure 409 {object} ErrorResponse
|
// @Failure 409 {object} ErrorResponse "Email уже зарегистрирован"
|
||||||
// @Router /api/auth/register [post]
|
// @Router /api/v1/auth/register [post]
|
||||||
func (h *Handler) Register(c *gin.Context) {
|
func (h *Handler) Register(c *gin.Context) {
|
||||||
var req RegisterRequest
|
var req RegisterRequest
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
@@ -52,16 +53,16 @@ func (h *Handler) Register(c *gin.Context) {
|
|||||||
c.JSON(http.StatusCreated, resp)
|
c.JSON(http.StatusCreated, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Login
|
// @Summary Вход
|
||||||
// @Description Аунтефикация пользователя с помощью email и password, возвращает JWT token
|
// @Description Аутентификация по email и паролю. Возвращает access_token (JWT) и refresh_token.
|
||||||
// @Tags auth
|
// @Tags auth
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param request body LoginRequest true "Login credentials"
|
// @Param request body LoginRequest true "Email и пароль"
|
||||||
// @Success 200 {object} AuthResponse
|
// @Success 200 {object} AuthResponse "Успешный вход, токены в ответе"
|
||||||
// @Failure 400 {object} ErrorResponse
|
// @Failure 400 {object} ErrorResponse "Ошибка валидации полей"
|
||||||
// @Failure 401 {object} ErrorResponse
|
// @Failure 401 {object} ErrorResponse "Неверный email или пароль"
|
||||||
// @Router /api/auth/login [post]
|
// @Router /api/v1/auth/login [post]
|
||||||
func (h *Handler) Login(c *gin.Context) {
|
func (h *Handler) Login(c *gin.Context) {
|
||||||
var req LoginRequest
|
var req LoginRequest
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
@@ -83,16 +84,17 @@ func (h *Handler) Login(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, resp)
|
c.JSON(http.StatusOK, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Refresh token
|
// @Summary Обновление токенов
|
||||||
// @Description Получение ново
|
// @Description Получение новой пары токенов по refresh_token. Старый refresh_token становится недействительным (ротация).
|
||||||
|
// @Description Если refresh_token истёк или уже был использован — придёт 401.
|
||||||
// @Tags auth
|
// @Tags auth
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param request body RefreshRequest true "Refresh token"
|
// @Param request body RefreshRequest true "Действительный refresh_token"
|
||||||
// @Success 200 {object} AuthResponse
|
// @Success 200 {object} AuthResponse "Новая пара токенов"
|
||||||
// @Failure 400 {object} ErrorResponse
|
// @Failure 400 {object} ErrorResponse "Не указан refresh_token"
|
||||||
// @Failure 401 {object} ErrorResponse
|
// @Failure 401 {object} ErrorResponse "Refresh_token недействителен или истёк"
|
||||||
// @Router /api/auth/refresh [post]
|
// @Router /api/v1/auth/refresh [post]
|
||||||
func (h *Handler) Refresh(c *gin.Context) {
|
func (h *Handler) Refresh(c *gin.Context) {
|
||||||
var req RefreshRequest
|
var req RefreshRequest
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
@@ -114,16 +116,16 @@ func (h *Handler) Refresh(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, resp)
|
c.JSON(http.StatusOK, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Logout
|
// @Summary Выход
|
||||||
// @Description Аннулирует refresh token
|
// @Description Аннулирование refresh_token. После выхода повторное использование того же refresh_token вернёт 401.
|
||||||
// @Tags auth
|
// @Tags auth
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param request body LogoutRequest true "Refresh token to invalidate"
|
// @Param request body LogoutRequest true "Refresh_token для аннулирования"
|
||||||
// @Success 200 {object} map[string]string
|
// @Success 200 {object} map[string]string "{"message": "logged out successfully"}"
|
||||||
// @Failure 400 {object} ErrorResponse
|
// @Failure 400 {object} ErrorResponse "Не указан refresh_token"
|
||||||
// @Failure 401 {object} ErrorResponse
|
// @Failure 401 {object} ErrorResponse "Refresh_token не найден или уже аннулирован"
|
||||||
// @Router /api/auth/logout [post]
|
// @Router /api/v1/auth/logout [post]
|
||||||
func (h *Handler) Logout(c *gin.Context) {
|
func (h *Handler) Logout(c *gin.Context) {
|
||||||
var req LogoutRequest
|
var req LogoutRequest
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
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"})
|
c.JSON(http.StatusOK, gin.H{"message": "logged out successfully"})
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Get current user
|
// @Summary Профиль пользователя
|
||||||
// @Description Получить профиль авторизованного пользователя
|
// @Description Получение профиля текущего авторизованного пользователя.
|
||||||
|
// @Description **Требуется:** заголовок `Authorization: Bearer <token>`.
|
||||||
// @Tags auth
|
// @Tags auth
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Success 200 {object} UserResponse
|
// @Success 200 {object} UserResponse "Данные пользователя"
|
||||||
// @Failure 401 {object} ErrorResponse
|
// @Failure 401 {object} ErrorResponse "Токен не указан или недействителен"
|
||||||
// @Router /api/auth/me [get]
|
// @Router /api/v1/auth/me [get]
|
||||||
func (h *Handler) Me(c *gin.Context) {
|
func (h *Handler) Me(c *gin.Context) {
|
||||||
userID := api.GetUserID(c)
|
userID := api.GetUserID(c)
|
||||||
if userID == "" {
|
if userID == "" {
|
||||||
@@ -174,17 +177,19 @@ func (h *Handler) Me(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, UserResponse{User: *user})
|
c.JSON(http.StatusOK, UserResponse{User: *user})
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Change password
|
// @Summary Смена пароля
|
||||||
// @Description Изменить текущий password пользователя
|
// @Description Изменение пароля текущего пользователя. Требуется указать старый и новый пароль.
|
||||||
|
// @Description **Требуется:** заголовок `Authorization: Bearer <token>`.
|
||||||
|
// @Description Пароль должен содержать минимум 8 символов, заглавную букву, строчную букву и цифру.
|
||||||
// @Tags auth
|
// @Tags auth
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Param request body PasswordChangeRequest true "Password change details"
|
// @Param request body PasswordChangeRequest true "Старый и новый пароль"
|
||||||
// @Success 200 {object} map[string]string
|
// @Success 200 {object} map[string]string "{"message": "password changed successfully"}"
|
||||||
// @Failure 400 {object} ErrorResponse
|
// @Failure 400 {object} ErrorResponse "Ошибка валидации: неверный старый пароль, слабый новый или совпадают"
|
||||||
// @Failure 401 {object} ErrorResponse
|
// @Failure 401 {object} ErrorResponse "Токен не указан или недействителен"
|
||||||
// @Router /api/auth/password [put]
|
// @Router /api/v1/auth/password [put]
|
||||||
func (h *Handler) ChangePassword(c *gin.Context) {
|
func (h *Handler) ChangePassword(c *gin.Context) {
|
||||||
userID := api.GetUserID(c)
|
userID := api.GetUserID(c)
|
||||||
if userID == "" {
|
if userID == "" {
|
||||||
@@ -216,17 +221,18 @@ func (h *Handler) ChangePassword(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, gin.H{"message": "password changed successfully"})
|
c.JSON(http.StatusOK, gin.H{"message": "password changed successfully"})
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Update profile
|
// @Summary Обновление профиля
|
||||||
// @Description Обновить username текущего пользователя
|
// @Description Обновление username текущего пользователя.
|
||||||
|
// @Description **Требуется:** заголовок `Authorization: Bearer <token>`.
|
||||||
// @Tags auth
|
// @Tags auth
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Param request body UpdateProfileRequest true "Profile update"
|
// @Param request body UpdateProfileRequest true "Новый username"
|
||||||
// @Success 200 {object} UserResponse
|
// @Success 200 {object} UserResponse "Обновлённый профиль"
|
||||||
// @Failure 400 {object} ErrorResponse
|
// @Failure 400 {object} ErrorResponse "Ошибка валидации: username от 3 до 30 символов"
|
||||||
// @Failure 401 {object} ErrorResponse
|
// @Failure 401 {object} ErrorResponse "Токен не указан или недействителен"
|
||||||
// @Router /api/auth/me [put]
|
// @Router /api/v1/auth/me [put]
|
||||||
func (h *Handler) UpdateProfile(c *gin.Context) {
|
func (h *Handler) UpdateProfile(c *gin.Context) {
|
||||||
userID := api.GetUserID(c)
|
userID := api.GetUserID(c)
|
||||||
if userID == "" {
|
if userID == "" {
|
||||||
|
|||||||
@@ -1,87 +0,0 @@
|
|||||||
package middleware
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
)
|
|
||||||
|
|
||||||
type visitor struct {
|
|
||||||
count int
|
|
||||||
lastSeen time.Time
|
|
||||||
}
|
|
||||||
|
|
||||||
type RateLimiter struct {
|
|
||||||
mu sync.Mutex
|
|
||||||
visitors map[string]*visitor
|
|
||||||
rate int
|
|
||||||
window time.Duration
|
|
||||||
done chan struct{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewRateLimiter(rate int, window time.Duration) *RateLimiter {
|
|
||||||
rl := &RateLimiter{
|
|
||||||
visitors: make(map[string]*visitor),
|
|
||||||
rate: rate,
|
|
||||||
window: window,
|
|
||||||
done: make(chan struct{}),
|
|
||||||
}
|
|
||||||
go rl.cleanup()
|
|
||||||
return rl
|
|
||||||
}
|
|
||||||
|
|
||||||
func (rl *RateLimiter) Stop() {
|
|
||||||
close(rl.done)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (rl *RateLimiter) cleanup() {
|
|
||||||
ticker := time.NewTicker(10 * time.Minute)
|
|
||||||
defer ticker.Stop()
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-rl.done:
|
|
||||||
return
|
|
||||||
case <-ticker.C:
|
|
||||||
rl.mu.Lock()
|
|
||||||
now := time.Now()
|
|
||||||
for ip, v := range rl.visitors {
|
|
||||||
if now.Sub(v.lastSeen) > rl.window*2 {
|
|
||||||
delete(rl.visitors, ip)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rl.mu.Unlock()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (rl *RateLimiter) Middleware() gin.HandlerFunc {
|
|
||||||
return func(c *gin.Context) {
|
|
||||||
ip := c.ClientIP()
|
|
||||||
|
|
||||||
rl.mu.Lock()
|
|
||||||
v, exists := rl.visitors[ip]
|
|
||||||
now := time.Now()
|
|
||||||
|
|
||||||
if !exists || now.Sub(v.lastSeen) > rl.window {
|
|
||||||
rl.visitors[ip] = &visitor{count: 1, lastSeen: now}
|
|
||||||
rl.mu.Unlock()
|
|
||||||
c.Next()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
v.count++
|
|
||||||
v.lastSeen = now
|
|
||||||
|
|
||||||
if v.count > rl.rate {
|
|
||||||
rl.mu.Unlock()
|
|
||||||
c.JSON(http.StatusTooManyRequests, gin.H{"error": "too many requests, try again later"})
|
|
||||||
c.Abort()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
rl.mu.Unlock()
|
|
||||||
c.Next()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+39
-34
@@ -17,17 +17,18 @@ func NewHandler(service *Service) *Handler {
|
|||||||
return &Handler{service: service}
|
return &Handler{service: service}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Create organization
|
// @Summary Создание организации
|
||||||
// @Description Create a new organization
|
// @Description Создание новой организации. slug используется в URL и должен быть уникальным.
|
||||||
|
// @Description **Требуется:** заголовок `Authorization: Bearer <token>`.
|
||||||
// @Tags organizations
|
// @Tags organizations
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Param request body CreateOrgRequest true "Organization details"
|
// @Param request body CreateOrgRequest true "Название и slug организации"
|
||||||
// @Success 201 {object} OrgResponse
|
// @Success 201 {object} OrgResponse "Организация создана"
|
||||||
// @Failure 400 {object} ErrorResponse
|
// @Failure 400 {object} ErrorResponse "Ошибка валидации полей"
|
||||||
// @Failure 409 {object} ErrorResponse
|
// @Failure 409 {object} ErrorResponse "Slug уже занят"
|
||||||
// @Router /api/organizations [post]
|
// @Router /api/v1/organizations [post]
|
||||||
func (h *Handler) Create(c *gin.Context) {
|
func (h *Handler) Create(c *gin.Context) {
|
||||||
var req CreateOrgRequest
|
var req CreateOrgRequest
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
@@ -49,16 +50,17 @@ func (h *Handler) Create(c *gin.Context) {
|
|||||||
c.JSON(http.StatusCreated, OrgResponse{Organization: *org})
|
c.JSON(http.StatusCreated, OrgResponse{Organization: *org})
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Get organization by ID
|
// @Summary Получить организацию
|
||||||
// @Description Get organization details
|
// @Description Получение информации об организации по её ID.
|
||||||
|
// @Description **Требуется:** заголовок `Authorization: Bearer <token>`.
|
||||||
// @Tags organizations
|
// @Tags organizations
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Param id path string true "Organization ID"
|
// @Param id path string true "UUID организации"
|
||||||
// @Success 200 {object} OrgResponse
|
// @Success 200 {object} OrgResponse "Данные организации"
|
||||||
// @Failure 404 {object} ErrorResponse
|
// @Failure 404 {object} ErrorResponse "Организация не найдена"
|
||||||
// @Router /api/organizations/{id} [get]
|
// @Router /api/v1/organizations/{id} [get]
|
||||||
func (h *Handler) GetByID(c *gin.Context) {
|
func (h *Handler) GetByID(c *gin.Context) {
|
||||||
id := c.Param("id")
|
id := c.Param("id")
|
||||||
|
|
||||||
@@ -76,17 +78,18 @@ func (h *Handler) GetByID(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, OrgResponse{Organization: *org})
|
c.JSON(http.StatusOK, OrgResponse{Organization: *org})
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary List organizations
|
// @Summary Список организаций
|
||||||
// @Description Get all organizations with pagination
|
// @Description Получение списка всех организаций с пагинацией.
|
||||||
|
// @Description **Требуется:** заголовок `Authorization: Bearer <token>`.
|
||||||
// @Tags organizations
|
// @Tags organizations
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Param limit query int false "Page size (default 20)"
|
// @Param limit query int false "Количество записей на странице (по умолчанию 20)"
|
||||||
// @Param offset query int false "Offset (default 0)"
|
// @Param offset query int false "Смещение от начала списка (по умолчанию 0)"
|
||||||
// @Success 200 {object} OrgListResponse
|
// @Success 200 {object} OrgListResponse "Список организаций"
|
||||||
// @Failure 500 {object} ErrorResponse
|
// @Failure 500 {object} ErrorResponse "Внутренняя ошибка сервера"
|
||||||
// @Router /api/organizations [get]
|
// @Router /api/v1/organizations [get]
|
||||||
func (h *Handler) List(c *gin.Context) {
|
func (h *Handler) List(c *gin.Context) {
|
||||||
limit, _ := strconv.Atoi(c.DefaultQuery("limit", "20"))
|
limit, _ := strconv.Atoi(c.DefaultQuery("limit", "20"))
|
||||||
offset, _ := strconv.Atoi(c.DefaultQuery("offset", "0"))
|
offset, _ := strconv.Atoi(c.DefaultQuery("offset", "0"))
|
||||||
@@ -101,18 +104,19 @@ func (h *Handler) List(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, resp)
|
c.JSON(http.StatusOK, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Update organization
|
// @Summary Обновление организации
|
||||||
// @Description Update organization name
|
// @Description Обновление названия организации. slug изменить нельзя.
|
||||||
|
// @Description **Требуется:** заголовок `Authorization: Bearer <token>`.
|
||||||
// @Tags organizations
|
// @Tags organizations
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Param id path string true "Organization ID"
|
// @Param id path string true "UUID организации"
|
||||||
// @Param request body UpdateOrgRequest true "New organization details"
|
// @Param request body UpdateOrgRequest true "Новое название организации"
|
||||||
// @Success 200 {object} OrgResponse
|
// @Success 200 {object} OrgResponse "Обновлённая организация"
|
||||||
// @Failure 400 {object} ErrorResponse
|
// @Failure 400 {object} ErrorResponse "Ошибка валидации полей"
|
||||||
// @Failure 404 {object} ErrorResponse
|
// @Failure 404 {object} ErrorResponse "Организация не найдена"
|
||||||
// @Router /api/organizations/{id} [put]
|
// @Router /api/v1/organizations/{id} [put]
|
||||||
func (h *Handler) Update(c *gin.Context) {
|
func (h *Handler) Update(c *gin.Context) {
|
||||||
id := c.Param("id")
|
id := c.Param("id")
|
||||||
|
|
||||||
@@ -136,16 +140,17 @@ func (h *Handler) Update(c *gin.Context) {
|
|||||||
c.JSON(http.StatusOK, OrgResponse{Organization: *org})
|
c.JSON(http.StatusOK, OrgResponse{Organization: *org})
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Delete organization
|
// @Summary Удаление организации
|
||||||
// @Description Delete an organization
|
// @Description Безвозвратное удаление организации по её ID.
|
||||||
|
// @Description **Требуется:** заголовок `Authorization: Bearer <token>`.
|
||||||
// @Tags organizations
|
// @Tags organizations
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
// @Param id path string true "Organization ID"
|
// @Param id path string true "UUID организации"
|
||||||
// @Success 200 {object} map[string]string
|
// @Success 200 {object} map[string]string "{"message": "organization deleted"}"
|
||||||
// @Failure 404 {object} ErrorResponse
|
// @Failure 404 {object} ErrorResponse "Организация не найдена"
|
||||||
// @Router /api/organizations/{id} [delete]
|
// @Router /api/v1/organizations/{id} [delete]
|
||||||
func (h *Handler) Delete(c *gin.Context) {
|
func (h *Handler) Delete(c *gin.Context) {
|
||||||
id := c.Param("id")
|
id := c.Param("id")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user