test.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package test
  2. import (
  3. "fmt"
  4. "net/http"
  5. "github.com/gin-gonic/gin"
  6. "github.com/metarare/metarare_api/common"
  7. "github.com/metarare/metarare_api/helpers/gerror"
  8. "github.com/spf13/viper"
  9. "gorm.io/gorm"
  10. )
  11. type TestV1Router struct {
  12. group *gin.RouterGroup
  13. mDB *gorm.DB
  14. rDB *gorm.DB
  15. Env *viper.Viper
  16. }
  17. type TestSendmailBody struct {
  18. Email string `json:"email" binding:"required"`
  19. }
  20. func NewTestV1Router(r common.Router, basePath string) TestV1Router {
  21. h := TestV1Router{
  22. group: r.Version.Group(basePath),
  23. mDB: r.Db.MasterDB,
  24. rDB: r.Db.ReadDB,
  25. Env: r.Env,
  26. }
  27. h.group.POST("sendmail", h.certificationCode)
  28. return h
  29. }
  30. // certificationCode godoc
  31. // @Summary send mail code
  32. // @Description 출금하기 2차 인증
  33. // @Schemes
  34. // @Tags test
  35. // @name get-string-by-int
  36. // @Accept json
  37. // @Produce json
  38. // @Param TestSendmailBody body TestSendmailBody true "email: test@abc.mr"
  39. // @Success 200 {string} OK!
  40. // @Router /test/sendmail [post]
  41. func (u TestV1Router) certificationCode(c *gin.Context) {
  42. request := TestSendmailBody{}
  43. if err := c.ShouldBindJSON(&request); err != nil {
  44. gerror.IntegratedResponseToRequest(c, http.StatusBadRequest, gerror.InvalidParameterValue, nil, err)
  45. return
  46. }
  47. _email := request.Email
  48. fmt.Println("send mail", u.Env.GetString("smtp.email"), u.Env.GetString("smtp.password"))
  49. code, err := common.SendCertificationCode(_email, u.Env.GetString("smtp.email"), u.Env.GetString("smtp.password"))
  50. if err != nil {
  51. gerror.IntegratedResponseToRequest(c, http.StatusInternalServerError, gerror.InvalidParameterValue, nil, err)
  52. return
  53. }
  54. gerror.IntegratedResponseToRequest(c, http.StatusOK, gerror.OK, code, nil)
  55. }