5 changed files with 72 additions and 54 deletions
-
57controllers/app_controller.go
-
45controllers/auth_controller.go
-
6main.go
-
3services/app_service.go
-
15services/app_service_impl.go
@ -0,0 +1,57 @@ |
|||
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 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": "http://localhost:3000/" + 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.Logout(c) |
|||
utils.PanicIfNeeded(err) |
|||
|
|||
return c.JSON(utils.ResponseData{ |
|||
Code: 200, |
|||
Message: "Reconnect success", |
|||
Results: nil, |
|||
}) |
|||
} |
|||
@ -1,45 +0,0 @@ |
|||
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, |
|||
}) |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue