From b5a5a0f9e783c723b1242d3e95cc1967af02d1ea Mon Sep 17 00:00:00 2001 From: elliot14A Date: Tue, 30 May 2023 11:53:46 +0530 Subject: [PATCH 1/2] feat: fixed parsing birth_date bug in profile update --- server/action/profile/update.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/action/profile/update.go b/server/action/profile/update.go index 2021af7e..5a9db8c7 100644 --- a/server/action/profile/update.go +++ b/server/action/profile/update.go @@ -19,7 +19,7 @@ type user struct { LastName string `json:"last_name"` DisplayName string `json:"display_name" validate:"required"` Slug string `json:"slug" validate:"required"` - BirthDate time.Time `json:"birth_date"` + BirthDate string `json:"birth_date"` Gender string `json:"gender"` FeaturedMediumID uint `json:"featured_medium_id"` Description string `json:"description"` @@ -85,16 +85,16 @@ func update(w http.ResponseWriter, r *http.Request) { "meta": req.Meta, } - if !req.BirthDate.IsZero() { - birthDate := req.BirthDate.Format("2006-01-02") // format birth_date to YYYY-MM-DD - + timeLayout := "2006-01-02" + if req.BirthDate != "" { + birth_date, err := time.Parse(timeLayout, req.BirthDate) if err != nil { tx.Rollback() loggerx.Error(err) - errorx.Render(w, errorx.Parser(errorx.DecodeError())) + errorx.Render(w, errorx.Parser(errorx.GetMessage("invalid birth_date", http.StatusUnprocessableEntity))) return } - updateUser["birth_date"] = birthDate + updateUser["birth_date"] = birth_date } else { updateUser["birth_date"] = nil } From 2649e28d4a3d197f9be3e9f01a32ddff78677e4b Mon Sep 17 00:00:00 2001 From: elliot14A Date: Wed, 31 May 2023 12:34:02 +0530 Subject: [PATCH 2/2] fix: birth_date is set to null if it is passed in update req body --- server/action/profile/update.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/server/action/profile/update.go b/server/action/profile/update.go index 5a9db8c7..f1423a5c 100644 --- a/server/action/profile/update.go +++ b/server/action/profile/update.go @@ -85,8 +85,8 @@ func update(w http.ResponseWriter, r *http.Request) { "meta": req.Meta, } - timeLayout := "2006-01-02" if req.BirthDate != "" { + timeLayout := "2006-01-02" birth_date, err := time.Parse(timeLayout, req.BirthDate) if err != nil { tx.Rollback() @@ -95,8 +95,6 @@ func update(w http.ResponseWriter, r *http.Request) { return } updateUser["birth_date"] = birth_date - } else { - updateUser["birth_date"] = nil } if req.FeaturedMediumID == 0 {