package admin import ( "github.com/gofiber/fiber/v2" "github.com/themakers/hlog" "penahub.gitlab.yandexcloud.net/backend/verification/internal/models" "penahub.gitlab.yandexcloud.net/backend/verification/internal/repository" "penahub.gitlab.yandexcloud.net/backend/verification/pkg/validate_controllers" "penahub.gitlab.yandexcloud.net/pena-services/customer/pkg/customer_clients" "strings" ) type VerifyAdminControllerDeps struct { Repository *repository.VerificationRepository Customer *customer_clients.CustomersClient } type VerifyAdminController struct { repository *repository.VerificationRepository customer *customer_clients.CustomersClient } func NewVerificationAdminController(deps VerifyAdminControllerDeps) *VerifyAdminController { return &VerifyAdminController{ repository: deps.Repository, customer: deps.Customer, } } func (r *VerifyAdminController) SetVerificationStatus(c *fiber.Ctx) error { var req models.ReqSetVerification hloger := c.Locals(models.HlogCtxKey).(hlog.Logger) err := c.BodyParser(&req) if err != nil { return fiber.NewError(fiber.StatusBadRequest, err.Error()) } errValidate := validate_controllers.ValidateStruct(&req) if errValidate != nil { return c.Status(fiber.StatusBadRequest).JSON(errValidate) } updated, err := r.repository.Update(c.Context(), &models.Verification{ ID: req.ID, Accepted: req.Accepted, Status: req.Status, Comment: req.Comment, TaxNumber: req.TaxNumber, }) if err != nil { return fiber.NewError(fiber.StatusInternalServerError, err.Error()) } if req.Accepted { _, err := r.customer.SetVerifyAccount(c.Context(), updated.UserID, req.Status) if err != nil { return fiber.NewError(fiber.StatusInternalServerError, err.Error()) } hloger.Emit(models.InfoVerificationAccepted{ CtxUserIP: c.IP(), CtxUserPort: c.Port(), KeyDomain: strings.Join(c.Subdomains(), "/"), KeyPath: c.Path(), CtxID: updated.ID, KeyStatus: updated.Status, CtxTaxNumber: updated.TaxNumber, }) } if !req.Accepted { hloger.Emit(models.InfoVerificationDeclined{ CtxUserIP: c.IP(), CtxUserPort: c.Port(), KeyDomain: strings.Join(c.Subdomains(), "/"), KeyPath: c.Path(), CtxID: updated.ID, KeyStatus: updated.Status, CtxComment: updated.Comment, }) } return c.SendStatus(fiber.StatusOK) } func (r *VerifyAdminController) GetVerification(c *fiber.Ctx) error { userID := c.Params("userID") if userID == "" { return fiber.NewError(fiber.StatusUnauthorized) } resp, err := r.repository.GetByUserID(c.Context(), userID) if err != nil { return c.Status(fiber.StatusInternalServerError).SendString(err.Error()) } if resp == nil { return c.SendStatus(fiber.StatusNotFound) } return c.Status(fiber.StatusOK).JSON(resp) }