gowhatsapp-multi-devicewhatsapp-apiwhatsapprestgolangwhatsapp-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.
58 lines
1.4 KiB
58 lines
1.4 KiB
package controllers
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/aldinokemal/go-whatsapp-web-multidevice/services"
|
|
"github.com/aldinokemal/go-whatsapp-web-multidevice/utils"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
type AppController struct {
|
|
Service services.AppService
|
|
}
|
|
|
|
func NewAppController(service services.AppService) AppController {
|
|
return AppController{Service: service}
|
|
}
|
|
|
|
func (controller *AppController) Route(app *fiber.App) {
|
|
app.Get("/app/login", controller.Login)
|
|
app.Get("/app/logout", controller.Logout)
|
|
app.Get("/app/reconnect", controller.Reconnect)
|
|
}
|
|
|
|
func (controller *AppController) 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": fmt.Sprintf("%s/%s", c.Hostname(), response.ImagePath),
|
|
"qr_duration": response.Duration,
|
|
},
|
|
})
|
|
}
|
|
|
|
func (controller *AppController) 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,
|
|
})
|
|
}
|
|
|
|
func (controller *AppController) Reconnect(c *fiber.Ctx) error {
|
|
err := controller.Service.Reconnect(c)
|
|
utils.PanicIfNeeded(err)
|
|
|
|
return c.JSON(utils.ResponseData{
|
|
Code: 200,
|
|
Message: "Reconnect success",
|
|
Results: nil,
|
|
})
|
|
}
|