55 "net/http"
66
77 "github.com/go-playground/validator/v10"
8+ "github.com/google/uuid"
89 "github.com/rs/zerolog"
910 res "github.com/swamphacks/core/apps/api/internal/api/response"
1011 "github.com/swamphacks/core/apps/api/internal/email"
@@ -82,6 +83,18 @@ type QueueConfirmationEmailFields struct {
8283 FirstName string `json:"firstName" validate:"required"`
8384}
8485
86+ // Queue a Confirmation Email
87+ //
88+ // @Summary Queue a Confirmation Email Request
89+ // @Description Push a Confirmation Email request to the task queue
90+ // @Tags Email
91+ // @Accept json
92+ // @Produce json
93+ // @Param request body QueueConfirmationEmailFields true "Email data"
94+ // @Success 201 {object} string "OK: Email request queued"
95+ // @Failure 400 {object} response.ErrorResponse "Bad request/Malformed request. The email request is potentially invalid."
96+ // @Failure 500 {object} response.ErrorResponse "Server Error: The server went kaput while queueing email sending"
97+ // @Router /email/queue [post]
8598func (h * EmailHandler ) QueueConfirmationEmail (w http.ResponseWriter , r * http.Request ) {
8699 var req QueueConfirmationEmailFields
87100 decoder := json .NewDecoder (r .Body )
@@ -103,3 +116,49 @@ func (h *EmailHandler) QueueConfirmationEmail(w http.ResponseWriter, r *http.Req
103116
104117 res .Send (w , http .StatusOK , nil )
105118}
119+
120+ type QueueWelcomeEmailFields struct {
121+ Email string `json:"email" validate:"required"`
122+ FirstName string `json:"firstName" validate:"required"`
123+ UserId string `json:userId validate:"required"`
124+ }
125+
126+ // Queue a Welcome Email
127+ //
128+ // @Summary Queue a Welcome Email
129+ // @Description Push an Welcome Email request to the task queue
130+ // @Tags Email
131+ // @Accept json
132+ // @Produce json
133+ // @Param request body QueueConfirmationEmailFields true "Email data"
134+ // @Success 201 {object} string "OK: Email request queued"
135+ // @Failure 400 {object} response.ErrorResponse "Bad request/Malformed request. The email request is potentially invalid."
136+ // @Failure 500 {object} response.ErrorResponse "Server Error: The server went kaput while queueing email sending"
137+ func (h * EmailHandler ) QueueWelcomeEmail (w http.ResponseWriter , r * http.Request ) {
138+ var req QueueWelcomeEmailFields
139+ decoder := json .NewDecoder (r .Body )
140+ decoder .DisallowUnknownFields ()
141+ err := decoder .Decode (& req )
142+ if err != nil {
143+ res .SendError (w , http .StatusBadRequest , res .NewError ("invalid_request" , "Could not parse request body" ))
144+ return
145+ }
146+
147+ validate := validator .New ()
148+ if err := validate .Struct (req ); err != nil {
149+ res .SendError (w , http .StatusBadRequest , res .NewError ("invalid_request" , err .Error ()))
150+ }
151+
152+ parsedUserId , err := uuid .Parse (req .UserId )
153+ if err != nil {
154+ res .SendError (w , http .StatusBadRequest , res .NewError ("invalid_request" , "userId must be of type uuid" ))
155+ return
156+ }
157+
158+ err = h .emailService .QueueWelcomeEmail (r .Context (), req .Email , req .FirstName , parsedUserId )
159+ if err != nil {
160+ res .SendError (w , http .StatusInternalServerError , res .NewError ("internal_err" , "Hacker email could not be queued." ))
161+ }
162+
163+ res .Send (w , http .StatusOK , nil )
164+ }
0 commit comments