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) }