From 98d063b8c3c593edd1db52cab4c15d67679546fe Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Mon, 10 Nov 2025 17:06:10 +0700 Subject: [PATCH] remove ids from mcu related --- .../migrations/20251110100258.sql | 8 +++ .../migrations/20251110100545.sql | 2 + cmd/main-migration/migrations/atlas.sum | 66 ++++++++++--------- internal/domain/main-entities/mcu-src/dto.go | 15 +++-- .../domain/main-entities/mcu-src/entity.go | 3 +- .../domain/main-entities/mcu-sub-src/dto.go | 43 ++++++------ .../main-entities/mcu-sub-src/entity.go | 7 +- .../medical-action-src-item/dto.go | 36 +++++----- .../medical-action-src-item/entity.go | 9 +-- .../main-entities/medical-action-src/dto.go | 31 ++++----- .../medical-action-src/entity.go | 3 +- .../interface/main-handler/main-handler.go | 6 +- .../interface/main-handler/mcu-src/handler.go | 18 ++--- .../main-handler/mcu-sub-src/handler.go | 18 ++--- .../medical-action-src/handler.go | 18 ++--- .../use-case/main-use-case/mcu-src/case.go | 4 +- .../use-case/main-use-case/mcu-src/helper.go | 6 +- .../use-case/main-use-case/mcu-src/lib.go | 9 ++- .../main-use-case/mcu-sub-src/case.go | 4 +- .../main-use-case/mcu-sub-src/helper.go | 10 +-- .../use-case/main-use-case/mcu-sub-src/lib.go | 9 ++- .../medical-action-src-item/helper.go | 6 +- .../main-use-case/medical-action-src/case.go | 4 +- .../medical-action-src/helper.go | 8 +-- .../main-use-case/medical-action-src/lib.go | 9 ++- 25 files changed, 191 insertions(+), 161 deletions(-) create mode 100644 cmd/main-migration/migrations/20251110100258.sql create mode 100644 cmd/main-migration/migrations/20251110100545.sql diff --git a/cmd/main-migration/migrations/20251110100258.sql b/cmd/main-migration/migrations/20251110100258.sql new file mode 100644 index 00000000..9d902938 --- /dev/null +++ b/cmd/main-migration/migrations/20251110100258.sql @@ -0,0 +1,8 @@ +-- Modify "McuSrc" table +ALTER TABLE "public"."McuSrc" DROP CONSTRAINT "fk_McuSrc_Item", DROP COLUMN "Item_Id", ALTER COLUMN "Item_Code" TYPE character varying(50), ADD CONSTRAINT "fk_McuSrc_Item" FOREIGN KEY ("Item_Code") REFERENCES "public"."Item" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "McuSubSrc" table +ALTER TABLE "public"."McuSubSrc" DROP CONSTRAINT "fk_McuSubSrc_McuSrc", DROP COLUMN "McuSrc_Id", ALTER COLUMN "McuSrc_Code" TYPE character varying(20), ADD COLUMN "Item_Code" text NULL, ADD CONSTRAINT "fk_McuSubSrc_McuSrc" FOREIGN KEY ("McuSrc_Code") REFERENCES "public"."McuSrc" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "MedicalActionSrc" table +ALTER TABLE "public"."MedicalActionSrc" DROP CONSTRAINT "fk_MedicalActionSrc_Item", DROP COLUMN "Item_Id", ALTER COLUMN "Item_Code" TYPE character varying(50), ADD CONSTRAINT "fk_MedicalActionSrc_Item" FOREIGN KEY ("Item_Code") REFERENCES "public"."Item" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "MedicalActionSrcItem" table +ALTER TABLE "public"."MedicalActionSrcItem" DROP CONSTRAINT "fk_MedicalActionSrcItem_Item", DROP CONSTRAINT "fk_MedicalActionSrcItem_MedicalActionSrc", DROP CONSTRAINT "fk_MedicalActionSrcItem_ProcedureSrc", DROP COLUMN "MedicalActionSrc_Id", DROP COLUMN "ProcedureSrc_Id", DROP COLUMN "Item_Id", ALTER COLUMN "MedicalActionSrc_Code" TYPE character varying(20), ALTER COLUMN "ProcedureSrc_Code" TYPE character varying(10), ALTER COLUMN "Item_Code" TYPE character varying(50), ADD CONSTRAINT "fk_MedicalActionSrcItem_Item" FOREIGN KEY ("Item_Code") REFERENCES "public"."Item" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_MedicalActionSrcItem_MedicalActionSrc" FOREIGN KEY ("MedicalActionSrc_Code") REFERENCES "public"."MedicalActionSrc" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_MedicalActionSrcItem_ProcedureSrc" FOREIGN KEY ("ProcedureSrc_Code") REFERENCES "public"."ProcedureSrc" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251110100545.sql b/cmd/main-migration/migrations/20251110100545.sql new file mode 100644 index 00000000..3fdc6a82 --- /dev/null +++ b/cmd/main-migration/migrations/20251110100545.sql @@ -0,0 +1,2 @@ +-- Modify "McuSubSrc" table +ALTER TABLE "public"."McuSubSrc" DROP CONSTRAINT "fk_McuSubSrc_Item", DROP COLUMN "Item_Id", ALTER COLUMN "Item_Code" TYPE character varying(50), ADD CONSTRAINT "fk_McuSubSrc_Item" FOREIGN KEY ("Item_Code") REFERENCES "public"."Item" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index c5616081..7756676a 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:6IW+yN2RN0XymhaT/06JrQgiM+zJq5sv75us5k42LtI= +h1:A2lCKVFcUNfX413tNFZWZs6OkFj5+RmByLwekKRxWow= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -75,34 +75,36 @@ h1:6IW+yN2RN0XymhaT/06JrQgiM+zJq5sv75us5k42LtI= 20251106040137.sql h1:ppcqkVoT0o9jZcjI/TN7LuaPxXhJQhnIXEJtloP/46o= 20251106041333.sql h1:2JkxyelQ/EeB+boL5bfpnzefw32ttEGKvKchtQjWmAU= 20251106042006.sql h1:ruppYa1kAJQUU3ufQBbKGMcXrGbGJJiRPclT+dNc/YQ= -20251106050412.sql h1:MiEMJ1HCFYnalKuq3Z38xJeogfBAMqsTv2sG4EF8dDw= -20251106063418.sql h1:y3veDJPjKekOWLCZek/LgQwXPRhZtOppTfUXiqoL95s= -20251106071906.sql h1:/TUZA3XpMY23qEJXdkTwlzrNMvSSl6JJniPcgAttBaw= -20251106073157.sql h1:78txeibJ602DMD7huD618ZSMt6phSRzDNPTlo0PGyrc= -20251106074218.sql h1:8Xz7WywrtUnSxOHhlal53gG9rE7r86LFUt5zBFe/mIs= -20251106081846.sql h1:jp91Bf5bxGXMiUB1VIuN6y768vb2iWwow44WfCE5J5k= -20251106082844.sql h1:RHYzRO4G1fSWwf+xc/3QezZ/Iil67cZPIgNpNz3TNhQ= -20251106090021.sql h1:dFDk6mq+zjbYWmfWIrHf9DiKvvoXHjrr0++zssMTWP8= -20251106144745.sql h1:aHcr23iBFqCHer5D/SsPMXBCLjGqUYvWYfRU8jSJgIw= -20251107012049.sql h1:hu/7NHhnAkT4xK0RNtqmMDdH1Bo5EZbl7itDRjiCT+g= -20251107064812.sql h1:sfCXDQYnMf0ddrQ9oYljWJLLSt9NJjJV6o8VS3p7aZE= -20251107064937.sql h1:DlYGJ9LZFwZyR7jBP5zaGB128aIc4HAixBKPYCz9EkY= -20251107071420.sql h1:ynCdZAd2utLl+FhtWZwtahNXgIVOvuk3s/rOq7lfXA4= -20251107074318.sql h1:WE9cPhibWtZ0dbu1VEGirTeY6ijFYGMNhHdBtM32kOc= -20251107075050.sql h1:8tvneruqdynDOaJK1+0z4CH7YXZStZpGdqwIeOMLik4= -20251107080604.sql h1:8c4jd4Tql7tcdhbI9NS0tgvN+ADu9FnCf8wMUbmW7A0= -20251107081830.sql h1:SAAe3lmsm9vGXuSEsDdl7ad0EAxP5CMmFRDEgp9M7yY= -20251107091033.sql h1:JLdX/u7GUdBfjrPrMSNAqc8HtSoj0YA9iW9Vc6FJZdw= -20251107091209.sql h1:CzhYtwAwT+GHrbqcagnJE+v3mbl/rObf1IJaLCKlzrs= -20251107091541.sql h1:+3ZyWJTftDY2JeWThXuIxGWpUBnyMPyOyY4jBjdWYJI= -20251110012217.sql h1:f4Z8TuGc+XMSJ+Ekn4/PeHRE2FlHWkc5gKPJB0hAX7c= -20251110012306.sql h1:ENPyI6Kjdk6qKJQb0yJ6MCTDPAmO1WD/uhKuCSl+jYo= -20251110052049.sql h1:OrQ0acnyoQLKnTitZfnBcVr5jDslF59OFLaqT7SpdVs= -20251110062042.sql h1:9KwldQt0NpVPR86L0T4hlkfHAGau+7CiZYgu5rF+yhg= -20251110063202.sql h1:A117DuZmZ6U0jWHA3DISnr+yvBjKIr1ObrUr047YezQ= -20251110063633.sql h1:qTiC0F19JnhUIXF4LGJQ21jEV6kKGyhTr1x2kimFqPQ= -20251110085551.sql h1:HZcJM0RSC6HBaUSjKBE8MgDG8Vn9f3LmwA/OnT9Cp7I= -20251110091516.sql h1:W3AQhQLgirEWuCObbLl+Prdrbq6k6EEY1xcoWsmbog4= -20251110091948.sql h1:3tsITMrZr/T+L4wqUMz8sHS229jCJl4T0Nu3dMccxH8= -20251110092729.sql h1:uU+k88RH/e0Ns4/SmJl03RVYPscBAPuiLfxR6CJqaf0= -20251110093522.sql h1:O7upSj8VNjzvroL4IU59bfxKATOkAVGBArcUbVNq9aM= +20251106050412.sql h1:1002KYtHd8AwrQTMewbs/PPHDylHDghigE/3S7PVdMA= +20251106063418.sql h1:jPW/gBnbFl4RO39lQ0ZMDtYA6xbhyD6CgQupT50HmaY= +20251106071906.sql h1:leYGKxR3EQn794aOehf0sd/ZPmOnvBMZPy5/anGmRB4= +20251106073157.sql h1:KASMzjjjk5UB7Zj8lCRtM1utc4ZnDjlnpZbtTe3vONE= +20251106074218.sql h1:Z5q5deOvLaZDPhiVTN9st3/s56RepBa2YOyrMXBdj4A= +20251106081846.sql h1:P+VsWwhGt60adDIZuE/Aa38JVp/yX1rnsdpXpxASodw= +20251106082844.sql h1:Dmi5A8i9frQZvdXYPwc7f8CisZtBH8liSXq1rI6z1iM= +20251106090021.sql h1:4JwdKgO8T46YhyWVJUxpRIwudBDlG8QN1brSOYmgQ20= +20251106144745.sql h1:nqnQCzGrVJaq8ilOEOGXeRUL1dolj+OPWKuP8A92FRA= +20251107012049.sql h1:Pff4UqltGS3clSlGr0qq8CQM56L29wyxY0FC/N/YAhU= +20251107064812.sql h1:GB9a0ZfMYTIoGNmKUG+XcYUsTnRMFfT4/dAD71uCPc4= +20251107064937.sql h1:IC5pw1Ifj30hiE6dr5NMHXaSHoQI+vRd40N5ABgBHRI= +20251107071420.sql h1:9NO3iyLEXEtWa2kSRjM/8LyzuVIk6pdFL2SuheWjB08= +20251107074318.sql h1:7fHbSRrdjOmHh/xwnjCLwoiB5cW5zeH+uxLV0vZbkIA= +20251107075050.sql h1:np+3uTOnU9QNtK7Knaw8eRMhkyB9AwrtSNHphOBxbHY= +20251107080604.sql h1:cXDBLPJDVWLTG6yEJqkJsOQ7p7VYxLM2SY+mwO8qSHo= +20251107081830.sql h1:/S7OQZo4ZnK80t28g/JyiOTZtmWG/dP5Wg2zXNMQ/iE= +20251107091033.sql h1:/cbkF1nO/IjNSIfDJJx456KJtQ9rWFXOBFAkR/M2xiE= +20251107091209.sql h1:jrLQOUeV8ji2fg0pnEcs1bw4ANUxzTSMXC/rrHLIY+M= +20251107091541.sql h1:6UqbhQQRmzA2+eKu5lIvkwOkk+lH70QLZC8Pjpjcq68= +20251110012217.sql h1:C9HpX0iyHzKjyNv/5DSAn2MCHj6MX4p5UQ/NrY7QD0w= +20251110012306.sql h1:J54yb27d30LBbYp9n1P66gFVRlxPguKu0kxmWIBBG8g= +20251110052049.sql h1:232T2x8xTczJl9nk4jxJpZXhoOGYthhxjJ7nK8Jd8vg= +20251110062042.sql h1:WnfVUXrzYoj8qdkkjO9/JQQ8agGd4GfSHQdMjo7LDAg= +20251110063202.sql h1:hSzGfwVMWa6q3vwIQZUkxKgBNCzHjB+6GKy54zfV+oQ= +20251110063633.sql h1:/VpofIAqNS1CnazEnpW/+evbzn9Kew3xDW48r57M+Xg= +20251110085551.sql h1:pAVoSz6QO8bwYqn9Y7f2Bgdvh8TVNMiv/JqJgwSI+ck= +20251110091516.sql h1:Ab7z5iz7MgeSKxkvXGQSTZfO2nRO6lu1c/5SwO3aeCs= +20251110091948.sql h1:cM8dIy7OHIxws4fcpJjHhY61+4Q1aNCXpyKh9BbSOB8= +20251110092729.sql h1:AAg9gXlwOWxOS5L6EryOUNrKkFna7i0oiKdiu3G1Hyg= +20251110093522.sql h1:sCowKTPaaXKKaa5i5HKIlOaOeqre+5m4RxTUNHPrOX8= +20251110100258.sql h1:3iVmC33XfxCquwfyWTC0QsUNPgiX9/mknggjTbJXfCk= +20251110100545.sql h1:b5pQN3cg59DahiA/rujc45RH53XQFaUmqVqouglFk1o= diff --git a/internal/domain/main-entities/mcu-src/dto.go b/internal/domain/main-entities/mcu-src/dto.go index 7ab13428..6db7af65 100644 --- a/internal/domain/main-entities/mcu-src/dto.go +++ b/internal/domain/main-entities/mcu-src/dto.go @@ -6,10 +6,10 @@ import ( ) type CreateDto struct { - Code string `json:"code" validate:"maxLength=20"` + Code *string `json:"code" validate:"maxLength=20"` Name string `json:"name" validate:"maxLength=50"` McuSrcCategory_Code *string `json:"mcuSrcCategory_code" validate:"maxLength=20"` - Item_Id *uint `json:"item_id"` + Item_Code *string `json:"item_code"` } type ReadListDto struct { @@ -27,17 +27,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 { @@ -51,7 +52,7 @@ type ResponseDto struct { Code string `json:"code"` Name string `json:"name"` McuSrcCategory_Code *string `json:"mcuSrcCategory_code"` - Item_Id *uint `json:"item_id"` + Item_Code *string `json:"item_code"` Item *ei.Item `json:"item,omitempty"` } @@ -60,7 +61,7 @@ func (d McuSrc) ToResponse() ResponseDto { Code: d.Code, Name: d.Name, McuSrcCategory_Code: d.McuSrcCategory_Code, - Item_Id: d.Item_Id, + Item_Code: d.Item_Code, Item: d.Item, } resp.Main = d.Main diff --git a/internal/domain/main-entities/mcu-src/entity.go b/internal/domain/main-entities/mcu-src/entity.go index 6f97ac24..91ef8b99 100644 --- a/internal/domain/main-entities/mcu-src/entity.go +++ b/internal/domain/main-entities/mcu-src/entity.go @@ -12,7 +12,6 @@ type McuSrc struct { Name string `json:"name" gorm:"size:50"` McuSrcCategory_Code *string `json:"mcuSrcCategory_code" gorm:"size:20"` McuSrcCategory *emsc.McuSrcCategory `json:"mcuSrcCategory,omitempty" gorm:"foreignKey:McuSrcCategory_Code;references:Code"` - Item_Id *uint `json:"item_id"` Item_Code *string `json:"item_code"` - Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` + Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Code;references:Code"` } diff --git a/internal/domain/main-entities/mcu-sub-src/dto.go b/internal/domain/main-entities/mcu-sub-src/dto.go index f1b6d3bb..fde77fd2 100644 --- a/internal/domain/main-entities/mcu-sub-src/dto.go +++ b/internal/domain/main-entities/mcu-sub-src/dto.go @@ -7,10 +7,10 @@ import ( ) type CreateDto struct { - Code string `json:"code" validate:"maxLength=20"` - Name string `json:"name" validate:"maxLength=50"` - McuSrc_Id *uint `json:"mcuSrc_id"` - Item_Id *uint `json:"item_id"` + Code *string `json:"code" validate:"maxLength=20"` + Name string `json:"name" validate:"maxLength=50"` + McuSrc_Code *string `json:"mcuSrc_code"` + Item_Code *string `json:"item_code"` } type ReadListDto struct { @@ -21,24 +21,25 @@ type ReadListDto struct { } type FilterDto struct { - Code string `json:"code"` - Name string `json:"name"` + Code *string `json:"code"` + Name *string `json:"name"` CheckupCategory_Code *string `json:"checkupCategory-code"` 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 { @@ -49,22 +50,22 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Code string `json:"code"` - Name string `json:"name"` - McuSrc_Id *uint `json:"mcuSrc_id"` - McuSrc *ems.McuSrc `json:"mcuSrc,omitempty"` - Item_Id *uint `json:"item_id"` - Item *ei.Item `json:"item,omitempty"` + Code string `json:"code"` + Name string `json:"name"` + McuSrc_Code *string `json:"mcuSrc_code"` + McuSrc *ems.McuSrc `json:"mcuSrc,omitempty"` + Item_Code *string `json:"item_code"` + Item *ei.Item `json:"item,omitempty"` } func (d McuSubSrc) ToResponse() ResponseDto { resp := ResponseDto{ - Code: d.Code, - Name: d.Name, - McuSrc_Id: d.McuSrc_Id, - McuSrc: d.McuSrc, - Item_Id: d.Item_Id, - Item: d.Item, + Code: d.Code, + Name: d.Name, + McuSrc_Code: d.McuSrc_Code, + McuSrc: d.McuSrc, + Item_Code: d.Item_Code, + Item: d.Item, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/mcu-sub-src/entity.go b/internal/domain/main-entities/mcu-sub-src/entity.go index d81e9d00..888ebf90 100644 --- a/internal/domain/main-entities/mcu-sub-src/entity.go +++ b/internal/domain/main-entities/mcu-sub-src/entity.go @@ -10,9 +10,8 @@ type McuSubSrc struct { ecore.Main // adjust this according to the needs Code string `json:"code" gorm:"unique;size:20"` Name string `json:"name" gorm:"size:50"` - McuSrc_Id *uint `json:"mcuSrc_id"` McuSrc_Code *string `json:"mcuSrc_code"` - McuSrc *ems.McuSrc `json:"mcuSrc,omitempty" gorm:"foreignKey:McuSrc_Id;references:Id"` - Item_Id *uint `json:"item_id"` - Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` + McuSrc *ems.McuSrc `json:"mcuSrc,omitempty" gorm:"foreignKey:McuSrc_Code;references:Code"` + Item_Code *string `json:"item_code"` + Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Code;references:Code"` } diff --git a/internal/domain/main-entities/medical-action-src-item/dto.go b/internal/domain/main-entities/medical-action-src-item/dto.go index 540a6ca5..849e6b18 100644 --- a/internal/domain/main-entities/medical-action-src-item/dto.go +++ b/internal/domain/main-entities/medical-action-src-item/dto.go @@ -8,9 +8,9 @@ import ( ) type CreateDto struct { - MedicalActionSrc_Id *uint `json:"medicalActionSrc_id"` - ProcedureSrc_Id *uint `json:"procedureSrc_id"` - Item_Id *uint `json:"item_id"` + MedicalActionSrc_Code *string `json:"medicalActionSrc_code"` + ProcedureSrc_Code *string `json:"procedureSrc_code"` + Item_Code *string `json:"item_code"` } type ReadListDto struct { @@ -20,9 +20,9 @@ type ReadListDto struct { } type FilterDto struct { - MedicalActionSrc_Id *uint `json:"medicalActionSrc-id"` - ProcedureSrc_Id *uint `json:"procedureSrc-id"` - Item_Id *uint `json:"item-id"` + MedicalActionSrc_Code *string `json:"medicalActionSrc-code"` + ProcedureSrc_Code *string `json:"procedureSrc-code"` + Item_Code *string `json:"item-code"` } type ReadDetailDto struct { @@ -46,22 +46,22 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - MedicalActionSrc_Id *uint `json:"medicalActionSrc_id"` - MedicalActionSrc *emas.MedicalActionSrc `json:"medicalActionSrc,omitempty"` - ProcedureSrc_Id *uint `json:"procedureSrc_id"` - ProcedureSrc *eps.ProcedureSrc `json:"procedureSrc,omitempty"` - Item_Id *uint `json:"item_id"` - Item *ei.Item `json:"item,omitempty"` + MedicalActionSrc_Code *string `json:"medicalActionSrc_code"` + MedicalActionSrc *emas.MedicalActionSrc `json:"medicalActionSrc,omitempty"` + ProcedureSrc_Code *string `json:"procedureSrc_code"` + ProcedureSrc *eps.ProcedureSrc `json:"procedureSrc,omitempty"` + Item_Code *string `json:"item_code"` + Item *ei.Item `json:"item,omitempty"` } func (d MedicalActionSrcItem) ToResponse() ResponseDto { resp := ResponseDto{ - MedicalActionSrc_Id: d.MedicalActionSrc_Id, - MedicalActionSrc: d.MedicalActionSrc, - ProcedureSrc_Id: d.ProcedureSrc_Id, - ProcedureSrc: d.ProcedureSrc, - Item_Id: d.Item_Id, - Item: d.Item, + MedicalActionSrc_Code: d.MedicalActionSrc_Code, + MedicalActionSrc: d.MedicalActionSrc, + ProcedureSrc_Code: d.ProcedureSrc_Code, + ProcedureSrc: d.ProcedureSrc, + Item_Code: d.Item_Code, + Item: d.Item, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/medical-action-src-item/entity.go b/internal/domain/main-entities/medical-action-src-item/entity.go index 579d7d87..2474c08b 100644 --- a/internal/domain/main-entities/medical-action-src-item/entity.go +++ b/internal/domain/main-entities/medical-action-src-item/entity.go @@ -9,13 +9,10 @@ import ( type MedicalActionSrcItem struct { ecore.Main // adjust this according to the needs - MedicalActionSrc_Id *uint `json:"medicalActionSrc_id"` MedicalActionSrc_Code *string `json:"medicalActionSrc_code"` - MedicalActionSrc *emas.MedicalActionSrc `json:"medicalActionSrc,omitempty" gorm:"foreignKey:MedicalActionSrc_Id;references:Id"` - ProcedureSrc_Id *uint `json:"procedureSrc_id"` + MedicalActionSrc *emas.MedicalActionSrc `json:"medicalActionSrc,omitempty" gorm:"foreignKey:MedicalActionSrc_Code;references:Code"` ProcedureSrc_Code *string `json:"procedureSrc_code"` - ProcedureSrc *eps.ProcedureSrc `json:"procedureSrc,omitempty" gorm:"foreignKey:ProcedureSrc_Id;references:Id"` - Item_Id *uint `json:"item_id"` + ProcedureSrc *eps.ProcedureSrc `json:"procedureSrc,omitempty" gorm:"foreignKey:ProcedureSrc_Code;references:Code"` Item_Code *string `json:"item_code"` - Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` + Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Code;references:Code"` } diff --git a/internal/domain/main-entities/medical-action-src/dto.go b/internal/domain/main-entities/medical-action-src/dto.go index 32e248d8..9316677f 100644 --- a/internal/domain/main-entities/medical-action-src/dto.go +++ b/internal/domain/main-entities/medical-action-src/dto.go @@ -6,10 +6,10 @@ import ( ) type CreateDto struct { - Code string `json:"code" validate:"maxLength=20"` - Name string `json:"name" validate:"maxLength=50"` - Type_Code string `json:"type_code" validate:"maxLength=20"` - Item_Id *uint `json:"item_id"` + Code *string `json:"code" validate:"maxLength=20"` + Name string `json:"name" validate:"maxLength=50"` + Type_Code string `json:"type_code" validate:"maxLength=20"` + Item_Code *string `json:"item_code"` } type ReadListDto struct { @@ -20,25 +20,26 @@ type ReadListDto struct { } type FilterDto struct { - Code string `json:"code"` - Name string `json:"name"` - Type_Code string `json:"type_code"` - Item_Id *uint `json:"item-id"` - Search string `json:"search" gormhelper:"searchColumns=Code,Name"` + Code *string `json:"code"` + Name string `json:"name"` + Type_Code string `json:"type_code"` + Item_Code *string `json:"item-code"` + Search string `json:"search" gormhelper:"searchColumns=Code,Name"` } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code string `json:"code"` + Id *uint16 `json:"id"` + Code *string `json:"code"` } type UpdateDto struct { - Id uint `json:"id"` + Id *uint `json:"id"` CreateDto } type DeleteDto struct { - Id uint `json:"id"` + Id *uint `json:"id"` + Code *string `json:"code"` } type MetaDto struct { @@ -52,7 +53,7 @@ type ResponseDto struct { Code string `json:"code"` Name string `json:"name"` Type_Code string `json:"type_code"` - Item_Id *uint `json:"item_id"` + Item_Code *string `json:"item_code"` Item *ei.Item `json:"item,omitempty"` } @@ -61,7 +62,7 @@ func (d MedicalActionSrc) ToResponse() ResponseDto { Code: d.Code, Name: d.Name, Type_Code: d.Type_Code, - Item_Id: d.Item_Id, + Item_Code: d.Item_Code, Item: d.Item, } resp.Main = d.Main diff --git a/internal/domain/main-entities/medical-action-src/entity.go b/internal/domain/main-entities/medical-action-src/entity.go index a4543d92..db3672a6 100644 --- a/internal/domain/main-entities/medical-action-src/entity.go +++ b/internal/domain/main-entities/medical-action-src/entity.go @@ -10,7 +10,6 @@ type MedicalActionSrc struct { Code string `json:"code" gorm:"unique;size:20"` Name string `json:"name" gorm:"size:50"` Type_Code string `json:"type_code" gorm:"size:20"` - Item_Id *uint `json:"item_id"` Item_Code *string `json:"item_code"` - Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` + Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Code;references:Code"` } diff --git a/internal/interface/main-handler/main-handler.go b/internal/interface/main-handler/main-handler.go index 15c236b8..74a5e40a 100644 --- a/internal/interface/main-handler/main-handler.go +++ b/internal/interface/main-handler/main-handler.go @@ -316,17 +316,17 @@ func SetRoutes() http.Handler { hc.RegCrud(r, "/v1/medicine-group", medicinegroup.O) hc.RegCrud(r, "/v1/medicine-method", medicinemethod.O) hc.RegCrud(r, "/v1/mcu-src-category", mcusrccategory.O) - hc.RegCrud(r, "/v1/mcu-src", mcusrc.O) + hc.RegCrudByCode(r, "/v1/mcu-src", mcusrc.O) hc.RegCrud(r, "/v1/ethnic", ethnic.O) hc.RegCrud(r, "/v1/insurance-company", insurancecompany.O) hc.RegCrudByCode(r, "/v1/medicine", medicine.O) hc.RegCrudByCode(r, "/v1/device", device.O) hc.RegCrudByCode(r, "/v1/material", material.O) hc.RegCrud(r, "/v1/doctor-fee", doctorfee.O) - hc.RegCrud(r, "/v1/medical-action-src", medicalactionsrc.O) + hc.RegCrudByCode(r, "/v1/medical-action-src", medicalactionsrc.O) hc.RegCrud(r, "/v1/medical-action-src-item", medicalactionsrcitem.O) hc.RegCrud(r, "/v1/language", language.O) - hc.RegCrud(r, "/v1/mcu-sub-src", mcusubsrc.O) + hc.RegCrudByCode(r, "/v1/mcu-sub-src", mcusubsrc.O) hc.RegCrud(r, "/v1/vehicle", vehicle.O) hc.RegCrud(r, "/v1/vehicle-hist", vehiclehist.O) hc.RegCrud(r, "/v1/edu-assessment", eduassesment.O) diff --git a/internal/interface/main-handler/mcu-src/handler.go b/internal/interface/main-handler/mcu-src/handler.go index c607017d..7523ea7e 100644 --- a/internal/interface/main-handler/mcu-src/handler.go +++ b/internal/interface/main-handler/mcu-src/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/mcu-sub-src/handler.go b/internal/interface/main-handler/mcu-sub-src/handler.go index 949be715..ad7868d9 100644 --- a/internal/interface/main-handler/mcu-sub-src/handler.go +++ b/internal/interface/main-handler/mcu-sub-src/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/medical-action-src/handler.go b/internal/interface/main-handler/medical-action-src/handler.go index c8b24706..42d41c92 100644 --- a/internal/interface/main-handler/medical-action-src/handler.go +++ b/internal/interface/main-handler/medical-action-src/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 = uint(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 = uint(id) + dto.Code = &code res, err := u.Delete(dto) rw.DataResponse(w, res, err) } diff --git a/internal/use-case/main-use-case/mcu-src/case.go b/internal/use-case/main-use-case/mcu-src/case.go index 564a582b..31af8e84 100644 --- a/internal/use-case/main-use-case/mcu-src/case.go +++ b/internal/use-case/main-use-case/mcu-src/case.go @@ -170,7 +170,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.McuSrc var err error @@ -226,7 +226,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.McuSrc var err error diff --git a/internal/use-case/main-use-case/mcu-src/helper.go b/internal/use-case/main-use-case/mcu-src/helper.go index 9d808ca8..545def25 100644 --- a/internal/use-case/main-use-case/mcu-src/helper.go +++ b/internal/use-case/main-use-case/mcu-src/helper.go @@ -27,14 +27,14 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.McuSrc) { inputSrc = &inputTemp.CreateDto } - data.Code = inputSrc.Code + data.Code = *inputSrc.Code data.Name = inputSrc.Name data.McuSrcCategory_Code = inputSrc.McuSrcCategory_Code } func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { itemCreate := ei.CreateDto{ - Code: pu.AddPrefix("mcu-", input.Code), + Code: pu.AddPrefix("mcu-", *input.Code), Name: input.Name, ItemGroup_Code: ero.ITGCMCU, // Uom_Code: &input.Uom_Code, @@ -45,6 +45,6 @@ func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { return err } - input.Item_Id = &item.Id + input.Item_Code = &item.Code return nil } diff --git a/internal/use-case/main-use-case/mcu-src/lib.go b/internal/use-case/main-use-case/mcu-src/lib.go index e74d5ce8..d62c9282 100644 --- a/internal/use-case/main-use-case/mcu-src/lib.go +++ b/internal/use-case/main-use-case/mcu-src/lib.go @@ -81,7 +81,14 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e tx = dg.I } - if err := tx.First(&data, input.Id).Error; err != nil { + if input.Code != nil { + tx = tx.Where("\"Code\" = ?", *input.Code) + } + if input.Id != nil { + tx = tx.Where("\"Id\" = ?", input.Id) + } + + if err := tx.First(&data).Error; err != nil { if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil { return nil, processedErr } diff --git a/internal/use-case/main-use-case/mcu-sub-src/case.go b/internal/use-case/main-use-case/mcu-sub-src/case.go index ba533bc4..fbb9f468 100644 --- a/internal/use-case/main-use-case/mcu-sub-src/case.go +++ b/internal/use-case/main-use-case/mcu-sub-src/case.go @@ -170,7 +170,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.McuSubSrc var err error @@ -226,7 +226,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.McuSubSrc var err error diff --git a/internal/use-case/main-use-case/mcu-sub-src/helper.go b/internal/use-case/main-use-case/mcu-sub-src/helper.go index 95444d5a..962abe46 100644 --- a/internal/use-case/main-use-case/mcu-sub-src/helper.go +++ b/internal/use-case/main-use-case/mcu-sub-src/helper.go @@ -27,15 +27,15 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.McuSubSrc) { inputSrc = &inputTemp.CreateDto } - data.Code = inputSrc.Code + data.Code = *inputSrc.Code data.Name = inputSrc.Name - data.McuSrc_Id = inputSrc.McuSrc_Id - data.Item_Id = inputSrc.Item_Id + data.McuSrc_Code = inputSrc.McuSrc_Code + data.Item_Code = inputSrc.Item_Code } func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { itemCreate := ei.CreateDto{ - Code: pu.AddPrefix("mcuSub-", input.Code), + Code: pu.AddPrefix("mcuSub-", *input.Code), Name: input.Name, ItemGroup_Code: ero.ITGCMCUSub, // Uom_Code: &input.Uom_Code, @@ -46,6 +46,6 @@ func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { return err } - input.Item_Id = &item.Id + input.Item_Code = &item.Code return nil } diff --git a/internal/use-case/main-use-case/mcu-sub-src/lib.go b/internal/use-case/main-use-case/mcu-sub-src/lib.go index 96684fef..438eb7ac 100644 --- a/internal/use-case/main-use-case/mcu-sub-src/lib.go +++ b/internal/use-case/main-use-case/mcu-sub-src/lib.go @@ -81,7 +81,14 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e tx = dg.I } - if err := tx.First(&data, input.Id).Error; err != nil { + if input.Code != nil { + tx = tx.Where("\"Code\" = ?", *input.Code) + } + if input.Id != nil { + tx = tx.Where("\"Id\" = ?", input.Id) + } + + if err := tx.First(&data).Error; err != nil { if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil { return nil, processedErr } diff --git a/internal/use-case/main-use-case/medical-action-src-item/helper.go b/internal/use-case/main-use-case/medical-action-src-item/helper.go index 385b0f53..09d028a9 100644 --- a/internal/use-case/main-use-case/medical-action-src-item/helper.go +++ b/internal/use-case/main-use-case/medical-action-src-item/helper.go @@ -16,7 +16,7 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.MedicalActionSrcIte inputTemp := any(input).(*e.UpdateDto) inputSrc = &inputTemp.CreateDto } - data.MedicalActionSrc_Id = inputSrc.MedicalActionSrc_Id - data.ProcedureSrc_Id = inputSrc.ProcedureSrc_Id - data.Item_Id = inputSrc.Item_Id + data.MedicalActionSrc_Code = inputSrc.MedicalActionSrc_Code + data.ProcedureSrc_Code = inputSrc.ProcedureSrc_Code + data.Item_Code = inputSrc.Item_Code } diff --git a/internal/use-case/main-use-case/medical-action-src/case.go b/internal/use-case/main-use-case/medical-action-src/case.go index cd42766c..7ca58dde 100644 --- a/internal/use-case/main-use-case/medical-action-src/case.go +++ b/internal/use-case/main-use-case/medical-action-src/case.go @@ -169,7 +169,7 @@ func ReadDetail(input e.ReadDetailDto) (*d.Data, error) { } func Update(input e.UpdateDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.MedicalActionSrc var err error @@ -225,7 +225,7 @@ func Update(input e.UpdateDto) (*d.Data, error) { } func Delete(input e.DeleteDto) (*d.Data, error) { - rdDto := e.ReadDetailDto{Id: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.MedicalActionSrc var err error diff --git a/internal/use-case/main-use-case/medical-action-src/helper.go b/internal/use-case/main-use-case/medical-action-src/helper.go index c955274d..910b6f8a 100644 --- a/internal/use-case/main-use-case/medical-action-src/helper.go +++ b/internal/use-case/main-use-case/medical-action-src/helper.go @@ -27,15 +27,15 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.MedicalActionSrc) { inputSrc = &inputTemp.CreateDto } - data.Code = inputSrc.Code + data.Code = *inputSrc.Code data.Name = inputSrc.Name data.Type_Code = inputSrc.Type_Code - data.Item_Id = inputSrc.Item_Id + data.Item_Code = inputSrc.Item_Code } func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { itemCreate := ei.CreateDto{ - Code: pu.AddPrefix("medAct-", input.Code), + Code: pu.AddPrefix("medAct-", *input.Code), Name: input.Name, ItemGroup_Code: ero.ITGCMedAct, } @@ -44,6 +44,6 @@ func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { return err } - input.Item_Id = &item.Id + input.Item_Code = &item.Code return nil } diff --git a/internal/use-case/main-use-case/medical-action-src/lib.go b/internal/use-case/main-use-case/medical-action-src/lib.go index 31492861..dd29a6b3 100644 --- a/internal/use-case/main-use-case/medical-action-src/lib.go +++ b/internal/use-case/main-use-case/medical-action-src/lib.go @@ -81,7 +81,14 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e tx = dg.I } - if err := tx.First(&data, input.Id).Error; err != nil { + if input.Code != nil { + tx = tx.Where("\"Code\" = ?", *input.Code) + } + if input.Id != nil { + tx = tx.Where("\"Id\" = ?", input.Id) + } + + if err := tx.First(&data).Error; err != nil { if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil { return nil, processedErr }