update person models

This commit is contained in:
kandrusyak
2023-08-03 02:23:53 +03:00
parent aeccf956f7
commit ccba5f3844
4 changed files with 24 additions and 22 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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"`
}

View File

@@ -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