update person models
This commit is contained in:
@@ -17,7 +17,7 @@ import (
|
|||||||
// 200: Event
|
// 200: Event
|
||||||
|
|
||||||
func (h *Handler) CreateEvent(c echo.Context) (err error) {
|
func (h *Handler) CreateEvent(c echo.Context) (err error) {
|
||||||
var person *model.PersonalInformation
|
var person *model.PersonalInformationApi
|
||||||
event := new(model.CreateEvent)
|
event := new(model.CreateEvent)
|
||||||
authorId, err := uuid.Parse(c.Request().Header.Get("UserId"))
|
authorId, err := uuid.Parse(c.Request().Header.Get("UserId"))
|
||||||
orgId, err := uuid.Parse(c.Request().Header.Get("UserOrganizationId"))
|
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)
|
return c.NoContent(http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
newPerson := model.PersonalInformationCreate{
|
newPerson := model.PersonalInformationApi{
|
||||||
FirstName: event.Person.FirstName,
|
FirstName: event.Person.FirstName,
|
||||||
LastName: event.Person.LastName,
|
LastName: event.Person.LastName,
|
||||||
Patronymic: event.Person.Patronymic,
|
Patronymic: event.Person.Patronymic,
|
||||||
@@ -71,7 +71,7 @@ func (h *Handler) CreateEvent(c echo.Context) (err error) {
|
|||||||
newEvent.MedicId = event.MedicId
|
newEvent.MedicId = event.MedicId
|
||||||
newEvent.AuthorId = authorId
|
newEvent.AuthorId = authorId
|
||||||
newEvent.PersonId = person.ID
|
newEvent.PersonId = person.ID
|
||||||
newEvent.Person = *person
|
newEvent.Person = person
|
||||||
|
|
||||||
tx := h.DB.Create(&newEvent)
|
tx := h.DB.Create(&newEvent)
|
||||||
|
|
||||||
|
|||||||
@@ -9,16 +9,16 @@ import (
|
|||||||
// swagger:model Event
|
// swagger:model Event
|
||||||
type Event struct {
|
type Event struct {
|
||||||
gorm.Model `json:"meta"`
|
gorm.Model `json:"meta"`
|
||||||
ID uuid.UUID `json:"id" gorm:"type:uuid;default:gen_random_uuid();primarykey"`
|
ID uuid.UUID `json:"id" gorm:"type:uuid;default:gen_random_uuid();primarykey"`
|
||||||
Start time.Time `json:"start"`
|
Start time.Time `json:"start"`
|
||||||
End time.Time `json:"end"`
|
End time.Time `json:"end"`
|
||||||
Author User `json:"author" gorm:"-"`
|
Author User `json:"author" gorm:"-"`
|
||||||
AuthorId uuid.UUID `json:"-"`
|
AuthorId uuid.UUID `json:"-"`
|
||||||
Medic User `json:"medic" gorm:"-"`
|
Medic User `json:"medic" gorm:"-"`
|
||||||
MedicId uuid.UUID `json:"-"`
|
MedicId uuid.UUID `json:"-"`
|
||||||
Person PersonalInformation `json:"person" gorm:"-"`
|
Person *PersonalInformationApi `json:"person" gorm:"-"`
|
||||||
PersonId uuid.UUID `json:"-"`
|
PersonId uuid.UUID `json:"-"`
|
||||||
OrgId uuid.UUID `json:"-"`
|
OrgId uuid.UUID `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// swagger:model CreateEvent
|
// swagger:model CreateEvent
|
||||||
|
|||||||
@@ -21,10 +21,12 @@ type PersonalInformation struct {
|
|||||||
Phone string `json:"phone,omitempty" validate:"required_without=ID"`
|
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"`
|
FirstName string `json:"first_name,omitempty"`
|
||||||
LastName string `json:"last_name,omitempty"`
|
LastName string `json:"last_name,omitempty"`
|
||||||
Patronymic string `json:"patronymic,omitempty"`
|
Patronymic string `json:"patronymic,omitempty"`
|
||||||
|
BirthDate string `json:"birth_date,omitempty"`
|
||||||
Contacts []Contact `json:"contacts"`
|
Contacts []Contact `json:"contacts"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
"net/http"
|
"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(
|
data, err, _ := api.GetRequest(
|
||||||
config.Env.MSHosts.PersonsHost+"/persons/"+id.String(),
|
config.Env.MSHosts.PersonsHost+"/persons/"+id.String(),
|
||||||
header)
|
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")
|
return nil, errors.New("error Request to Personal Information Service")
|
||||||
}
|
}
|
||||||
|
|
||||||
pi := new(model.PersonalInformation)
|
pi := new(model.PersonalInformationApi)
|
||||||
|
|
||||||
err = json.Unmarshal(data, &pi)
|
err = json.Unmarshal(data, &pi)
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ func GetPerson(id uuid.UUID, header http.Header) (*model.PersonalInformation, er
|
|||||||
return pi, nil
|
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(
|
data, err, _ := api.PostRequest(
|
||||||
config.Env.MSHosts.PersonsHost+"/persons/",
|
config.Env.MSHosts.PersonsHost+"/persons/",
|
||||||
person,
|
person,
|
||||||
@@ -40,7 +40,7 @@ func CreatePerson(person model.PersonalInformationCreate, header http.Header) (*
|
|||||||
return nil, errors.New("error Request to Personal Information Service")
|
return nil, errors.New("error Request to Personal Information Service")
|
||||||
}
|
}
|
||||||
|
|
||||||
pi := new(model.PersonalInformation)
|
pi := new(model.PersonalInformationApi)
|
||||||
|
|
||||||
err = json.Unmarshal(data, &pi)
|
err = json.Unmarshal(data, &pi)
|
||||||
|
|
||||||
@@ -51,9 +51,9 @@ func CreatePerson(person model.PersonalInformationCreate, header http.Header) (*
|
|||||||
return pi, nil
|
return pi, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPersons(ids []uuid.UUID, header http.Header) (map[uuid.UUID]model.PersonalInformation, error) {
|
func GetPersons(ids []uuid.UUID, header http.Header) (map[uuid.UUID]*model.PersonalInformationApi, error) {
|
||||||
var persons []model.PersonalInformation
|
var persons []model.PersonalInformationApi
|
||||||
personsMap := make(map[uuid.UUID]model.PersonalInformation)
|
personsMap := make(map[uuid.UUID]*model.PersonalInformationApi)
|
||||||
|
|
||||||
data, err, req := api.PostRequest(
|
data, err, req := api.PostRequest(
|
||||||
config.Env.MSHosts.PersonsHost+"/persons/batch/",
|
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 {
|
for _, person := range persons {
|
||||||
personsMap[person.ID] = person
|
personsMap[person.ID] = &person
|
||||||
}
|
}
|
||||||
|
|
||||||
return personsMap, nil
|
return personsMap, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user