refactor(mail): extract mail logic into MailService

Introduce MailService as a convenience layer between handlers/services
and MailRepo. Provides Send, SendSystem, SendGuildInvite, and
BroadcastToGuild methods that encapsulate the boolean flag combinations.

GuildService now depends on MailService instead of MailRepo directly,
simplifying its mail-sending calls from verbose SendMail(..., false, true)
to clean SendSystem(recipientID, subject, body).

Guild mail broadcast logic moved from handleMsgMhfSendMail into
MailService.BroadcastToGuild.
This commit is contained in:
Houmgaor
2026-02-24 00:05:56 +01:00
parent 1e9de7920d
commit 077c08fd49
9 changed files with 292 additions and 64 deletions

View File

@@ -84,16 +84,16 @@ type AnswerScoutResult struct {
// GuildService encapsulates guild business logic, sitting between handlers and repos.
type GuildService struct {
guildRepo GuildRepo
mailRepo MailRepo
mailSvc *MailService
charRepo CharacterRepo
logger *zap.Logger
}
// NewGuildService creates a new GuildService.
func NewGuildService(gr GuildRepo, mr MailRepo, cr CharacterRepo, log *zap.Logger) *GuildService {
func NewGuildService(gr GuildRepo, ms *MailService, cr CharacterRepo, log *zap.Logger) *GuildService {
return &GuildService{
guildRepo: gr,
mailRepo: mr,
mailSvc: ms,
charRepo: cr,
logger: log,
}
@@ -148,7 +148,7 @@ func (svc *GuildService) OperateMember(actorCharID, targetCharID uint32, action
}
// Send mail best-effort
if mailErr := svc.mailRepo.SendMail(mail.SenderID, mail.RecipientID, mail.Subject, mail.Body, 0, 0, false, true); mailErr != nil {
if mailErr := svc.mailSvc.SendSystem(mail.RecipientID, mail.Subject, mail.Body); mailErr != nil {
svc.logger.Warn("Failed to send guild member operation mail", zap.Error(mailErr))
}
@@ -255,9 +255,8 @@ func (svc *GuildService) Leave(charID, guildID uint32, isApplicant bool, guildNa
}
// Best-effort withdrawal notification
if err := svc.mailRepo.SendMail(0, charID, "Withdrawal",
fmt.Sprintf("You have withdrawn from 「%s」.", guildName),
0, 0, false, true); err != nil {
if err := svc.mailSvc.SendSystem(charID, "Withdrawal",
fmt.Sprintf("You have withdrawn from 「%s」.", guildName)); err != nil {
svc.logger.Warn("Failed to send guild withdrawal notification", zap.Error(err))
}
@@ -342,7 +341,7 @@ func (svc *GuildService) AnswerScout(charID, leaderID uint32, accept bool, strin
// Send mails best-effort
for _, m := range mails {
if mailErr := svc.mailRepo.SendMail(m.SenderID, m.RecipientID, m.Subject, m.Body, 0, 0, false, true); mailErr != nil {
if mailErr := svc.mailSvc.SendSystem(m.RecipientID, m.Subject, m.Body); mailErr != nil {
svc.logger.Warn("Failed to send guild scout response mail", zap.Error(mailErr))
}
}