cslms-api/internal/controllers/token.go

54 lines
1.1 KiB
Go
Raw Normal View History

2023-12-27 17:31:49 +09:00
package controllers
import (
"net/http"
"learnsteam/cslms-api/internal/models"
"learnsteam/cslms-api/internal/services"
"github.com/gin-gonic/gin"
)
type TokenController interface {
Refresh(*gin.Context)
}
type tokenController struct {
service services.TokenService
}
func NewTokenController(service services.TokenService) TokenController {
return &tokenController{
service: service,
}
}
// Refresh Token
//
// @Summary AccessToken Refresh
// @Description AccessToken을 RefreshToken으로 갱신합니다.
// @Tags Token
//
// @Accept json
// @Produce json
//
// @Param refresh_token body string true "RefreshToken"
//
// @Router /token/refresh [post]
// @Success 200 {object} models.Token
func (controller *tokenController) Refresh(c *gin.Context) {
var request models.RefreshTokenRequest
if err := c.ShouldBindJSON(&request); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
result, err := controller.service.Refresh(request.RefreshToken)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, result)
}