-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from homenoc/develop
v3.1.0
- Loading branch information
Showing
10 changed files
with
123 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package mail | ||
|
||
type Mail struct { | ||
ToMail string `json:"to_mail"` | ||
Subject string `json:"subject"` | ||
Content string `json:"content"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package v0 | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
auth "github.com/homenoc/dsbd-backend/pkg/api/core/auth/v0" | ||
"github.com/homenoc/dsbd-backend/pkg/api/core/common" | ||
"github.com/homenoc/dsbd-backend/pkg/api/core/mail" | ||
"net/http" | ||
) | ||
|
||
func SendAdmin(c *gin.Context) { | ||
var input mail.Mail | ||
|
||
resultAdmin := auth.AdminAuthentication(c.Request.Header.Get("ACCESS_TOKEN")) | ||
if resultAdmin.Err != nil { | ||
c.JSON(http.StatusUnauthorized, common.Error{Error: resultAdmin.Err.Error()}) | ||
return | ||
} | ||
|
||
err := c.BindJSON(&input) | ||
if err != nil { | ||
c.JSON(http.StatusBadRequest, common.Error{Error: err.Error()}) | ||
return | ||
} | ||
|
||
if err = check(input); err != nil { | ||
c.JSON(http.StatusBadRequest, common.Error{Error: err.Error()}) | ||
return | ||
} | ||
|
||
if err = SendMail(input); err != nil { | ||
c.JSON(http.StatusInternalServerError, common.Error{Error: err.Error()}) | ||
} else { | ||
c.JSON(http.StatusOK, common.Result{}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package v0 | ||
|
||
import ( | ||
"fmt" | ||
"github.com/homenoc/dsbd-backend/pkg/api/core/mail" | ||
"strings" | ||
) | ||
|
||
func check(input mail.Mail) error { | ||
// check | ||
if !strings.Contains(input.ToMail, "@") { | ||
return fmt.Errorf("invalid: email address") | ||
} | ||
|
||
if input.Subject == "" { | ||
return fmt.Errorf("no data: subject") | ||
} | ||
|
||
if input.Content == "" { | ||
return fmt.Errorf("no data: content") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package v0 | ||
|
||
import ( | ||
"github.com/ashwanthkumar/slack-go-webhook" | ||
"github.com/homenoc/dsbd-backend/pkg/api/core/mail" | ||
"github.com/homenoc/dsbd-backend/pkg/api/core/tool/notification" | ||
) | ||
|
||
func noticeSlack(err error, input mail.Mail) { | ||
// 審査ステータスのSlack通知 | ||
attachment := slack.Attachment{} | ||
|
||
if err != nil { | ||
attachment.AddField(slack.Field{Title: "Title", Value: "メール送信(失敗)"}). | ||
AddField(slack.Field{Title: "To", Value: input.ToMail}). | ||
AddField(slack.Field{Title: "Subject", Value: input.Subject}). | ||
AddField(slack.Field{Title: "Content", Value: input.Content}). | ||
AddField(slack.Field{Title: "Error", Value: err.Error()}) | ||
notification.SendSlack(notification.Slack{Attachment: attachment, ID: "main", Status: false}) | ||
} else { | ||
attachment.AddField(slack.Field{Title: "Title", Value: "メール送信"}). | ||
AddField(slack.Field{Title: "To", Value: input.ToMail}). | ||
AddField(slack.Field{Title: "Subject", Value: input.Subject}). | ||
AddField(slack.Field{Title: "Content", Value: input.Content}) | ||
notification.SendSlack(notification.Slack{Attachment: attachment, ID: "main", Status: true}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters