From 68bd7dec1176344d1aec7bdfb9c76a053a971f59 Mon Sep 17 00:00:00 2001 From: Vargha Csongor Date: Tue, 16 Apr 2024 23:00:06 +0200 Subject: [PATCH] update person to string --- backend/memgraph/model.go | 40 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/backend/memgraph/model.go b/backend/memgraph/model.go index 84e282b..68a12f7 100644 --- a/backend/memgraph/model.go +++ b/backend/memgraph/model.go @@ -37,9 +37,43 @@ type Person struct { } func (p *Person) ToString() string { - result := fmt.Sprintf("ID: '%s', Firstname: '%s', Lastname: '%s', Middlename: '%s', MothersFirstname: '%s', MothersLastname: '%s'", p.ID, p.Firstname, p.Lastname, p.Middlename, p.MothersFirstname, p.MothersLastname) - result = fmt.Sprintf("%s, Born: date({year:%d, month:%d, day:%d}), Death: date({year:%d, month:%d, day:%d})", result, p.Born.Year(), p.Born.Month(), p.Born.Day(), p.Death.Year(), p.Death.Month(), p.Death.Day()) - result = fmt.Sprintf("%s, Birthplace: '%s', Residence: '%s', Deathplace: '%s', OccupationToDisplay: '%s', ProfilePicture: '%s'", result, p.Birthplace, p.Residence, p.Deathplace, p.OccupationToDisplay, p.ProfilePicture) + result := fmt.Sprintf("ID: '%s'", p.ID) + if p.Firstname != "" { + result = fmt.Sprintf("%s, Firstname: '%s'", result, p.Firstname) + } + if p.Lastname != "" { + result = fmt.Sprintf("%s, Lastname: '%s'", result, p.Lastname) + } + if p.Middlename != "" { + result = fmt.Sprintf("%s, Middlename: '%s'", result, p.Middlename) + } + if p.MothersFirstname != "" { + result = fmt.Sprintf("%s, MothersFirstname: '%s'", result, p.MothersFirstname) + } + if p.MothersLastname != "" { + result = fmt.Sprintf("%s, MothersLastname: '%s'", result, p.MothersLastname) + } + if !p.Born.IsZero() { + result = fmt.Sprintf("%s, Born: date({year:%d, month:%d, day:%d})", result, p.Born.Year(), p.Born.Month(), p.Born.Day()) + } + if !p.Death.IsZero() { + result = fmt.Sprintf("%s, Death: date({year:%d, month:%d, day:%d})", result, p.Death.Year(), p.Death.Month(), p.Death.Day()) + } + if p.Birthplace != "" { + result = fmt.Sprintf("%s, Birthplace: '%s'", result, p.Birthplace) + } + if p.Residence != "" { + result = fmt.Sprintf("%s, Residence: '%s'", result, p.Residence) + } + if p.Deathplace != "" { + result = fmt.Sprintf("%s, Deathplace: '%s'", result, p.Deathplace) + } + if p.OccupationToDisplay != "" { + result = fmt.Sprintf("%s, OccupationToDisplay: '%s'", result, p.OccupationToDisplay) + } + if p.ProfilePicture != "" { + result = fmt.Sprintf("%s, ProfilePicture: '%s'", result, p.ProfilePicture) + } if p.Titles != nil && len(p.Titles) > 0 { result = fmt.Sprintf("%s, Titles: [", result)