restgolanggowhatsapp-multi-devicewhatsapp-apiwhatsappwhatsapp-web-multi-devicewhatsapp-api-gorest-apigolang-whatsapp-apigolang-whatsappbot
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
45 lines
1.1 KiB
package controllers
|
|
|
|
import (
|
|
"github.com/aldinokemal/go-whatsapp-web-multidevice/services"
|
|
"github.com/aldinokemal/go-whatsapp-web-multidevice/utils"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
type AuthController struct {
|
|
Service services.AuthService
|
|
}
|
|
|
|
func NewAuthController(service services.AuthService) AuthController {
|
|
return AuthController{Service: service}
|
|
}
|
|
|
|
func (controller *AuthController) Route(app *fiber.App) {
|
|
app.Get("/auth/login", controller.Login)
|
|
app.Get("/auth/logout", controller.Logout)
|
|
}
|
|
|
|
func (controller *AuthController) Login(c *fiber.Ctx) error {
|
|
response, err := controller.Service.Login(c)
|
|
utils.PanicIfNeeded(err)
|
|
|
|
return c.JSON(utils.ResponseData{
|
|
Code: 200,
|
|
Message: "Success",
|
|
Results: map[string]interface{}{
|
|
"qr_link": "http://localhost:3000/" + response.ImagePath,
|
|
"qr_duration": response.Duration,
|
|
},
|
|
})
|
|
}
|
|
|
|
func (controller *AuthController) Logout(c *fiber.Ctx) error {
|
|
err := controller.Service.Logout(c)
|
|
utils.PanicIfNeeded(err)
|
|
|
|
return c.JSON(utils.ResponseData{
|
|
Code: 200,
|
|
Message: "Success logout",
|
|
Results: nil,
|
|
})
|
|
}
|