This commit is contained in:
teddy
2025-04-30 09:47:03 +07:00
parent cce3b3e1f1
commit 6eb0c1e367
2 changed files with 39 additions and 6 deletions

View File

@@ -20,3 +20,7 @@ type SendEmailRequest struct {
CC []string `json:"cc"` CC []string `json:"cc"`
Message string `json:"message"` Message string `json:"message"`
} }
type EmailResponse struct {
Email []string `json:"email"`
}

View File

@@ -5,6 +5,7 @@ import (
"email-notification/middleware" "email-notification/middleware"
"email-notification/model" "email-notification/model"
"email-notification/query" "email-notification/query"
"encoding/json"
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
@@ -40,9 +41,11 @@ func Route(db *gorm.DB, mux *http.ServeMux) {
return return
} }
var responseEmailData []string
for _, v := range *data { for _, v := range *data {
fmt.Println("Birthday", v.Fullname) fmt.Println("Birthday", v.Fullname)
responseEmailData = append(responseEmailData, v.Email)
sendTo := []string{v.Email} sendTo := []string{v.Email}
type Data struct { type Data struct {
@@ -64,8 +67,20 @@ func Route(db *gorm.DB, mux *http.ServeMux) {
}(v) }(v)
} }
log.Printf("%+v %+v response %+v", sessionID, module, "success") responseData := model.EmailResponse{
w.Write([]byte("success")) Email: responseEmailData,
}
resData, err := json.Marshal(responseData)
if err != nil {
log.Printf("%+v %+v response %+v", sessionID, module, err.Error())
w.WriteHeader(500)
w.Write([]byte(err.Error()))
return
}
log.Printf("%+v %+v response %+v", sessionID, module, responseData)
w.Write(resData)
})) }))
mux.HandleFunc("/workanniversary-notification", middleware.ResponseTimeMiddleware(func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/workanniversary-notification", middleware.ResponseTimeMiddleware(func(w http.ResponseWriter, r *http.Request) {
@@ -93,9 +108,11 @@ func Route(db *gorm.DB, mux *http.ServeMux) {
subject := "Work Anniversary 🎉" subject := "Work Anniversary 🎉"
var responseEmailData []string
for _, v := range *data { for _, v := range *data {
fmt.Println("Workanniversary", v.Fullname) fmt.Println("Workanniversary", v.Fullname)
responseEmailData = append(responseEmailData, v.Email)
sendTo := []string{v.Email} sendTo := []string{v.Email}
type Data struct { type Data struct {
@@ -121,8 +138,20 @@ func Route(db *gorm.DB, mux *http.ServeMux) {
}(v) }(v)
} }
log.Printf("%+v %+v response %+v", sessionID, module, "success") responseData := model.EmailResponse{
w.Write([]byte("success")) Email: responseEmailData,
}
resData, err := json.Marshal(responseData)
if err != nil {
log.Printf("%+v %+v response %+v", sessionID, module, err.Error())
w.WriteHeader(500)
w.Write([]byte(err.Error()))
return
}
log.Printf("%+v %+v response %+v", sessionID, module, responseData)
w.Write(resData)
})) }))
mux.HandleFunc("/server-down-notification", middleware.ResponseTimeMiddleware(func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/server-down-notification", middleware.ResponseTimeMiddleware(func(w http.ResponseWriter, r *http.Request) {