From 6ed038eb543ebd8dffae80c314e4fa5311ae6382 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Thu, 6 Nov 2025 15:48:32 +0700 Subject: [PATCH] unit, unit-position,installation-position removes ids --- .../installation-position/base/entity.go | 1 - .../installation-position/dto.go | 57 ++++++++++--------- .../installation-position/entity.go | 2 +- .../main-entities/installation/entity.go | 2 +- .../unit-position/base/entity.go | 1 - .../domain/main-entities/unit-position/dto.go | 15 ++--- internal/domain/main-entities/unit/dto.go | 45 ++++++++------- internal/domain/main-entities/unit/entity.go | 5 +- .../installation-position/handler.go | 18 +++--- .../interface/main-handler/main-handler.go | 16 +++--- .../main-handler/unit-position/handler.go | 18 +++--- .../interface/main-handler/unit/handler.go | 18 +++--- .../installation-position/case.go | 6 +- .../installation-position/helper.go | 2 +- .../installation-position/lib.go | 4 +- .../main-use-case/unit-position/case.go | 6 +- .../main-use-case/unit-position/helper.go | 2 +- .../main-use-case/unit-position/lib.go | 2 +- internal/use-case/main-use-case/unit/case.go | 4 +- .../use-case/main-use-case/unit/helper.go | 2 +- internal/use-case/main-use-case/unit/lib.go | 9 ++- 21 files changed, 121 insertions(+), 114 deletions(-) diff --git a/internal/domain/main-entities/installation-position/base/entity.go b/internal/domain/main-entities/installation-position/base/entity.go index e5e8c589..3ebc171b 100644 --- a/internal/domain/main-entities/installation-position/base/entity.go +++ b/internal/domain/main-entities/installation-position/base/entity.go @@ -7,7 +7,6 @@ import ( type Basic struct { 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"` Code string `json:"code" gorm:"unique;size:10;not null"` Name string `json:"name" gorm:"size:30;not null"` diff --git a/internal/domain/main-entities/installation-position/dto.go b/internal/domain/main-entities/installation-position/dto.go index aada7443..12e13afc 100644 --- a/internal/domain/main-entities/installation-position/dto.go +++ b/internal/domain/main-entities/installation-position/dto.go @@ -7,11 +7,11 @@ import ( ) type CreateDto struct { - Installation_Id *uint16 `json:"installation_id" validate:"required"` - Code string `json:"code" validate:"maxLength=10;required"` - Name string `json:"name" validate:"maxLength=30;required"` - HeadStatus bool `json:"headStatus"` - Employee_Id *uint `json:"employee_id"` + Installation_Code *string `json:"installation_code" validate:"required"` + Code string `json:"code" validate:"maxLength=10;required"` + Name string `json:"name" validate:"maxLength=30;required"` + HeadStatus bool `json:"headStatus"` + Employee_Id *uint `json:"employee_id"` } type ReadListDto struct { @@ -22,26 +22,27 @@ type ReadListDto struct { } type FilterDto struct { - Installation_Id *uint16 `json:"installation-id"` - Code string `json:"code"` - Name string `json:"name"` - HeadStatus *bool `json:"head-status"` - Employee_Id *uint `json:"employee-id"` - Search string `json:"search" gormhelper:"searchColumns=Code,Name"` + Installation_Code *string `json:"installation-code"` + Code string `json:"code"` + Name string `json:"name"` + HeadStatus *bool `json:"head-status"` + Employee_Id *uint `json:"employee-id"` + Search string `json:"search" gormhelper:"searchColumns=Code,Name"` } type ReadDetailDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` Code *string `json:"code"` } type UpdateDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` CreateDto } type DeleteDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` + Code *string `json:"code"` } type MetaDto struct { @@ -52,24 +53,24 @@ type MetaDto struct { type ResponseDto struct { ecore.SmallMain - Installation_Id *uint16 `json:"installation_id"` - Installation *ei.Installation `json:"installation,omitempty"` - Code string `json:"code"` - Name string `json:"name"` - HeadStatus bool `json:"headStatus"` - Employee_Id *uint `json:"employee_id"` - Employee *ee.Employee `json:"employee,omitempty"` + Installation_Code *string `json:"installation_code"` + Installation *ei.Installation `json:"installation,omitempty"` + Code string `json:"code"` + Name string `json:"name"` + HeadStatus bool `json:"headStatus"` + Employee_Id *uint `json:"employee_id"` + Employee *ee.Employee `json:"employee,omitempty"` } func (d InstallationPosition) ToResponse() ResponseDto { resp := ResponseDto{ - Installation_Id: d.Installation_Id, - Installation: d.Installation, - Code: d.Code, - Name: d.Name, - HeadStatus: d.HeadStatus, - Employee_Id: d.Employee_Id, - Employee: d.Employee, + Installation_Code: d.Installation_Code, + Installation: d.Installation, + Code: d.Code, + Name: d.Name, + HeadStatus: d.HeadStatus, + Employee_Id: d.Employee_Id, + Employee: d.Employee, } resp.SmallMain = d.SmallMain return resp diff --git a/internal/domain/main-entities/installation-position/entity.go b/internal/domain/main-entities/installation-position/entity.go index 48e95ac5..ba8ddece 100644 --- a/internal/domain/main-entities/installation-position/entity.go +++ b/internal/domain/main-entities/installation-position/entity.go @@ -7,5 +7,5 @@ import ( type InstallationPosition struct { 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"` } diff --git a/internal/domain/main-entities/installation/entity.go b/internal/domain/main-entities/installation/entity.go index dea63a45..5cc82430 100644 --- a/internal/domain/main-entities/installation/entity.go +++ b/internal/domain/main-entities/installation/entity.go @@ -11,5 +11,5 @@ type Installation struct { Code string `json:"code" gorm:"unique;size:10"` Name string `json:"name" gorm:"size:50"` 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"` } diff --git a/internal/domain/main-entities/unit-position/base/entity.go b/internal/domain/main-entities/unit-position/base/entity.go index e7376e51..eb046dfc 100644 --- a/internal/domain/main-entities/unit-position/base/entity.go +++ b/internal/domain/main-entities/unit-position/base/entity.go @@ -7,7 +7,6 @@ import ( type Basic struct { 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"` Code string `json:"code" gorm:"unique;size:10;not null"` Name string `json:"name" gorm:"size:30;not null"` diff --git a/internal/domain/main-entities/unit-position/dto.go b/internal/domain/main-entities/unit-position/dto.go index cc52c493..856cec77 100644 --- a/internal/domain/main-entities/unit-position/dto.go +++ b/internal/domain/main-entities/unit-position/dto.go @@ -7,7 +7,7 @@ import ( ) 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"` Name string `json:"name" validate:"maxLength=30;required"` HeadStatus bool `json:"headStatus"` @@ -22,7 +22,7 @@ type ReadListDto struct { } type FilterDto struct { - Unit_Id *uint16 `json:"unit-id"` + Unit_Code *string `json:"unit-code"` Code string `json:"code"` Name string `json:"name"` HeadStatus *bool `json:"head-status"` @@ -31,17 +31,18 @@ type FilterDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` Code *string `json:"code"` } type UpdateDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` CreateDto } type DeleteDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` + Code *string `json:"code"` } type MetaDto struct { @@ -52,7 +53,7 @@ type MetaDto struct { type ResponseDto struct { ecore.SmallMain - Unit_Id *uint16 `json:"unit_id"` + Unit_Code *string `json:"unit_code"` Unit *eu.Unit `json:"unit,omitempty"` Code string `json:"code"` Name string `json:"name"` @@ -63,7 +64,7 @@ type ResponseDto struct { func (d UnitPosition) ToResponse() ResponseDto { resp := ResponseDto{ - Unit_Id: d.Unit_Id, + Unit_Code: d.Unit_Code, Unit: d.Unit, Code: d.Code, Name: d.Name, diff --git a/internal/domain/main-entities/unit/dto.go b/internal/domain/main-entities/unit/dto.go index e47afed9..f272ecec 100644 --- a/internal/domain/main-entities/unit/dto.go +++ b/internal/domain/main-entities/unit/dto.go @@ -7,9 +7,9 @@ import ( ) type CreateDto struct { - Installation_Id *uint16 `json:"installation_id"` - Code string `json:"code" validate:"maxLength=10"` - Name string `json:"name" validate:"maxLength=50"` + Installation_Code *string `json:"installation_code"` + Code string `json:"code" validate:"maxLength=10"` + Name string `json:"name" validate:"maxLength=50"` } type ReadListDto struct { @@ -20,26 +20,27 @@ type ReadListDto struct { } type FilterDto struct { - Installation_Id *uint16 `json:"installation-id"` - Code string `json:"code"` - Name string `json:"name"` - Search string `json:"search" gormhelper:"searchColumns=Code,Name"` + Installation_Code *string `json:"installation-code"` + Code string `json:"code"` + Name string `json:"name"` + Search string `json:"search" gormhelper:"searchColumns=Code,Name"` } type ReadDetailDto struct { - Id uint16 `json:"id"` - Installation_Id *uint16 `json:"installation_id"` - Code *string `json:"code"` - Includes string `json:"includes"` + Id *uint16 `json:"id"` + Installation_Code *string `json:"installation_code"` + Code *string `json:"code"` + Includes string `json:"includes"` } type UpdateDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` CreateDto } type DeleteDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` + Code *string `json:"code"` } type MetaDto struct { @@ -50,19 +51,19 @@ type MetaDto struct { type ResponseDto struct { ecore.SmallMain - Installation_Id *uint16 `json:"installation_id"` - Installation *ei.Installation `json:"installation,omitempty"` - Code string `json:"code"` - Name string `json:"name"` - UnitPositions []eipb.Basic `json:"unitPositions,omitempty"` + Installation_Code *string `json:"installation_code"` + Installation *ei.Installation `json:"installation,omitempty"` + Code string `json:"code"` + Name string `json:"name"` + UnitPositions []eipb.Basic `json:"unitPositions,omitempty"` } func (d Unit) ToResponse() ResponseDto { resp := ResponseDto{ - Installation_Id: d.Installation_Id, - Code: d.Code, - Name: d.Name, - UnitPositions: d.UnitPositions, + Installation_Code: d.Installation_Code, + Code: d.Code, + Name: d.Name, + UnitPositions: d.UnitPositions, } resp.SmallMain = d.SmallMain if d.Installation != nil { diff --git a/internal/domain/main-entities/unit/entity.go b/internal/domain/main-entities/unit/entity.go index 254bc163..97db9885 100644 --- a/internal/domain/main-entities/unit/entity.go +++ b/internal/domain/main-entities/unit/entity.go @@ -9,11 +9,10 @@ import ( type Unit struct { ecore.SmallMain // adjust this according to the needs - Installation_Id *uint16 `json:"installation_id"` 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"` Name string `json:"name" gorm:"size:50"` 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"` } diff --git a/internal/interface/main-handler/installation-position/handler.go b/internal/interface/main-handler/installation-position/handler.go index 59f35340..57a439be 100644 --- a/internal/interface/main-handler/installation-position/handler.go +++ b/internal/interface/main-handler/installation-position/handler.go @@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.ReadDetailDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.ReadDetail(dto) rw.DataResponse(w, res, err) } func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } @@ -53,19 +53,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - dto.Id = uint16(id) + dto.Code = code res, err := u.Update(dto) rw.DataResponse(w, res, err) } func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.DeleteDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/interface/main-handler/main-handler.go b/internal/interface/main-handler/main-handler.go index 071e7e24..925f9dc6 100644 --- a/internal/interface/main-handler/main-handler.go +++ b/internal/interface/main-handler/main-handler.go @@ -292,8 +292,14 @@ func SetRoutes() http.Handler { /******************** sources ********************/ hc.RegCrudByCode(r, "/v1/division", division.O) hc.RegCrudByCode(r, "/v1/division-position", divisionposition.O) - hc.RegCrud(r, "/v1/installation", installation.O) - hc.RegCrud(r, "/v1/unit", unit.O) + hc.RegCrudByCode(r, "/v1/installation", installation.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/diagnose-src", diagnosesrc.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-hist", vehiclehist.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/district", district.O) diff --git a/internal/interface/main-handler/unit-position/handler.go b/internal/interface/main-handler/unit-position/handler.go index 82b89465..7780e80d 100644 --- a/internal/interface/main-handler/unit-position/handler.go +++ b/internal/interface/main-handler/unit-position/handler.go @@ -33,19 +33,19 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.ReadDetailDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.ReadDetail(dto) rw.DataResponse(w, res, err) } func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } @@ -53,19 +53,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - dto.Id = uint16(id) + dto.Code = code res, err := u.Update(dto) rw.DataResponse(w, res, err) } func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.DeleteDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/interface/main-handler/unit/handler.go b/internal/interface/main-handler/unit/handler.go index a94ce74e..f31667a2 100644 --- a/internal/interface/main-handler/unit/handler.go +++ b/internal/interface/main-handler/unit/handler.go @@ -33,21 +33,21 @@ func (obj myBase) GetList(w http.ResponseWriter, r *http.Request) { } func (obj myBase) GetDetail(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.ReadDetailDto{} sf.UrlQueryParam(&dto, *r.URL) - dto.Id = uint16(id) + dto.Code = &code res, err := u.ReadDetail(dto) rw.DataResponse(w, res, err) } func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } @@ -55,19 +55,19 @@ func (obj myBase) Update(w http.ResponseWriter, r *http.Request) { if res := rw.ValidateStructByIOR(w, r.Body, &dto); !res { return } - dto.Id = uint16(id) + dto.Code = code res, err := u.Update(dto) rw.DataResponse(w, res, err) } func (obj myBase) Delete(w http.ResponseWriter, r *http.Request) { - id := rw.ValidateInt(w, "id", r.PathValue("id")) - if id <= 0 { + code := rw.ValidateString(w, "code", r.PathValue("code")) + if code == "" { return } dto := e.DeleteDto{} - dto.Id = uint16(id) + dto.Code = &code res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/use-case/main-use-case/installation-position/case.go b/internal/use-case/main-use-case/installation-position/case.go index f9458c0b..73e64630 100644 --- a/internal/use-case/main-use-case/installation-position/case.go +++ b/internal/use-case/main-use-case/installation-position/case.go @@ -175,7 +175,7 @@ func ReadDetail(input e.ReadDetailDto) (*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 err error @@ -235,7 +235,7 @@ func Update(input e.UpdateDto) (*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 err error @@ -290,7 +290,7 @@ func Delete(input e.DeleteDto) (*d.Data, error) { func validateForeignKey(input e.CreateDto) error { // 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 } diff --git a/internal/use-case/main-use-case/installation-position/helper.go b/internal/use-case/main-use-case/installation-position/helper.go index 640993c8..2d36d402 100644 --- a/internal/use-case/main-use-case/installation-position/helper.go +++ b/internal/use-case/main-use-case/installation-position/helper.go @@ -17,7 +17,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.InstallationPositio inputSrc = &inputTemp.CreateDto } - data.Installation_Id = inputSrc.Installation_Id + data.Installation_Code = inputSrc.Installation_Code data.Code = inputSrc.Code data.Name = inputSrc.Name data.HeadStatus = inputSrc.HeadStatus diff --git a/internal/use-case/main-use-case/installation-position/lib.go b/internal/use-case/main-use-case/installation-position/lib.go index bb33356f..d0cf72b3 100644 --- a/internal/use-case/main-use-case/installation-position/lib.go +++ b/internal/use-case/main-use-case/installation-position/lib.go @@ -83,10 +83,10 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e } switch { - case input.Id != 0: + case input.Id != nil: getData = tx.First(&data, input.Id) case input.Code != nil && *input.Code != "": - getData = tx.Where("code = ?", *input.Code).First(&data) + getData = tx.Where("\"Code\" = ?", *input.Code).First(&data) default: event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ diff --git a/internal/use-case/main-use-case/unit-position/case.go b/internal/use-case/main-use-case/unit-position/case.go index f3bd2840..47ea67cd 100644 --- a/internal/use-case/main-use-case/unit-position/case.go +++ b/internal/use-case/main-use-case/unit-position/case.go @@ -175,7 +175,7 @@ func ReadDetail(input e.ReadDetailDto) (*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 err error @@ -235,7 +235,7 @@ func Update(input e.UpdateDto) (*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 err error @@ -290,7 +290,7 @@ func Delete(input e.DeleteDto) (*d.Data, error) { func validateForeignKey(input e.CreateDto) error { // 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 } diff --git a/internal/use-case/main-use-case/unit-position/helper.go b/internal/use-case/main-use-case/unit-position/helper.go index c1db758d..827dfcc3 100644 --- a/internal/use-case/main-use-case/unit-position/helper.go +++ b/internal/use-case/main-use-case/unit-position/helper.go @@ -17,7 +17,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.UnitPosition) { inputSrc = &inputTemp.CreateDto } - data.Unit_Id = inputSrc.Unit_Id + data.Unit_Code = inputSrc.Unit_Code data.Code = inputSrc.Code data.Name = inputSrc.Name data.HeadStatus = inputSrc.HeadStatus diff --git a/internal/use-case/main-use-case/unit-position/lib.go b/internal/use-case/main-use-case/unit-position/lib.go index c58edd4e..d6f42936 100644 --- a/internal/use-case/main-use-case/unit-position/lib.go +++ b/internal/use-case/main-use-case/unit-position/lib.go @@ -83,7 +83,7 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e } switch { - case input.Id != 0: + case input.Id != nil: getData = tx.First(&data, input.Id) case input.Code != nil && *input.Code != "": getData = tx.Where("code = ?", *input.Code).First(&data) diff --git a/internal/use-case/main-use-case/unit/case.go b/internal/use-case/main-use-case/unit/case.go index e11dbd21..650c4511 100644 --- a/internal/use-case/main-use-case/unit/case.go +++ b/internal/use-case/main-use-case/unit/case.go @@ -166,7 +166,7 @@ func ReadDetail(input e.ReadDetailDto) (*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 err error @@ -222,7 +222,7 @@ func Update(input e.UpdateDto) (*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 err error diff --git a/internal/use-case/main-use-case/unit/helper.go b/internal/use-case/main-use-case/unit/helper.go index f7729ec9..8ee7f7e6 100644 --- a/internal/use-case/main-use-case/unit/helper.go +++ b/internal/use-case/main-use-case/unit/helper.go @@ -17,7 +17,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Unit) { inputSrc = &inputTemp.CreateDto } - data.Installation_Id = inputSrc.Installation_Id + data.Installation_Code = inputSrc.Installation_Code data.Code = inputSrc.Code data.Name = inputSrc.Name } diff --git a/internal/use-case/main-use-case/unit/lib.go b/internal/use-case/main-use-case/unit/lib.go index 1a3e5652..3ec4a10c 100644 --- a/internal/use-case/main-use-case/unit/lib.go +++ b/internal/use-case/main-use-case/unit/lib.go @@ -81,9 +81,16 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e 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. 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 { return nil, processedErr }