zitadel/internal/api/grpc/management/mail_text_converter.go
Fabi d8e42744b4
fix: move v2 pkgs (#1331)
* fix: move eventstore pkgs

* fix: move eventstore pkgs

* fix: remove v2 view

* fix: remove v2 view
2021-02-23 15:13:04 +01:00

72 lines
2.2 KiB
Go

package management
import (
"github.com/caos/logging"
"github.com/caos/zitadel/internal/domain"
iam_model "github.com/caos/zitadel/internal/iam/model"
"github.com/caos/zitadel/pkg/grpc/management"
"github.com/golang/protobuf/ptypes"
"google.golang.org/protobuf/types/known/timestamppb"
)
func mailTextRequestToDomain(mailText *management.MailTextUpdate) *domain.MailText {
return &domain.MailText{
MailTextType: mailText.MailTextType,
Language: mailText.Language,
Title: mailText.Title,
PreHeader: mailText.PreHeader,
Subject: mailText.Subject,
Greeting: mailText.Greeting,
Text: mailText.Text,
ButtonText: mailText.ButtonText,
}
}
func mailTextFromDoamin(mailText *domain.MailText) *management.MailText {
return &management.MailText{
MailTextType: mailText.MailTextType,
Language: mailText.Language,
Title: mailText.Title,
PreHeader: mailText.PreHeader,
Subject: mailText.Subject,
Greeting: mailText.Greeting,
Text: mailText.Text,
ButtonText: mailText.ButtonText,
CreationDate: timestamppb.New(mailText.CreationDate),
ChangeDate: timestamppb.New(mailText.ChangeDate),
}
}
func mailTextsViewFromModel(queries []*iam_model.MailTextView) *management.MailTextsView {
modelQueries := make([]*management.MailTextView, len(queries))
for i, query := range queries {
modelQueries[i] = mailTextViewFromModel(query)
}
return &management.MailTextsView{
Texts: modelQueries,
}
}
func mailTextViewFromModel(mailText *iam_model.MailTextView) *management.MailTextView {
creationDate, err := ptypes.TimestampProto(mailText.CreationDate)
logging.Log("MANAG-koQnB").OnError(err).Debug("date parse failed")
changeDate, err := ptypes.TimestampProto(mailText.ChangeDate)
logging.Log("MANAG-ToDhD").OnError(err).Debug("date parse failed")
return &management.MailTextView{
Default: mailText.Default,
MailTextType: mailText.MailTextType,
Language: mailText.Language,
Title: mailText.Title,
PreHeader: mailText.PreHeader,
Subject: mailText.Subject,
Greeting: mailText.Greeting,
Text: mailText.Text,
ButtonText: mailText.ButtonText,
CreationDate: creationDate,
ChangeDate: changeDate,
}
}