You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1006 B
Go
45 lines
1006 B
Go
1 month ago
|
package free_trial
|
||
|
|
||
|
import (
|
||
|
"cls/internal/application/free_trial"
|
||
|
"cls/internal/interfaces"
|
||
|
"cls/pkg/logger"
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
type FreeTrialHandler struct {
|
||
|
service *free_trial.FreeTrialService
|
||
|
log logger.Logger
|
||
|
}
|
||
|
|
||
|
var _ interfaces.Handler = (*FreeTrialHandler)(nil)
|
||
|
|
||
|
func NewFreeTrialHandler(service *free_trial.FreeTrialService, log logger.New) *FreeTrialHandler {
|
||
|
return &FreeTrialHandler{service, log("cls:interfaces:auth")}
|
||
|
}
|
||
|
|
||
|
func (f *FreeTrialHandler) RegisterRouters(app gin.IRouter) {
|
||
|
auth := app.Group("/free_trial")
|
||
|
{
|
||
|
auth.POST("/create", f.create)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (f *FreeTrialHandler) create(c *gin.Context) {
|
||
|
dto := &free_trial.FreeTrialDto{}
|
||
|
err := c.ShouldBindJSON(dto)
|
||
|
if err != nil {
|
||
|
f.log.Error(err.Error())
|
||
|
c.AbortWithStatus(http.StatusInternalServerError)
|
||
|
return
|
||
|
}
|
||
|
err = f.service.SaveFreeTrial(dto)
|
||
|
if err != nil {
|
||
|
f.log.Error(err)
|
||
|
c.AbortWithStatus(http.StatusInternalServerError)
|
||
|
} else {
|
||
|
c.AbortWithStatus(http.StatusOK)
|
||
|
}
|
||
|
}
|