file-system/internal/api/endpoints/auth_endpoint.go
向宁 b5df6445e5 refactor: commit all pending file_system changes
- Restructure handlers into file_commands/file_queries/file_handlers
- Add gRPC auth client, JWT middleware, rate limiting, request ID
- Add common utilities: logger, sanitizer, s3_errors
- Add unit tests for config, mediator, auth, request_id, sanitize
- Add proto definitions and generated code
- Remove old web UI pages
- Add .dockerignore and .env.example
2026-05-17 22:20:02 +08:00

49 lines
1.3 KiB
Go

package endpoints
import (
"rag/file-system/internal/api/handlers"
"rag/file-system/internal/infrastructure/mediator"
"net/http"
"github.com/gin-gonic/gin"
)
// AuthEndpoint handles authentication endpoints
type AuthEndpoint struct {
mediator *mediator.Mediator
}
// NewAuthEndpoint creates a new auth endpoint
func NewAuthEndpoint(m *mediator.Mediator) *AuthEndpoint {
return &AuthEndpoint{
mediator: m,
}
}
// Login authenticates a user with API key
// @Summary User login
// @Description Authenticate with API key
// @Tags Authentication
// @Accept json
// @Produce json
// @Param request body handlers.LoginQuery true "Login credentials"
// @Success 200 {object} handlers.LoginResult
// @Failure 400 {object} map[string]string "Invalid request"
// @Failure 500 {object} map[string]string "Internal error"
// @Router /auth/login [post]
func (e *AuthEndpoint) Login(c *gin.Context) {
var query handlers.LoginQuery
if err := c.ShouldBindJSON(&query); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid request parameters"})
return
}
result, err := mediator.Send[handlers.LoginQuery, handlers.LoginResult](e.mediator, c.Request.Context(), query)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "authentication failed"})
return
}
c.JSON(http.StatusOK, result)
}