Remove the ToMap birthday method
This commit is contained in:
parent
1918740563
commit
7cd86ed429
3 changed files with 6 additions and 12 deletions
|
@ -24,6 +24,11 @@ Template Format, and has the following properties available:
|
||||||
- `.MonthOfBirth`: the month that the person was born, as number.
|
- `.MonthOfBirth`: the month that the person was born, as number.
|
||||||
- `.DayOfBirth`: the day that the person was born, as number.
|
- `.DayOfBirth`: the day that the person was born, as number.
|
||||||
|
|
||||||
|
There are as well some functions available to be used:
|
||||||
|
|
||||||
|
- `getYeardsOld`: receives the year that a user was born, and returns
|
||||||
|
how old the user is getting.
|
||||||
|
|
||||||
### Pictures
|
### Pictures
|
||||||
|
|
||||||
Alongside the notification for each birthday, the bot can send a
|
Alongside the notification for each birthday, the bot can send a
|
||||||
|
|
|
@ -19,17 +19,6 @@ func (b *Birthday) Filename() string {
|
||||||
return fmt.Sprintf("%d_%d_%d_%s.png", b.YearOfBirth, b.MonthOfBirth, b.DayOfBirth, b.Phone)
|
return fmt.Sprintf("%d_%d_%d_%s.png", b.YearOfBirth, b.MonthOfBirth, b.DayOfBirth, b.Phone)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Birthday) ToMap() map[string]any {
|
|
||||||
return map[string]any{
|
|
||||||
"Name": b.Name,
|
|
||||||
"Email": b.Email,
|
|
||||||
"Phone": b.Phone,
|
|
||||||
"YearOfBirth": b.YearOfBirth,
|
|
||||||
"MonthOfBirth": b.MonthOfBirth,
|
|
||||||
"DayOfBirth": b.DayOfBirth,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewBirthdayFromRecord(record []string) (*Birthday, error) {
|
func NewBirthdayFromRecord(record []string) (*Birthday, error) {
|
||||||
if len(record) != 4 {
|
if len(record) != 4 {
|
||||||
return nil, fmt.Errorf("invalid length %d for record", len(record))
|
return nil, fmt.Errorf("invalid length %d for record", len(record))
|
||||||
|
|
|
@ -43,7 +43,7 @@ func (tns *TelegramNotificationService) Notify(birthday *model.Birthday, templat
|
||||||
var msgText string
|
var msgText string
|
||||||
if template != nil {
|
if template != nil {
|
||||||
var stringBuffer bytes.Buffer
|
var stringBuffer bytes.Buffer
|
||||||
if err := template.Execute(&stringBuffer, birthday.ToMap()); err != nil {
|
if err := template.Execute(&stringBuffer, birthday); err != nil {
|
||||||
return fmt.Errorf("cannot execute template for birthday: %w", err)
|
return fmt.Errorf("cannot execute template for birthday: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue