From ccba5f38444af8d4e3764b7fdce398b0ccd702dd Mon Sep 17 00:00:00 2001 From: kandrusyak Date: Thu, 3 Aug 2023 02:23:53 +0300 Subject: [PATCH] update person models --- handler/event.go | 6 +++--- model/event.go | 20 ++++++++++---------- model/{pd.go => personal-information.go} | 4 +++- services/personal-information.go | 16 ++++++++-------- 4 files changed, 24 insertions(+), 22 deletions(-) rename model/{pd.go => personal-information.go} (89%) diff --git a/handler/event.go b/handler/event.go index 3267161..2077293 100644 --- a/handler/event.go +++ b/handler/event.go @@ -17,7 +17,7 @@ import ( // 200: Event func (h *Handler) CreateEvent(c echo.Context) (err error) { - var person *model.PersonalInformation + var person *model.PersonalInformationApi event := new(model.CreateEvent) authorId, err := uuid.Parse(c.Request().Header.Get("UserId")) orgId, err := uuid.Parse(c.Request().Header.Get("UserOrganizationId")) @@ -38,7 +38,7 @@ func (h *Handler) CreateEvent(c echo.Context) (err error) { return c.NoContent(http.StatusBadRequest) } } else { - newPerson := model.PersonalInformationCreate{ + newPerson := model.PersonalInformationApi{ FirstName: event.Person.FirstName, LastName: event.Person.LastName, Patronymic: event.Person.Patronymic, @@ -71,7 +71,7 @@ func (h *Handler) CreateEvent(c echo.Context) (err error) { newEvent.MedicId = event.MedicId newEvent.AuthorId = authorId newEvent.PersonId = person.ID - newEvent.Person = *person + newEvent.Person = person tx := h.DB.Create(&newEvent) diff --git a/model/event.go b/model/event.go index 36cc787..cfb31ec 100644 --- a/model/event.go +++ b/model/event.go @@ -9,16 +9,16 @@ import ( // swagger:model Event type Event struct { gorm.Model `json:"meta"` - ID uuid.UUID `json:"id" gorm:"type:uuid;default:gen_random_uuid();primarykey"` - Start time.Time `json:"start"` - End time.Time `json:"end"` - Author User `json:"author" gorm:"-"` - AuthorId uuid.UUID `json:"-"` - Medic User `json:"medic" gorm:"-"` - MedicId uuid.UUID `json:"-"` - Person PersonalInformation `json:"person" gorm:"-"` - PersonId uuid.UUID `json:"-"` - OrgId uuid.UUID `json:"-"` + ID uuid.UUID `json:"id" gorm:"type:uuid;default:gen_random_uuid();primarykey"` + Start time.Time `json:"start"` + End time.Time `json:"end"` + Author User `json:"author" gorm:"-"` + AuthorId uuid.UUID `json:"-"` + Medic User `json:"medic" gorm:"-"` + MedicId uuid.UUID `json:"-"` + Person *PersonalInformationApi `json:"person" gorm:"-"` + PersonId uuid.UUID `json:"-"` + OrgId uuid.UUID `json:"-"` } // swagger:model CreateEvent diff --git a/model/pd.go b/model/personal-information.go similarity index 89% rename from model/pd.go rename to model/personal-information.go index beb7c20..60e0274 100644 --- a/model/pd.go +++ b/model/personal-information.go @@ -21,10 +21,12 @@ type PersonalInformation struct { Phone string `json:"phone,omitempty" validate:"required_without=ID"` } -type PersonalInformationCreate struct { +type PersonalInformationApi struct { + ID uuid.UUID `json:"id,omitempty"` FirstName string `json:"first_name,omitempty"` LastName string `json:"last_name,omitempty"` Patronymic string `json:"patronymic,omitempty"` + BirthDate string `json:"birth_date,omitempty"` Contacts []Contact `json:"contacts"` } diff --git a/services/personal-information.go b/services/personal-information.go index 44a9a7e..6c73ef3 100644 --- a/services/personal-information.go +++ b/services/personal-information.go @@ -10,7 +10,7 @@ import ( "net/http" ) -func GetPerson(id uuid.UUID, header http.Header) (*model.PersonalInformation, error) { +func GetPerson(id uuid.UUID, header http.Header) (*model.PersonalInformationApi, error) { data, err, _ := api.GetRequest( config.Env.MSHosts.PersonsHost+"/persons/"+id.String(), header) @@ -19,7 +19,7 @@ func GetPerson(id uuid.UUID, header http.Header) (*model.PersonalInformation, er return nil, errors.New("error Request to Personal Information Service") } - pi := new(model.PersonalInformation) + pi := new(model.PersonalInformationApi) err = json.Unmarshal(data, &pi) @@ -30,7 +30,7 @@ func GetPerson(id uuid.UUID, header http.Header) (*model.PersonalInformation, er return pi, nil } -func CreatePerson(person model.PersonalInformationCreate, header http.Header) (*model.PersonalInformation, error) { +func CreatePerson(person model.PersonalInformationApi, header http.Header) (*model.PersonalInformationApi, error) { data, err, _ := api.PostRequest( config.Env.MSHosts.PersonsHost+"/persons/", person, @@ -40,7 +40,7 @@ func CreatePerson(person model.PersonalInformationCreate, header http.Header) (* return nil, errors.New("error Request to Personal Information Service") } - pi := new(model.PersonalInformation) + pi := new(model.PersonalInformationApi) err = json.Unmarshal(data, &pi) @@ -51,9 +51,9 @@ func CreatePerson(person model.PersonalInformationCreate, header http.Header) (* return pi, nil } -func GetPersons(ids []uuid.UUID, header http.Header) (map[uuid.UUID]model.PersonalInformation, error) { - var persons []model.PersonalInformation - personsMap := make(map[uuid.UUID]model.PersonalInformation) +func GetPersons(ids []uuid.UUID, header http.Header) (map[uuid.UUID]*model.PersonalInformationApi, error) { + var persons []model.PersonalInformationApi + personsMap := make(map[uuid.UUID]*model.PersonalInformationApi) data, err, req := api.PostRequest( config.Env.MSHosts.PersonsHost+"/persons/batch/", @@ -73,7 +73,7 @@ func GetPersons(ids []uuid.UUID, header http.Header) (map[uuid.UUID]model.Person } for _, person := range persons { - personsMap[person.ID] = person + personsMap[person.ID] = &person } return personsMap, nil