88 lines
2.1 KiB
Go
88 lines
2.1 KiB
Go
package controllers
|
|
|
|
import (
|
|
"codeword/internal/models"
|
|
"codeword/internal/service"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
type RecoverController struct {
|
|
RecoverService *service.RecoverService
|
|
}
|
|
|
|
func NewRecoverController(service *service.RecoverService) *RecoverController {
|
|
return &RecoverController{
|
|
RecoverService: service,
|
|
}
|
|
}
|
|
|
|
func (c *RecoverController) Register(router fiber.Router) {
|
|
|
|
router.Get("/liveness", c.Liveness)
|
|
|
|
router.Post("/recover", c.Recovery)
|
|
|
|
router.Get("/recover/{sign}", c.Recoverylink)
|
|
|
|
router.Get("/readiness", c.Readiness)
|
|
|
|
}
|
|
|
|
func (c *RecoverController) Name() string {
|
|
return ""
|
|
}
|
|
|
|
func (c *RecoverController) Liveness(ctx *fiber.Ctx) error {
|
|
// Обработчик для метода Liveness
|
|
|
|
err := c.RecoverService.Liveness(ctx.Context())
|
|
|
|
if err != nil {
|
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
|
}
|
|
return ctx.SendStatus(fiber.StatusOK)
|
|
|
|
}
|
|
|
|
func (c *RecoverController) Recovery(ctx *fiber.Ctx) error {
|
|
// Обработчик для метода Recovery
|
|
|
|
var request models.RecoveryReq
|
|
if err := ctx.BodyParser(&request); err != nil {
|
|
return ctx.Status(fiber.StatusBadRequest).JSON(fiber.Map{"error": "Invalid request payload"})
|
|
}
|
|
|
|
err := c.RecoverService.Recovery(ctx.Context(), &request)
|
|
|
|
if err != nil {
|
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
|
}
|
|
return ctx.SendStatus(fiber.StatusOK)
|
|
|
|
}
|
|
|
|
func (c *RecoverController) Recoverylink(ctx *fiber.Ctx) error {
|
|
// Обработчик для метода Recoverylink
|
|
|
|
err := c.RecoverService.Recoverylink(ctx.Context())
|
|
|
|
if err != nil {
|
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
|
}
|
|
return ctx.SendStatus(fiber.StatusOK)
|
|
|
|
}
|
|
|
|
func (c *RecoverController) Readiness(ctx *fiber.Ctx) error {
|
|
// Обработчик для метода Readiness
|
|
|
|
err := c.RecoverService.Readiness(ctx.Context())
|
|
|
|
if err != nil {
|
|
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
|
|
}
|
|
return ctx.SendStatus(fiber.StatusOK)
|
|
|
|
}
|