app-cloudep-notification-se.../pkg/usecase/template.go

44 lines
1.2 KiB
Go

package usecase
import (
"app-cloudep-notification-service/pkg/domain/template"
"app-cloudep-notification-service/pkg/domain/usecase"
"context"
"fmt"
)
type TemplateUseCaseParam struct{}
type TemplateUseCase struct {
TemplateUseCaseParam
}
func MustTemplateUseCase(param TemplateUseCaseParam) usecase.TemplateUseCase {
return &TemplateUseCase{
param,
}
}
func (use *TemplateUseCase) GetEmailTemplateByStatic(_ context.Context, language template.Language, templateID template.Type) (template.EmailTemplate, error) {
// 查找指定語言的模板映射
templateByLang, exists := template.EmailTemplateMap[language]
if !exists {
return template.EmailTemplate{}, fmt.Errorf("email template not found for language: %s", language)
}
// 查找指定類型的模板生成函數
templateFunc, exists := templateByLang[templateID]
if !exists {
return template.EmailTemplate{}, fmt.Errorf("email template not found for type ID: %s", templateID)
}
// 執行模板生成函數
tmp, err := templateFunc()
if err != nil {
return template.EmailTemplate{}, fmt.Errorf("error generating email template: %w", err)
}
// 返回構建好的響應
return tmp, nil
}