From 282cc93c140959a9a8c2c23d7f7f414c057d9251 Mon Sep 17 00:00:00 2001 From: dpurbosakti Date: Wed, 17 Sep 2025 11:53:04 +0700 Subject: [PATCH] change fk, put fk on medmix and remove fk from medmixitem --- cmd/main-migration/migrations/20250917045138.sql | 2 ++ cmd/main-migration/migrations/atlas.sum | 7 ++++--- .../domain/main-entities/medicine-mix-item/dto.go | 11 ++++------- .../domain/main-entities/medicine-mix-item/entity.go | 12 +++++------- internal/domain/main-entities/medicine-mix/dto.go | 8 ++++++-- internal/domain/main-entities/medicine-mix/entity.go | 8 +++++--- 6 files changed, 26 insertions(+), 22 deletions(-) create mode 100644 cmd/main-migration/migrations/20250917045138.sql diff --git a/cmd/main-migration/migrations/20250917045138.sql b/cmd/main-migration/migrations/20250917045138.sql new file mode 100644 index 00000000..b40ade76 --- /dev/null +++ b/cmd/main-migration/migrations/20250917045138.sql @@ -0,0 +1,2 @@ +-- Modify "MedicineMixItem" table +ALTER TABLE "public"."MedicineMixItem" DROP CONSTRAINT "fk_MedicineMixItem_MedicineMix", ADD CONSTRAINT "fk_MedicineMix_MixItems" FOREIGN KEY ("MedicineMix_Id") REFERENCES "public"."MedicineMix" ("Id") 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 559bbade..947c21ed 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:1QSYLfLrRojOO3SUOR0bOUsv7hWGJxR4mfzv6/P540k= +h1:QeWON016g64FziEzikpibQnksdHm3nulYh4SE5Wrpek= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -8,5 +8,6 @@ h1:1QSYLfLrRojOO3SUOR0bOUsv7hWGJxR4mfzv6/P540k= 20250910055902.sql h1:5xwjAV6QbtZT9empTJKfhyAjdknbHzb15B0Ku5dzqtQ= 20250915123412.sql h1:D83xaU2YlDEd21HLup/YQpQ2easMToYCyy/oK6AFgQs= 20250916043819.sql h1:ekoTJsBqQZ8G8n0qJ03d13+eoNoc7sAUEQGA5D/CCxk= -20250917040616.sql h1:QFuMvZUCmZPWsjHTdIFOT8P0fzCv3/xP0jGsfVms0aA= -20250917040751.sql h1:/0YgGP0VLK/WGTVi1KUuPQsx7i9O9Em8u/Ec1luYPDo= +20250917040616.sql h1:zoCnmcXuM7AVv85SmN7RmFglCgJnoDmpRWExH0LAc9Q= +20250917040751.sql h1:J1xyRrh32y1+lezwAyNwPcUQ6ABBSgbvzNLva4SVdQU= +20250917045138.sql h1:7yGxD9Rxn89d9Z7bJQQo0kS++ZE6c1w1iURemEDeo/U= diff --git a/internal/domain/main-entities/medicine-mix-item/dto.go b/internal/domain/main-entities/medicine-mix-item/dto.go index dbcbce21..1be930e1 100644 --- a/internal/domain/main-entities/medicine-mix-item/dto.go +++ b/internal/domain/main-entities/medicine-mix-item/dto.go @@ -3,7 +3,6 @@ package medicinemixitem import ( ecore "simrs-vx/internal/domain/base-entities/core" em "simrs-vx/internal/domain/main-entities/medicine" - emm "simrs-vx/internal/domain/main-entities/medicine-mix" ) type CreateDto struct { @@ -49,17 +48,15 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - MedicineMix_Id *uint `json:"medicineMix_id"` - MedicineMix *emm.MedicineMix `json:"medicineMix,omitempty"` - Medicine_Id *uint `json:"medicine_id"` - Medicine *em.Medicine `json:"medicine,omitempty"` - Dose *uint8 `json:"dose"` + MedicineMix_Id *uint `json:"medicineMix_id"` + Medicine_Id *uint `json:"medicine_id"` + Medicine *em.Medicine `json:"medicine,omitempty"` + Dose *uint8 `json:"dose"` } func (d MedicineMixItem) ToResponse() ResponseDto { resp := ResponseDto{ MedicineMix_Id: d.MedicineMix_Id, - MedicineMix: d.MedicineMix, Medicine_Id: d.Medicine_Id, Medicine: d.Medicine, Dose: d.Dose, diff --git a/internal/domain/main-entities/medicine-mix-item/entity.go b/internal/domain/main-entities/medicine-mix-item/entity.go index 7c456fcb..cbfdc7ed 100644 --- a/internal/domain/main-entities/medicine-mix-item/entity.go +++ b/internal/domain/main-entities/medicine-mix-item/entity.go @@ -3,14 +3,12 @@ package medicinemixitem import ( ecore "simrs-vx/internal/domain/base-entities/core" em "simrs-vx/internal/domain/main-entities/medicine" - emm "simrs-vx/internal/domain/main-entities/medicine-mix" ) type MedicineMixItem struct { - ecore.Main // adjust this according to the needs - MedicineMix_Id *uint `json:"medicineMix_id"` - MedicineMix *emm.MedicineMix `json:"medicineMix,omitempty" gorm:"foreignKey:MedicineMix_Id;references:Id"` - Medicine_Id *uint `json:"medicine_id"` - Medicine *em.Medicine `json:"medicine,omitempty" gorm:"foreignKey:Medicine_Id;references:Id"` - Dose *uint8 `json:"dose"` + ecore.Main // adjust this according to the needs + MedicineMix_Id *uint `json:"medicineMix_id"` + Medicine_Id *uint `json:"medicine_id"` + Medicine *em.Medicine `json:"medicine,omitempty" gorm:"foreignKey:Medicine_Id;references:Id"` + Dose *uint8 `json:"dose"` } diff --git a/internal/domain/main-entities/medicine-mix/dto.go b/internal/domain/main-entities/medicine-mix/dto.go index b9fc656e..05b67a06 100644 --- a/internal/domain/main-entities/medicine-mix/dto.go +++ b/internal/domain/main-entities/medicine-mix/dto.go @@ -2,6 +2,8 @@ package medicinemix import ( ecore "simrs-vx/internal/domain/base-entities/core" + + emmi "simrs-vx/internal/domain/main-entities/medicine-mix-item" ) type CreateDto struct { @@ -37,12 +39,14 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Name string `json:"name"` + Name string `json:"name"` + MixItems []*emmi.MedicineMixItem `json:"mixItems"` } func (d MedicineMix) ToResponse() ResponseDto { resp := ResponseDto{ - Name: d.Name, + Name: d.Name, + MixItems: d.MixItems, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/medicine-mix/entity.go b/internal/domain/main-entities/medicine-mix/entity.go index 2445bde2..8c609579 100644 --- a/internal/domain/main-entities/medicine-mix/entity.go +++ b/internal/domain/main-entities/medicine-mix/entity.go @@ -2,10 +2,12 @@ package medicinemix import ( ecore "simrs-vx/internal/domain/base-entities/core" + emmi "simrs-vx/internal/domain/main-entities/medicine-mix-item" ) type MedicineMix struct { - ecore.Main // adjust this according to the needs - Name string `json:"name" gorm:"size:50"` - Note *string `json:"note" gom:"size:1024"` + ecore.Main // adjust this according to the needs + Name string `json:"name" gorm:"size:50"` + Note *string `json:"note" gom:"size:1024"` + MixItems []*emmi.MedicineMixItem `json:"mixItems" gorm:"foreignKey:MedicineMix_Id;references:Id"` }