learnsteam-quiz-api/internal/controllers/token.go

54 lines
1.1 KiB
Go
Raw Normal View History

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