api

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractToken

func ExtractToken(c *gin.Context) string

ExtractToken delegates to the canonical middleware.ExtractToken.

func HandleCreateUserAPI

func HandleCreateUserAPI(c *gin.Context)

HandleCreateUserAPI handles POST /api/v1/users.

@Summary		Create user
@Description	Create a new agent user
@Tags			Users
@Accept			json
@Produce		json
@Param			user	body		object	true	"User data (login, email, first_name, last_name, password)"
@Success		201		{object}	map[string]interface{}	"Created user"
@Failure		400		{object}	map[string]interface{}	"Invalid request"
@Failure		401		{object}	map[string]interface{}	"Unauthorized"
@Security		BearerAuth
@Router			/users [post]

func HandleDeleteUserAPI

func HandleDeleteUserAPI(c *gin.Context)

HandleDeleteUserAPI handles DELETE /api/v1/users/:id. This performs a soft delete by setting valid_id = 2 (OTRS pattern).

@Summary		Delete user
@Description	Soft delete a user (deactivate)
@Tags			Users
@Accept			json
@Produce		json
@Param			id	path		int	true	"User ID"
@Success		200	{object}	map[string]interface{}	"User deleted"
@Failure		401	{object}	map[string]interface{}	"Unauthorized"
@Failure		404	{object}	map[string]interface{}	"User not found"
@Security		BearerAuth
@Router			/users/{id} [delete]

func HandleGetUserAPI

func HandleGetUserAPI(c *gin.Context)

HandleGetUserAPI handles GET /api/v1/users/:id.

@Summary		Get user by ID
@Description	Retrieve a single user by their ID
@Tags			Users
@Accept			json
@Produce		json
@Param			id	path		int	true	"User ID"
@Success		200	{object}	map[string]interface{}	"User details"
@Failure		401	{object}	map[string]interface{}	"Unauthorized"
@Failure		404	{object}	map[string]interface{}	"User not found"
@Security		BearerAuth
@Router			/users/{id} [get]

func HandleListUsersAPI

func HandleListUsersAPI(c *gin.Context)

HandleListUsersAPI handles GET /api/v1/users.

@Summary		List users
@Description	Retrieve a paginated list of users (agents)
@Tags			Users
@Accept			json
@Produce		json
@Param			page		query		int		false	"Page number"		default(1)
@Param			per_page	query		int		false	"Items per page"	default(20)
@Param			search		query		string	false	"Search in login, name, email"
@Param			group_id	query		int		false	"Filter by group membership"
@Success		200			{object}	map[string]interface{}	"List of users"
@Failure		401			{object}	map[string]interface{}	"Unauthorized"
@Security		BearerAuth
@Router			/users [get]

func HandleLoginAPI

func HandleLoginAPI(c *gin.Context)

HandleLoginAPI authenticates a user and returns JWT tokens.

@Summary		Login
@Description	Authenticate user with login/password and return JWT tokens
@Tags			Authentication
@Accept			json
@Produce		json
@Param			credentials	body		object	true	"Login credentials (login, password)"
@Success		200			{object}	map[string]interface{}	"JWT tokens (access_token, refresh_token)"
@Failure		400			{object}	map[string]interface{}	"Invalid request"
@Failure		401			{object}	map[string]interface{}	"Invalid credentials"
@Failure		403			{object}	map[string]interface{}	"Account disabled, or a second factor is enabled (use an API token)"
@Router			/auth/login [post]

func HandleLogoutAPI

func HandleLogoutAPI(c *gin.Context)

HandleLogoutAPI logs out a user (client-side token removal). No YAML route uses it.

func HandleRefreshTokenAPI

func HandleRefreshTokenAPI(c *gin.Context)

HandleRefreshTokenAPI exchanges a refresh token for a new access token and a new (rotated) refresh token.

@Summary		Refresh token
@Description	Exchange a refresh token (from login or a previous refresh) for a new access token and refresh token. The account is reloaded, so role and admin flag are current; disabled or deleted accounts are rejected.
@Tags			Authentication
@Accept			json
@Produce		json
@Param			token	body		object	true	"Refresh token: {\"refresh_token\": \"...\"}"
@Success		200		{object}	map[string]interface{}	"Same body as login: user, access_token, refresh_token, token_type, expires_in, refresh_expires_in"
@Failure		400		{object}	map[string]interface{}	"Missing refresh_token"
@Failure		401		{object}	map[string]interface{}	"Invalid, expired or revoked-account refresh token"
@Router			/auth/refresh [post]

func HandleUpdateUserAPI

func HandleUpdateUserAPI(c *gin.Context)

HandleUpdateUserAPI handles PUT /api/v1/users/:id.

@Summary		Update user
@Description	Update an existing user's properties
@Tags			Users
@Accept			json
@Produce		json
@Param			id		path		int		true	"User ID"
@Param			user	body		object	true	"User update data"
@Success		200		{object}	map[string]interface{}	"Updated user"
@Failure		400		{object}	map[string]interface{}	"Invalid request"
@Failure		401		{object}	map[string]interface{}	"Unauthorized"
@Failure		404		{object}	map[string]interface{}	"User not found"
@Security		BearerAuth
@Router			/users/{id} [put]

func HandleUserMeAPI

func HandleUserMeAPI(c *gin.Context)

HandleUserMeAPI returns the current authenticated user's information.

@Summary		Get current user
@Description	Get the authenticated user's profile
@Tags			Users
@Accept			json
@Produce		json
@Success		200	{object}	map[string]interface{}	"User profile"
@Failure		401	{object}	map[string]interface{}	"Unauthorized"
@Security		BearerAuth
@Router			/users/me [get]

func JWTAuthMiddleware

func JWTAuthMiddleware() gin.HandlerFunc

JWTAuthMiddleware is a middleware that requires JWT authentication.

Types

type CoverageResponse

type CoverageResponse struct {
	Languages []LanguageCoverage `json:"languages"`
	Summary   struct {
		TotalKeys       int     `json:"total_keys"`
		AverageCoverage float64 `json:"average_coverage"`
	} `json:"summary"`
}

CoverageResponse represents the coverage statistics response.

type CreateUserRequest

type CreateUserRequest struct {
	Login     string `json:"login" binding:"required"`
	Email     string `json:"email" binding:"required,email"`
	Password  string `json:"password" binding:"required,min=8"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	ValidID   int    `json:"valid_id"`
	Groups    []int  `json:"groups"` // Optional group IDs to assign
}

CreateUserRequest represents the request to create a new user.

type I18nHandlers

type I18nHandlers struct {
	// contains filtered or unexported fields
}

I18nHandlers handles internationalization-related requests.

func NewI18nHandlers

func NewI18nHandlers() *I18nHandlers

NewI18nHandlers creates new i18n handlers.

func (*I18nHandlers) ExportTranslations

func (h *I18nHandlers) ExportTranslations(c *gin.Context)

@Router /i18n/export/{lang} [get].

func (*I18nHandlers) GetCurrentTranslations

func (h *I18nHandlers) GetCurrentTranslations(c *gin.Context)

@Router /i18n/translations [get].

func (*I18nHandlers) GetLanguageStats

func (h *I18nHandlers) GetLanguageStats(c *gin.Context)

@Router /i18n/stats [get].

func (*I18nHandlers) GetMissingTranslations

func (h *I18nHandlers) GetMissingTranslations(c *gin.Context)

@Router /i18n/missing/{lang} [get].

func (*I18nHandlers) GetSupportedLanguages

func (h *I18nHandlers) GetSupportedLanguages(c *gin.Context)

@Router /i18n/languages [get].

func (*I18nHandlers) GetTranslationCoverage

func (h *I18nHandlers) GetTranslationCoverage(c *gin.Context)

@Router /i18n/coverage [get].

func (*I18nHandlers) GetTranslations

func (h *I18nHandlers) GetTranslations(c *gin.Context)

@Router /i18n/translations/{lang} [get].

func (*I18nHandlers) RegisterRoutes

func (h *I18nHandlers) RegisterRoutes(router *gin.RouterGroup)

RegisterRoutes registers i18n routes.

func (*I18nHandlers) SetLanguage

func (h *I18nHandlers) SetLanguage(c *gin.Context)

@Router /i18n/language [post].

func (*I18nHandlers) Translate

func (h *I18nHandlers) Translate(c *gin.Context)

@Router /i18n/translate [post].

func (*I18nHandlers) ValidateTranslations

func (h *I18nHandlers) ValidateTranslations(c *gin.Context)

@Router /i18n/validate/{lang} [get].

type LanguageCoverage

type LanguageCoverage struct {
	Code           string  `json:"code"`
	Name           string  `json:"name"`
	TotalKeys      int     `json:"total_keys"`
	TranslatedKeys int     `json:"translated_keys"`
	MissingCount   int     `json:"missing_count"`
	Coverage       float64 `json:"coverage"`
}

LanguageCoverage represents coverage data for a language.

type LanguageInfo

type LanguageInfo struct {
	Code       string `json:"code"`
	Name       string `json:"name"`
	NativeName string `json:"native_name"`
	Active     bool   `json:"active"`
}

LanguageInfo represents information about a language.

type LanguageStats

type LanguageStats struct {
	Code       string  `json:"code"`
	Users      int     `json:"users"`
	Percentage float64 `json:"percentage"`
}

LanguageStats represents language usage statistics.

type LanguageStatsResponse

type LanguageStatsResponse struct {
	TotalUsers      int             `json:"total_users"`
	Languages       []LanguageStats `json:"languages"`
	DefaultLanguage string          `json:"default_language"`
}

LanguageStatsResponse represents language statistics response.

type LanguagesResponse

type LanguagesResponse struct {
	Languages []LanguageInfo `json:"languages"`
	Current   string         `json:"current"`
	Default   string         `json:"default"`
}

LanguagesResponse represents the response for supported languages.

type MissingKey

type MissingKey struct {
	Key          string `json:"key"`
	EnglishValue string `json:"english_value"`
	Category     string `json:"category"`
}

MissingKey represents a missing translation key.

type MissingKeysResponse

type MissingKeysResponse struct {
	Language    string       `json:"language"`
	MissingKeys []MissingKey `json:"missing_keys"`
	Count       int          `json:"count"`
}

MissingKeysResponse represents missing keys response.

type SetLanguageRequest

type SetLanguageRequest struct {
	Language string `json:"language" binding:"required"`
}

SetLanguageRequest represents a request to set language.

type TranslateRequest

type TranslateRequest struct {
	Key      string        `json:"key" binding:"required"`
	Language string        `json:"language"`
	Args     []interface{} `json:"args"`
}

TranslateRequest represents a request to translate a key.

type TranslateResponse

type TranslateResponse struct {
	Key         string `json:"key"`
	Translation string `json:"translation"`
	Language    string `json:"language"`
}

TranslateResponse represents the response for translation.

type TranslationsResponse

type TranslationsResponse struct {
	Language     string                 `json:"language"`
	Translations map[string]interface{} `json:"translations"`
}

TranslationsResponse represents the response for translations.

type UpdateUserRequest

type UpdateUserRequest struct {
	Email     *string `json:"email"`
	FirstName *string `json:"first_name"`
	LastName  *string `json:"last_name"`
	Password  *string `json:"password"`
	ValidID   *int    `json:"valid_id"`
}

UpdateUserRequest represents the request to update a user.

type ValidationResponse

type ValidationResponse struct {
	Language   string   `json:"language"`
	IsValid    bool     `json:"is_valid"`
	IsComplete bool     `json:"is_complete"`
	Coverage   float64  `json:"coverage"`
	Errors     []string `json:"errors"`
	Warnings   []string `json:"warnings"`
}

ValidationResponse represents translation validation response.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL