1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package test
- import (
- "fmt"
- "net/http"
- "github.com/gin-gonic/gin"
- "github.com/metarare/metarare_api/common"
- "github.com/metarare/metarare_api/helpers/gerror"
- "github.com/spf13/viper"
- "gorm.io/gorm"
- )
- type TestV1Router struct {
- group *gin.RouterGroup
- mDB *gorm.DB
- rDB *gorm.DB
- Env *viper.Viper
- }
- type TestSendmailBody struct {
- Email string `json:"email" binding:"required"`
- }
- func NewTestV1Router(r common.Router, basePath string) TestV1Router {
- h := TestV1Router{
- group: r.Version.Group(basePath),
- mDB: r.Db.MasterDB,
- rDB: r.Db.ReadDB,
- Env: r.Env,
- }
- h.group.POST("sendmail", h.certificationCode)
- return h
- }
- // certificationCode godoc
- // @Summary send mail code
- // @Description 출금하기 2차 인증
- // @Schemes
- // @Tags test
- // @name get-string-by-int
- // @Accept json
- // @Produce json
- // @Param TestSendmailBody body TestSendmailBody true "email: test@abc.mr"
- // @Success 200 {string} OK!
- // @Router /test/sendmail [post]
- func (u TestV1Router) certificationCode(c *gin.Context) {
- request := TestSendmailBody{}
- if err := c.ShouldBindJSON(&request); err != nil {
- gerror.IntegratedResponseToRequest(c, http.StatusBadRequest, gerror.InvalidParameterValue, nil, err)
- return
- }
- _email := request.Email
- fmt.Println("send mail", u.Env.GetString("smtp.email"), u.Env.GetString("smtp.password"))
- code, err := common.SendCertificationCode(_email, u.Env.GetString("smtp.email"), u.Env.GetString("smtp.password"))
- if err != nil {
- gerror.IntegratedResponseToRequest(c, http.StatusInternalServerError, gerror.InvalidParameterValue, nil, err)
- return
- }
- gerror.IntegratedResponseToRequest(c, http.StatusOK, gerror.OK, code, nil)
- }
|