feat: add http handlers, docs

This commit is contained in:
2025-09-15 16:45:16 +03:30
parent 5829b471d5
commit b2d5659aec
7 changed files with 466 additions and 43 deletions
+13
View File
@@ -28,3 +28,16 @@ type RefreshTokenRequest struct {
type OTPProviderReq struct {
Receptor string `json:"receptor"`
}
type OTPProviderResponse struct {
Message string `json:"message"`
}
type OTPVerifyRequest struct {
Phone string `json:"phone" validate:"required"`
Code string `json:"code" validate:"required"`
}
type OTPVerifyResponse struct {
Message string `json:"message"`
}
@@ -91,6 +91,68 @@ func (h *AuthHandler) Authenticate(c *fiber.Ctx) error {
})
}
// SendOTP sends OTP code to the provided phone number
// @Summary Send OTP code
// @Description Send OTP code to the provided phone number
// @Tags auth
// @Accept json
// @Produce json
// @Param request body dto.OTPProviderReq true "OTP Request"
// @Success 200 {object} dto.OTPProviderResponse
// @Failure 400 {object} map[string]string
// @Failure 500 {object} map[string]string
// @Router /auth/send-otp [post]
func (h *AuthHandler) SendOTP(c *fiber.Ctx) error {
var req dto.OTPProviderReq
if err := c.BodyParser(&req); err != nil {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
"error": "invalid request body",
})
}
_, err := h.authService.SendOTPCode(c.Context(), req.Receptor)
if err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{
"error": err.Error(),
})
}
return c.Status(fiber.StatusOK).JSON(dto.OTPProviderResponse{
Message: "OTP code sent successfully",
})
}
// VerifyOTP verifies the OTP code
// @Summary Verify OTP code
// @Description Verify the provided OTP code for the phone number
// @Tags auth
// @Accept json
// @Produce json
// @Param request body dto.OTPVerifyRequest true "OTP Verify Request"
// @Success 200 {object} dto.OTPVerifyResponse
// @Failure 400 {object} map[string]string
// @Failure 401 {object} map[string]string
// @Router /auth/verify-otp [post]
func (h *AuthHandler) VerifyOTP(c *fiber.Ctx) error {
var req dto.OTPVerifyRequest
if err := c.BodyParser(&req); err != nil {
return c.Status(fiber.StatusBadRequest).JSON(fiber.Map{
"error": "invalid request body",
})
}
err := h.authService.VerifyOTP(c.Context(), req.Phone, req.Code)
if err != nil {
return c.Status(fiber.StatusUnauthorized).JSON(fiber.Map{
"error": err.Error(),
})
}
return c.Status(fiber.StatusOK).JSON(dto.OTPVerifyResponse{
Message: "OTP verified successfully",
})
}
func (h *AuthHandler) HelloWorld(c *fiber.Ctx) error {
return c.Status(fiber.StatusOK).JSON(fiber.Map{
"message": "Hello, World!",
+2
View File
@@ -47,4 +47,6 @@ func registerPublicRoutes(router fiber.Router, app *app.AppContainer) {
// Register auth routes
authgroup.Post("/challenge", authHandler.GenerateChallenge)
authgroup.Post("/authenticate", authHandler.Authenticate)
authgroup.Post("/send-otp", authHandler.SendOTP)
authgroup.Post("/verify-otp", authHandler.VerifyOTP)
}