34 lines
662 B
Go
34 lines
662 B
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
"satusehat-rssa/internal/integration"
|
|
"satusehat-rssa/internal/model"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type OauthHandler struct {
|
|
Oauth integration.OauthInterface
|
|
}
|
|
|
|
func NewOuathHandler(Oauth integration.OauthInterface) *OauthHandler {
|
|
return &OauthHandler{Oauth: Oauth}
|
|
}
|
|
|
|
func (oh OauthHandler) GenerateToken(c *gin.Context) {
|
|
var bodyParam model.OauthRequest
|
|
if err := c.ShouldBindJSON(&bodyParam); err != nil {
|
|
c.JSON(http.StatusBadRequest, err)
|
|
return
|
|
}
|
|
|
|
res, err := oh.Oauth.GenerateToken(bodyParam)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, err)
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, res)
|
|
}
|