api

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

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 HandleAddUserToGroupAPI

func HandleAddUserToGroupAPI(c *gin.Context)

HandleAddUserToGroupAPI handles POST /api/v1/users/:id/groups.

@Summary		Add user to group
@Description	Add a user to a group
@Tags			Users
@Accept			json
@Produce		json
@Param			id		path		int		true	"User ID"
@Param			group	body		object	true	"Group data (group_id, permission)"
@Success		200		{object}	map[string]interface{}	"User added to group"
@Failure		400		{object}	map[string]interface{}	"Invalid request"
@Failure		401		{object}	map[string]interface{}	"Unauthorized"
@Security		BearerAuth
@Router			/users/{id}/groups [post]

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 HandleGetUserGroupsAPI

func HandleGetUserGroupsAPI(c *gin.Context)

HandleGetUserGroupsAPI handles GET /api/v1/users/:id/groups.

@Summary		Get user groups
@Description	List groups a user belongs to
@Tags			Users
@Accept			json
@Produce		json
@Param			id	path		int	true	"User ID"
@Success		200	{object}	map[string]interface{}	"List of groups"
@Failure		401	{object}	map[string]interface{}	"Unauthorized"
@Failure		404	{object}	map[string]interface{}	"User not found"
@Security		BearerAuth
@Router			/users/{id}/groups [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"
@Router			/auth/login [post]

func HandleLogoutAPI

func HandleLogoutAPI(c *gin.Context)

HandleLogoutAPI logs out a user (client-side token removal).

@Summary		Logout
@Description	Logout user (invalidates session, client should discard tokens)
@Tags			Authentication
@Accept			json
@Produce		json
@Success		200	{object}	map[string]interface{}	"Logout successful"
@Security		BearerAuth
@Router			/auth/logout [post]

func HandleRefreshTokenAPI

func HandleRefreshTokenAPI(c *gin.Context)

HandleRefreshTokenAPI refreshes an expired JWT token.

@Summary		Refresh token
@Description	Exchange a refresh token for a new access token
@Tags			Authentication
@Accept			json
@Produce		json
@Param			token	body		object	true	"Refresh token"
@Success		200		{object}	map[string]interface{}	"New access token"
@Failure		400		{object}	map[string]interface{}	"Invalid request"
@Failure		401		{object}	map[string]interface{}	"Invalid or expired refresh token"
@Router			/auth/refresh [post]

func HandleRegisterAPI

func HandleRegisterAPI(c *gin.Context)

HandleRegisterAPI registers a new user (if enabled).

@Summary		Register user
@Description	Register a new user (if self-registration is enabled)
@Tags			Authentication
@Accept			json
@Produce		json
@Param			user	body		object	true	"User registration data"
@Success		201		{object}	map[string]interface{}	"Registered user"
@Failure		400		{object}	map[string]interface{}	"Invalid request or registration disabled"
@Router			/auth/register [post]

func HandleRemoveUserFromGroupAPI

func HandleRemoveUserFromGroupAPI(c *gin.Context)

HandleRemoveUserFromGroupAPI handles DELETE /api/v1/users/:id/groups/:group_id.

@Summary		Remove user from group
@Description	Remove a user from a group
@Tags			Users
@Accept			json
@Produce		json
@Param			id			path		int	true	"User ID"
@Param			group_id	path		int	true	"Group ID"
@Success		200			{object}	map[string]interface{}	"User removed from group"
@Failure		401			{object}	map[string]interface{}	"Unauthorized"
@Failure		404			{object}	map[string]interface{}	"Not found"
@Security		BearerAuth
@Router			/users/{id}/groups/{group_id} [delete]

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 AuthHandler

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

func NewAuthHandler

func NewAuthHandler(authService *service.AuthService) *AuthHandler

func (*AuthHandler) ChangePassword

func (h *AuthHandler) ChangePassword(c *gin.Context)

func (*AuthHandler) GetCurrentUser

func (h *AuthHandler) GetCurrentUser(c *gin.Context)

func (*AuthHandler) Login

func (h *AuthHandler) Login(c *gin.Context)

func (*AuthHandler) Logout

func (h *AuthHandler) Logout(c *gin.Context)

func (*AuthHandler) RefreshToken

func (h *AuthHandler) RefreshToken(c *gin.Context)

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 /api/v1/i18n/export/{lang} [get].

func (*I18nHandlers) GetCurrentTranslations

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

@Router /api/v1/i18n/translations [get].

func (*I18nHandlers) GetLanguageStats

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

@Router /api/v1/i18n/stats [get].

func (*I18nHandlers) GetMissingTranslations

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

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

func (*I18nHandlers) GetSupportedLanguages

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

@Router /api/v1/i18n/languages [get].

func (*I18nHandlers) GetTranslationCoverage

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

@Router /api/v1/i18n/coverage [get].

func (*I18nHandlers) GetTranslations

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

@Router /api/v1/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 /api/v1/i18n/language [post].

func (*I18nHandlers) Translate

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

@Router /api/v1/i18n/translate [post].

func (*I18nHandlers) ValidateTranslations

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

@Router /api/v1/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