unit, unit-position,installation-position removes ids

This commit is contained in:
dpurbosakti
2025-11-06 15:48:32 +07:00
parent 42b1b48e36
commit 6ed038eb54
21 changed files with 121 additions and 114 deletions
@@ -7,7 +7,6 @@ import (
type Basic struct { type Basic struct {
ecore.SmallMain // adjust this according to the needs ecore.SmallMain // adjust this according to the needs
Installation_Id *uint16 `json:"installation_id" gorm:"not null"`
Installation_Code *string `json:"installation_code" gorm:"size:10"` Installation_Code *string `json:"installation_code" gorm:"size:10"`
Code string `json:"code" gorm:"unique;size:10;not null"` Code string `json:"code" gorm:"unique;size:10;not null"`
Name string `json:"name" gorm:"size:30;not null"` Name string `json:"name" gorm:"size:30;not null"`
@@ -7,11 +7,11 @@ import (
) )
type CreateDto struct { type CreateDto struct {
Installation_Id *uint16 `json:"installation_id" validate:"required"` Installation_Code *string `json:"installation_code" validate:"required"`
Code string `json:"code" validate:"maxLength=10;required"` Code string `json:"code" validate:"maxLength=10;required"`
Name string `json:"name" validate:"maxLength=30;required"` Name string `json:"name" validate:"maxLength=30;required"`
HeadStatus bool `json:"headStatus"` HeadStatus bool `json:"headStatus"`
Employee_Id *uint `json:"employee_id"` Employee_Id *uint `json:"employee_id"`
} }
type ReadListDto struct { type ReadListDto struct {
@@ -22,26 +22,27 @@ type ReadListDto struct {
} }
type FilterDto struct { type FilterDto struct {
Installation_Id *uint16 `json:"installation-id"` Installation_Code *string `json:"installation-code"`
Code string `json:"code"` Code string `json:"code"`
Name string `json:"name"` Name string `json:"name"`
HeadStatus *bool `json:"head-status"` HeadStatus *bool `json:"head-status"`
Employee_Id *uint `json:"employee-id"` Employee_Id *uint `json:"employee-id"`
Search string `json:"search" gormhelper:"searchColumns=Code,Name"` Search string `json:"search" gormhelper:"searchColumns=Code,Name"`
} }
type ReadDetailDto struct { type ReadDetailDto struct {
Id uint16 `json:"id"` Id *uint16 `json:"id"`
Code *string `json:"code"` Code *string `json:"code"`
} }
type UpdateDto struct { type UpdateDto struct {
Id uint16 `json:"id"` Id *uint16 `json:"id"`
CreateDto CreateDto
} }
type DeleteDto struct { type DeleteDto struct {
Id uint16 `json:"id"` Id *uint16 `json:"id"`
Code *string `json:"code"`
} }
type MetaDto struct { type MetaDto struct {
@@ -52,24 +53,24 @@ type MetaDto struct {
type ResponseDto struct { type ResponseDto struct {
ecore.SmallMain ecore.SmallMain
Installation_Id *uint16 `json:"installation_id"` Installation_Code *string `json:"installation_code"`
Installation *ei.Installation `json:"installation,omitempty"` Installation *ei.Installation `json:"installation,omitempty"`
Code string `json:"code"` Code string `json:"code"`
Name string `json:"name"` Name string `json:"name"`
HeadStatus bool `json:"headStatus"` HeadStatus bool `json:"headStatus"`
Employee_Id *uint `json:"employee_id"` Employee_Id *uint `json:"employee_id"`
Employee *ee.Employee `json:"employee,omitempty"` Employee *ee.Employee `json:"employee,omitempty"`
} }
func (d InstallationPosition) ToResponse() ResponseDto { func (d InstallationPosition) ToResponse() ResponseDto {
resp := ResponseDto{ resp := ResponseDto{
Installation_Id: d.Installation_Id, Installation_Code: d.Installation_Code,
Installation: d.Installation, Installation: d.Installation,
Code: d.Code, Code: d.Code,
Name: d.Name, Name: d.Name,
HeadStatus: d.HeadStatus, HeadStatus: d.HeadStatus,
Employee_Id: d.Employee_Id, Employee_Id: d.Employee_Id,
Employee: d.Employee, Employee: d.Employee,
} }
resp.SmallMain = d.SmallMain resp.SmallMain = d.SmallMain
return resp return resp
@@ -7,5 +7,5 @@ import (
type InstallationPosition struct { type InstallationPosition struct {
eib.Basic // adjust this according to the needs eib.Basic // adjust this according to the needs
Installation *ei.Installation `json:"installation,omitempty" gorm:"foreignKey:Installation_Id;references:Id"` Installation *ei.Installation `json:"installation,omitempty" gorm:"foreignKey:Installation_Code;references:Code"`
} }
@@ -11,5 +11,5 @@ type Installation struct {
Code string `json:"code" gorm:"unique;size:10"` Code string `json:"code" gorm:"unique;size:10"`
Name string `json:"name" gorm:"size:50"` Name string `json:"name" gorm:"size:50"`
EncounterClass_Code ere.EncounterClassCode `json:"encounterClass_code" gorm:"size:10"` EncounterClass_Code ere.EncounterClassCode `json:"encounterClass_code" gorm:"size:10"`
InstallationPositions []eipb.Basic `json:"installationPositions,omitempty" gorm:"foreignKey:Installation_Id;references:Id"` InstallationPositions []eipb.Basic `json:"installationPositions,omitempty" gorm:"foreignKey:Installation_Code;references:Code"`
} }
@@ -7,7 +7,6 @@ import (
type Basic struct { type Basic struct {
ecore.SmallMain // adjust this according to the needs ecore.SmallMain // adjust this according to the needs
Unit_Id *uint16 `json:"unit_id" gorm:"not null"`
Unit_Code *string `json:"unit_code" gorm:"size:10"` Unit_Code *string `json:"unit_code" gorm:"size:10"`
Code string `json:"code" gorm:"unique;size:10;not null"` Code string `json:"code" gorm:"unique;size:10;not null"`
Name string `json:"name" gorm:"size:30;not null"` Name string `json:"name" gorm:"size:30;not null"`
@@ -7,7 +7,7 @@ import (
) )
type CreateDto struct { type CreateDto struct {
Unit_Id *uint16 `json:"unit_id" validate:"required"` Unit_Code *string `json:"unit_code" validate:"required"`
Code string `json:"code" validate:"maxLength=10;required"` Code string `json:"code" validate:"maxLength=10;required"`
Name string `json:"name" validate:"maxLength=30;required"` Name string `json:"name" validate:"maxLength=30;required"`
HeadStatus bool `json:"headStatus"` HeadStatus bool `json:"headStatus"`
@@ -22,7 +22,7 @@ type ReadListDto struct {
} }
type FilterDto struct { type FilterDto struct {
Unit_Id *uint16 `json:"unit-id"` Unit_Code *string `json:"unit-code"`
Code string `json:"code"` Code string `json:"code"`
Name string `json:"name"` Name string `json:"name"`
HeadStatus *bool `json:"head-status"` HeadStatus *bool `json:"head-status"`
@@ -31,17 +31,18 @@ type FilterDto struct {
} }
type ReadDetailDto struct { type ReadDetailDto struct {
Id uint16 `json:"id"` Id *uint16 `json:"id"`
Code *string `json:"code"` Code *string `json:"code"`
} }
type UpdateDto struct { type UpdateDto struct {
Id uint16 `json:"id"` Id *uint16 `json:"id"`
CreateDto CreateDto
} }
type DeleteDto struct { type DeleteDto struct {
Id uint16 `json:"id"` Id *uint16 `json:"id"`
Code *string `json:"code"`
} }
type MetaDto struct { type MetaDto struct {
@@ -52,7 +53,7 @@ type MetaDto struct {
type ResponseDto struct { type ResponseDto struct {
ecore.SmallMain ecore.SmallMain
Unit_Id *uint16 `json:"unit_id"` Unit_Code *string `json:"unit_code"`
Unit *eu.Unit `json:"unit,omitempty"` Unit *eu.Unit `json:"unit,omitempty"`
Code string `json:"code"` Code string `json:"code"`
Name string `json:"name"` Name string `json:"name"`
@@ -63,7 +64,7 @@ type ResponseDto struct {
func (d UnitPosition) ToResponse() ResponseDto { func (d UnitPosition) ToResponse() ResponseDto {
resp := ResponseDto{ resp := ResponseDto{
Unit_Id: d.Unit_Id, Unit_Code: d.Unit_Code,
Unit: d.Unit, Unit: d.Unit,
Code: d.Code, Code: d.Code,
Name: d.Name, Name: d.Name,
+23 -22
View File
@@ -7,9 +7,9 @@ import (
) )
type CreateDto struct { type CreateDto struct {
Installation_Id *uint16 `json:"installation_id"` Installation_Code *string `json:"installation_code"`
Code string `json:"code" validate:"maxLength=10"` Code string `json:"code" validate:"maxLength=10"`
Name string `json:"name" validate:"maxLength=50"` Name string `json:"name" validate:"maxLength=50"`
} }
type ReadListDto struct { type ReadListDto struct {
@@ -20,26 +20,27 @@ type ReadListDto struct {
} }
type FilterDto struct { type FilterDto struct {
Installation_Id *uint16 `json:"installation-id"` Installation_Code *string `json:"installation-code"`
Code string `json:"code"` Code string `json:"code"`
Name string `json:"name"` Name string `json:"name"`
Search string `json:"search" gormhelper:"searchColumns=Code,Name"` Search string `json:"search" gormhelper:"searchColumns=Code,Name"`
} }
type ReadDetailDto struct { type ReadDetailDto struct {
Id uint16 `json:"id"` Id *uint16 `json:"id"`
Installation_Id *uint16 `json:"installation_id"` Installation_Code *string `json:"installation_code"`
Code *string `json:"code"` Code *string `json:"code"`
Includes string `json:"includes"` Includes string `json:"includes"`
} }
type UpdateDto struct { type UpdateDto struct {
Id uint16 `json:"id"` Id *uint16 `json:"id"`
CreateDto CreateDto
} }
type DeleteDto struct { type DeleteDto struct {
Id uint16 `json:"id"` Id *uint16 `json:"id"`
Code *string `json:"code"`
} }
type MetaDto struct { type MetaDto struct {
@@ -50,19 +51,19 @@ type MetaDto struct {
type ResponseDto struct { type ResponseDto struct {
ecore.SmallMain ecore.SmallMain
Installation_Id *uint16 `json:"installation_id"` Installation_Code *string `json:"installation_code"`
Installation *ei.Installation `json:"installation,omitempty"` Installation *ei.Installation `json:"installation,omitempty"`
Code string `json:"code"` Code string `json:"code"`
Name string `json:"name"` Name string `json:"name"`
UnitPositions []eipb.Basic `json:"unitPositions,omitempty"` UnitPositions []eipb.Basic `json:"unitPositions,omitempty"`
} }
func (d Unit) ToResponse() ResponseDto { func (d Unit) ToResponse() ResponseDto {
resp := ResponseDto{ resp := ResponseDto{
Installation_Id: d.Installation_Id, Installation_Code: d.Installation_Code,
Code: d.Code, Code: d.Code,
Name: d.Name, Name: d.Name,
UnitPositions: d.UnitPositions, UnitPositions: d.UnitPositions,
} }
resp.SmallMain = d.SmallMain resp.SmallMain = d.SmallMain
if d.Installation != nil { if d.Installation != nil {
+2 -3
View File
@@ -9,11 +9,10 @@ import (
type Unit struct { type Unit struct {
ecore.SmallMain // adjust this according to the needs ecore.SmallMain // adjust this according to the needs
Installation_Id *uint16 `json:"installation_id"`
Installation_Code *string `json:"installation_code" gorm:"size:10"` Installation_Code *string `json:"installation_code" gorm:"size:10"`
Installation *ei.Installation `json:"installation" gorm:"foreignKey:Installation_Id"` Installation *ei.Installation `json:"installation" gorm:"foreignKey:Installation_Code;references:Code"`
Code string `json:"code" gorm:"unique;size:10"` Code string `json:"code" gorm:"unique;size:10"`
Name string `json:"name" gorm:"size:50"` Name string `json:"name" gorm:"size:50"`
Type_Code *ero.UnitTypeCode `json:"type_code"` Type_Code *ero.UnitTypeCode `json:"type_code"`
UnitPositions []eub.Basic `json:"unitPositions,omitempty" gorm:"foreignKey:Unit_Id;references:Id"` UnitPositions []eub.Basic `json:"unitPositions,omitempty" gorm:"foreignKey:Unit_Code;references:Code"`
} }
@@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) {
} }
func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id")) code := rw.ValidateString(w, "code", r.PathValue("code"))
if id <= 0 { if code == "" {
return return
} }
dto := e.ReadDetailDto{} dto := e.ReadDetailDto{}
dto.Id = uint16(id) dto.Code = &code
res, err := u.ReadDetail(dto) res, err := u.ReadDetail(dto)
rw.DataResponse(w, res, err) rw.DataResponse(w, res, err)
} }
func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id")) code := rw.ValidateString(w, "code", r.PathValue("code"))
if id <= 0 { if code == "" {
return return
} }
@@ -53,19 +53,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
return return
} }
dto.Id = uint16(id) dto.Code = code
res, err := u.Update(dto) res, err := u.Update(dto)
rw.DataResponse(w, res, err) rw.DataResponse(w, res, err)
} }
func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id")) code := rw.ValidateString(w, "code", r.PathValue("code"))
if id <= 0 { if code == "" {
return return
} }
dto := e.DeleteDto{} dto := e.DeleteDto{}
dto.Id = uint16(id) dto.Code = &code
res, err := u.Delete(dto) res, err := u.Delete(dto)
rw.DataResponse(w, res, err) rw.DataResponse(w, res, err)
} }
@@ -292,8 +292,14 @@ func SetRoutes() http.Handler {
/******************** sources ********************/ /******************** sources ********************/
hc.RegCrudByCode(r, "/v1/division", division.O) hc.RegCrudByCode(r, "/v1/division", division.O)
hc.RegCrudByCode(r, "/v1/division-position", divisionposition.O) hc.RegCrudByCode(r, "/v1/division-position", divisionposition.O)
hc.RegCrud(r, "/v1/installation", installation.O) hc.RegCrudByCode(r, "/v1/installation", installation.O)
hc.RegCrud(r, "/v1/unit", unit.O) hc.RegCrudByCode(r, "/v1/unit", unit.O)
hc.RegCrudByCode(r, "/v1/installation-position", installationposition.O)
hc.RegCrudByCode(r, "/v1/unit-position", unitposition.O)
hc.RegCrudByCode(r, "/v1/specialist", specialist.O)
hc.RegCrudByCode(r, "/v1/subspecialist", subspecialist.O)
hc.RegCrudByCode(r, "/v1/specialist-position", specialistposition.O)
hc.RegCrudByCode(r, "/v1/subspecialist-position", subspecialistposition.O)
hc.RegCrud(r, "/v1/pharmacy-company", pharmacycompany.O) hc.RegCrud(r, "/v1/pharmacy-company", pharmacycompany.O)
hc.RegCrud(r, "/v1/diagnose-src", diagnosesrc.O) hc.RegCrud(r, "/v1/diagnose-src", diagnosesrc.O)
hc.RegCrud(r, "/v1/procedure-src", proceduresrc.O) hc.RegCrud(r, "/v1/procedure-src", proceduresrc.O)
@@ -318,12 +324,6 @@ func SetRoutes() http.Handler {
hc.RegCrud(r, "/v1/vehicle", vehicle.O) hc.RegCrud(r, "/v1/vehicle", vehicle.O)
hc.RegCrud(r, "/v1/vehicle-hist", vehiclehist.O) hc.RegCrud(r, "/v1/vehicle-hist", vehiclehist.O)
hc.RegCrud(r, "/v1/edu-assessment", eduassesment.O) hc.RegCrud(r, "/v1/edu-assessment", eduassesment.O)
hc.RegCrud(r, "/v1/installation-position", installationposition.O)
hc.RegCrud(r, "/v1/unit-position", unitposition.O)
hc.RegCrudByCode(r, "/v1/specialist", specialist.O)
hc.RegCrudByCode(r, "/v1/subspecialist", subspecialist.O)
hc.RegCrudByCode(r, "/v1/specialist-position", specialistposition.O)
hc.RegCrudByCode(r, "/v1/subspecialist-position", subspecialistposition.O)
hc.RegCrud(r, "/v1/village", village.O) hc.RegCrud(r, "/v1/village", village.O)
hc.RegCrud(r, "/v1/district", district.O) hc.RegCrud(r, "/v1/district", district.O)
@@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) {
} }
func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id")) code := rw.ValidateString(w, "code", r.PathValue("code"))
if id <= 0 { if code == "" {
return return
} }
dto := e.ReadDetailDto{} dto := e.ReadDetailDto{}
dto.Id = uint16(id) dto.Code = &code
res, err := u.ReadDetail(dto) res, err := u.ReadDetail(dto)
rw.DataResponse(w, res, err) rw.DataResponse(w, res, err)
} }
func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id")) code := rw.ValidateString(w, "code", r.PathValue("code"))
if id <= 0 { if code == "" {
return return
} }
@@ -53,19 +53,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
return return
} }
dto.Id = uint16(id) dto.Code = code
res, err := u.Update(dto) res, err := u.Update(dto)
rw.DataResponse(w, res, err) rw.DataResponse(w, res, err)
} }
func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id")) code := rw.ValidateString(w, "code", r.PathValue("code"))
if id <= 0 { if code == "" {
return return
} }
dto := e.DeleteDto{} dto := e.DeleteDto{}
dto.Id = uint16(id) dto.Code = &code
res, err := u.Delete(dto) res, err := u.Delete(dto)
rw.DataResponse(w, res, err) rw.DataResponse(w, res, err)
} }
@@ -33,21 +33,21 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) {
} }
func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id")) code := rw.ValidateString(w, "code", r.PathValue("code"))
if id <= 0 { if code == "" {
return return
} }
dto := e.ReadDetailDto{} dto := e.ReadDetailDto{}
sf.UrlQueryParam(&dto, *r.URL) sf.UrlQueryParam(&dto, *r.URL)
dto.Id = uint16(id) dto.Code = &code
res, err := u.ReadDetail(dto) res, err := u.ReadDetail(dto)
rw.DataResponse(w, res, err) rw.DataResponse(w, res, err)
} }
func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id")) code := rw.ValidateString(w, "code", r.PathValue("code"))
if id <= 0 { if code == "" {
return return
} }
@@ -55,19 +55,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) {
if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res {
return return
} }
dto.Id = uint16(id) dto.Code = code
res, err := u.Update(dto) res, err := u.Update(dto)
rw.DataResponse(w, res, err) rw.DataResponse(w, res, err)
} }
func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) {
id := rw.ValidateInt(w, "id", r.PathValue("id")) code := rw.ValidateString(w, "code", r.PathValue("code"))
if id <= 0 { if code == "" {
return return
} }
dto := e.DeleteDto{} dto := e.DeleteDto{}
dto.Id = uint16(id) dto.Code = &code
res, err := u.Delete(dto) res, err := u.Delete(dto)
rw.DataResponse(w, res, err) rw.DataResponse(w, res, err)
} }
@@ -175,7 +175,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) {
} }
func Update(input e.UpdateDto) (*d.Data, error) { func Update(input e.UpdateDto) (*d.Data, error) {
rdDto := e.ReadDetailDto{Id: input.Id} rdDto := e.ReadDetailDto{Code: &input.Code}
var data *e.InstallationPosition var data *e.InstallationPosition
var err error var err error
@@ -235,7 +235,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
} }
func Delete(input e.DeleteDto) (*d.Data, error) { func Delete(input e.DeleteDto) (*d.Data, error) {
rdDto := e.ReadDetailDto{Id: input.Id} rdDto := e.ReadDetailDto{Code: input.Code}
var data *e.InstallationPosition var data *e.InstallationPosition
var err error var err error
@@ -290,7 +290,7 @@ func Delete(input e.DeleteDto) (*d.Data, error) {
func validateForeignKey(input e.CreateDto) error { func validateForeignKey(input e.CreateDto) error {
// validate installation_id // validate installation_id
if _, err := ui.ReadDetail(ei.ReadDetailDto{Id: *input.Installation_Id}); err != nil { if _, err := ui.ReadDetail(ei.ReadDetailDto{Code: input.Installation_Code}); err != nil {
return err return err
} }
@@ -17,7 +17,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.InstallationPositio
inputSrc = &inputTemp.CreateDto inputSrc = &inputTemp.CreateDto
} }
data.Installation_Id = inputSrc.Installation_Id data.Installation_Code = inputSrc.Installation_Code
data.Code = inputSrc.Code data.Code = inputSrc.Code
data.Name = inputSrc.Name data.Name = inputSrc.Name
data.HeadStatus = inputSrc.HeadStatus data.HeadStatus = inputSrc.HeadStatus
@@ -83,10 +83,10 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e
} }
switch { switch {
case input.Id != 0: case input.Id != nil:
getData = tx.First(&data, input.Id) getData = tx.First(&data, input.Id)
case input.Code != nil && *input.Code != "": case input.Code != nil && *input.Code != "":
getData = tx.Where("code = ?", *input.Code).First(&data) getData = tx.Where("\"Code\" = ?", *input.Code).First(&data)
default: default:
event.Status = "failed" event.Status = "failed"
event.ErrInfo = pl.ErrorInfo{ event.ErrInfo = pl.ErrorInfo{
@@ -175,7 +175,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) {
} }
func Update(input e.UpdateDto) (*d.Data, error) { func Update(input e.UpdateDto) (*d.Data, error) {
rdDto := e.ReadDetailDto{Id: input.Id} rdDto := e.ReadDetailDto{Code: &input.Code}
var data *e.UnitPosition var data *e.UnitPosition
var err error var err error
@@ -235,7 +235,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
} }
func Delete(input e.DeleteDto) (*d.Data, error) { func Delete(input e.DeleteDto) (*d.Data, error) {
rdDto := e.ReadDetailDto{Id: input.Id} rdDto := e.ReadDetailDto{Code: input.Code}
var data *e.UnitPosition var data *e.UnitPosition
var err error var err error
@@ -290,7 +290,7 @@ func Delete(input e.DeleteDto) (*d.Data, error) {
func validateForeignKey(input e.CreateDto) error { func validateForeignKey(input e.CreateDto) error {
// validate installation_id // validate installation_id
if _, err := uu.ReadDetail(eu.ReadDetailDto{Id: *input.Unit_Id}); err != nil { if _, err := uu.ReadDetail(eu.ReadDetailDto{Code: &input.Code}); err != nil {
return err return err
} }
@@ -17,7 +17,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.UnitPosition) {
inputSrc = &inputTemp.CreateDto inputSrc = &inputTemp.CreateDto
} }
data.Unit_Id = inputSrc.Unit_Id data.Unit_Code = inputSrc.Unit_Code
data.Code = inputSrc.Code data.Code = inputSrc.Code
data.Name = inputSrc.Name data.Name = inputSrc.Name
data.HeadStatus = inputSrc.HeadStatus data.HeadStatus = inputSrc.HeadStatus
@@ -83,7 +83,7 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e
} }
switch { switch {
case input.Id != 0: case input.Id != nil:
getData = tx.First(&data, input.Id) getData = tx.First(&data, input.Id)
case input.Code != nil && *input.Code != "": case input.Code != nil && *input.Code != "":
getData = tx.Where("code = ?", *input.Code).First(&data) getData = tx.Where("code = ?", *input.Code).First(&data)
+2 -2
View File
@@ -166,7 +166,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) {
} }
func Update(input e.UpdateDto) (*d.Data, error) { func Update(input e.UpdateDto) (*d.Data, error) {
rdDto := e.ReadDetailDto{Id: input.Id} rdDto := e.ReadDetailDto{Code: &input.Code}
var data *e.Unit var data *e.Unit
var err error var err error
@@ -222,7 +222,7 @@ func Update(input e.UpdateDto) (*d.Data, error) {
} }
func Delete(input e.DeleteDto) (*d.Data, error) { func Delete(input e.DeleteDto) (*d.Data, error) {
rdDto := e.ReadDetailDto{Id: input.Id} rdDto := e.ReadDetailDto{Code: input.Code}
var data *e.Unit var data *e.Unit
var err error var err error
@@ -17,7 +17,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Unit) {
inputSrc = &inputTemp.CreateDto inputSrc = &inputTemp.CreateDto
} }
data.Installation_Id = inputSrc.Installation_Id data.Installation_Code = inputSrc.Installation_Code
data.Code = inputSrc.Code data.Code = inputSrc.Code
data.Name = inputSrc.Name data.Name = inputSrc.Name
} }
+8 -1
View File
@@ -81,9 +81,16 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e
tx = dg.I tx = dg.I
} }
if input.Code != nil {
tx = tx.Where("\"Code\" = ?", *input.Code)
}
if input.Id != nil {
tx = tx.Where("\"Id\" = ?", input.Id)
}
if err := tx. if err := tx.
Scopes(gh.Preload(input.Includes)). Scopes(gh.Preload(input.Includes)).
First(&data, input.Id).Error; err != nil { First(&data).Error; err != nil {
if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil { if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil {
return nil, processedErr return nil, processedErr
} }