revised lib and usecase update
This commit is contained in:
@@ -26,7 +26,8 @@ type FilterDto struct {
|
||||
}
|
||||
|
||||
type ReadDetailDto struct {
|
||||
Id uint16 `json:"id"`
|
||||
Id uint16 `json:"id"`
|
||||
Includes string `json:"includes"`
|
||||
}
|
||||
|
||||
type UpdateDto struct {
|
||||
|
||||
@@ -36,7 +36,9 @@ func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) {
|
||||
if id <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
dto := eir.ReadDetailDto{}
|
||||
sf.UrlQueryParam(&dto, *r.URL)
|
||||
dto.Id = uint16(id)
|
||||
res, err := uir.ReadDetail(dto)
|
||||
rw.DataResponse(w, res, err)
|
||||
|
||||
@@ -152,6 +152,7 @@ func ReadDetail(input eir.ReadDetailDto) (*d.Data, error) {
|
||||
return err
|
||||
}
|
||||
|
||||
//input.Includes = "encounter,unit,doctor"
|
||||
if data, err = ReadDetailData(input, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -238,6 +239,7 @@ func Update(input eir.UpdateDto) (*d.Data, error) {
|
||||
}
|
||||
|
||||
// Get Updated Data
|
||||
rdDto.Includes = "encounter,unit,doctor"
|
||||
if data, err = ReadDetailData(rdDto, &event, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -21,12 +21,3 @@ func setData[T *ir.CreateDto | *ir.UpdateDto](input T, data *ir.InternalReferenc
|
||||
data.Unit_Id = inputSrc.Unit_Id
|
||||
data.Doctor_Id = inputSrc.Doctor_Id
|
||||
}
|
||||
|
||||
func setDataUpdate(src ir.UpdateDto, dst *ir.InternalReference) *ir.InternalReference {
|
||||
return &ir.InternalReference{
|
||||
Main: dst.Main,
|
||||
Encounter_Id: src.Encounter_Id,
|
||||
Unit_Id: src.Unit_Id,
|
||||
Doctor_Id: src.Doctor_Id,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,10 +81,8 @@ func ReadDetailData(input eir.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (
|
||||
tx = dg.I
|
||||
}
|
||||
|
||||
preload := "encounter,unit,doctor"
|
||||
|
||||
if err := tx.
|
||||
Scopes(gh.Preload(preload)).
|
||||
Scopes(gh.Preload(input.Includes)).
|
||||
First(&data, input.Id).
|
||||
Error; err != nil {
|
||||
|
||||
@@ -99,7 +97,8 @@ func ReadDetailData(input eir.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (
|
||||
|
||||
func UpdateData(input eir.UpdateDto, data *eir.InternalReference, event *pl.Event, dbx ...*gorm.DB) error {
|
||||
pl.SetLogInfo(event, data, "started", "DBUpdate")
|
||||
data = setDataUpdate(input, data)
|
||||
setData(&input, data)
|
||||
//data = setDataUpdate(input, data)
|
||||
|
||||
var tx *gorm.DB
|
||||
if len(dbx) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user