45 lines
921 B
Go
45 lines
921 B
Go
package profile
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
messages "git.k6n.net/mats/go-cart-actor/proto/profile"
|
|
)
|
|
|
|
// HandleSetProfile updates the user's core profile information.
|
|
func HandleSetProfile(p *ProfileGrain, m *messages.SetProfile) error {
|
|
if m == nil {
|
|
return fmt.Errorf("SetProfile: nil payload")
|
|
}
|
|
if m.Name != nil {
|
|
p.Name = *m.Name
|
|
}
|
|
if m.Email != nil {
|
|
p.Email = *m.Email
|
|
}
|
|
if m.Phone != nil {
|
|
p.Phone = *m.Phone
|
|
}
|
|
if m.Language != nil {
|
|
p.Language = *m.Language
|
|
}
|
|
if m.Currency != nil {
|
|
p.Currency = *m.Currency
|
|
}
|
|
if m.AvatarUrl != nil {
|
|
p.AvatarUrl = *m.AvatarUrl
|
|
}
|
|
if m.OrderEmails != nil || m.MarketingEmails != nil {
|
|
if p.EmailPreferences == nil {
|
|
p.EmailPreferences = &EmailPreferences{}
|
|
}
|
|
if m.OrderEmails != nil {
|
|
p.EmailPreferences.OrderEmails = m.OrderEmails
|
|
}
|
|
if m.MarketingEmails != nil {
|
|
p.EmailPreferences.MarketingEmails = m.MarketingEmails
|
|
}
|
|
}
|
|
return nil
|
|
}
|