diff --git a/cmd/migration/migrations/20250829075746.sql b/cmd/migration/migrations/20250829081406.sql similarity index 98% rename from cmd/migration/migrations/20250829075746.sql rename to cmd/migration/migrations/20250829081406.sql index 11267986..c74cb017 100644 --- a/cmd/migration/migrations/20250829075746.sql +++ b/cmd/migration/migrations/20250829081406.sql @@ -1,18 +1,3 @@ --- Create "User" table -CREATE TABLE "public"."User" ( - "Id" bigserial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Name" character varying(25) NOT NULL, - "Password" character varying(255) NOT NULL, - "Status_Code" character varying(10) NOT NULL, - "FailedLoginCount" smallint NULL, - "LoginAttemptCount" bigint NULL, - "LastSuccessLogin" timestamptz NULL, - "LastAllowdLogin" timestamptz NULL, - PRIMARY KEY ("Id") -); -- Create "DiagnoseSrc" table CREATE TABLE "public"."DiagnoseSrc" ( "Id" bigserial NOT NULL, @@ -25,17 +10,6 @@ CREATE TABLE "public"."DiagnoseSrc" ( PRIMARY KEY ("Id"), CONSTRAINT "uni_DiagnoseSrc_Code" UNIQUE ("Code") ); --- Create "Uom" table -CREATE TABLE "public"."Uom" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(10) NULL, - "Name" character varying(50) NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_Uom_Code" UNIQUE ("Code") -); -- Create "Counter" table CREATE TABLE "public"."Counter" ( "Id" serial NOT NULL, @@ -75,6 +49,17 @@ CREATE TABLE "public"."McuSrc" ( PRIMARY KEY ("Id"), CONSTRAINT "uni_McuSrc_Code" UNIQUE ("Code") ); +-- Create "Uom" table +CREATE TABLE "public"."Uom" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(10) NULL, + "Name" character varying(50) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_Uom_Code" UNIQUE ("Code") +); -- Create "PharmacyCompany" table CREATE TABLE "public"."PharmacyCompany" ( "Id" bigserial NOT NULL, @@ -87,6 +72,21 @@ CREATE TABLE "public"."PharmacyCompany" ( PRIMARY KEY ("Id"), CONSTRAINT "uni_PharmacyCompany_Code" UNIQUE ("Code") ); +-- Create "User" table +CREATE TABLE "public"."User" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Name" character varying(25) NOT NULL, + "Password" character varying(255) NOT NULL, + "Status_Code" character varying(10) NOT NULL, + "FailedLoginCount" smallint NULL, + "LoginAttemptCount" bigint NULL, + "LastSuccessLogin" timestamptz NULL, + "LastAllowdLogin" timestamptz NULL, + PRIMARY KEY ("Id") +); -- Create "Item" table CREATE TABLE "public"."Item" ( "Id" bigserial NOT NULL, @@ -103,6 +103,21 @@ CREATE TABLE "public"."Item" ( CONSTRAINT "uni_Item_Code" UNIQUE ("Code"), CONSTRAINT "fk_Item_Uom" FOREIGN KEY ("Uom_Code") REFERENCES "public"."Uom" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION ); +-- Create "Infra" table +CREATE TABLE "public"."Infra" ( + "Id" serial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(10) NULL, + "Name" character varying(50) NULL, + "InfraGroup_Code" character varying(10) NULL, + "Parent_Id" smallint NULL, + "Item_Id" bigint NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_Infra_Code" UNIQUE ("Code"), + CONSTRAINT "fk_Infra_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION +); -- Create "Device" table CREATE TABLE "public"."Device" ( "Id" bigserial NOT NULL, @@ -112,9 +127,11 @@ CREATE TABLE "public"."Device" ( "Code" character varying(10) NULL, "Name" character varying(50) NULL, "Uom_Code" character varying(10) NULL, + "Infra_Id" integer NULL, "Item_Id" bigint NULL, PRIMARY KEY ("Id"), CONSTRAINT "uni_Device_Code" UNIQUE ("Code"), + CONSTRAINT "fk_Device_Infra" FOREIGN KEY ("Infra_Id") REFERENCES "public"."Infra" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "fk_Device_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "fk_Device_Uom" FOREIGN KEY ("Uom_Code") REFERENCES "public"."Uom" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION ); @@ -239,21 +256,6 @@ CREATE TABLE "public"."DoctorFee" ( CONSTRAINT "fk_DoctorFee_Doctor" FOREIGN KEY ("Doctor_Id") REFERENCES "public"."Doctor" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "fk_DoctorFee_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION ); --- Create "Infra" table -CREATE TABLE "public"."Infra" ( - "Id" serial NOT NULL, - "CreatedAt" timestamptz NULL, - "UpdatedAt" timestamptz NULL, - "DeletedAt" timestamptz NULL, - "Code" character varying(10) NULL, - "Name" character varying(50) NULL, - "InfraGroup_Code" character varying(10) NULL, - "Parent_Id" smallint NULL, - "Item_Id" bigint NULL, - PRIMARY KEY ("Id"), - CONSTRAINT "uni_Infra_Code" UNIQUE ("Code"), - CONSTRAINT "fk_Infra_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION -); -- Create "InsuranceCompany" table CREATE TABLE "public"."InsuranceCompany" ( "Id" serial NOT NULL, @@ -291,10 +293,12 @@ CREATE TABLE "public"."Material" ( "Code" character varying(10) NULL, "Name" character varying(50) NULL, "Uom_Code" character varying(10) NULL, + "Infra_Id" integer NULL, "Stock" bigint NULL, "Item_Id" bigint NULL, PRIMARY KEY ("Id"), CONSTRAINT "uni_Material_Code" UNIQUE ("Code"), + CONSTRAINT "fk_Material_Infra" FOREIGN KEY ("Infra_Id") REFERENCES "public"."Infra" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "fk_Material_Item" FOREIGN KEY ("Item_Id") REFERENCES "public"."Item" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, CONSTRAINT "fk_Material_Uom" FOREIGN KEY ("Uom_Code") REFERENCES "public"."Uom" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION ); diff --git a/cmd/migration/migrations/atlas.sum b/cmd/migration/migrations/atlas.sum index cd54143a..c58a11d6 100644 --- a/cmd/migration/migrations/atlas.sum +++ b/cmd/migration/migrations/atlas.sum @@ -1,2 +1,2 @@ -h1:EYDfTQ6odgD5wgHGPw24RCXeKOoI17X2Bdn5MiCcftM= -20250829075746.sql h1:HZRqrJLqG8GB8W5gpmCR4Itds/Ya51xJdY57nHuXSac= +h1:GkE3HIJ9M82/ti7zJNqapdIZW4D9hFb21ii0uzbb5Es= +20250829081406.sql h1:ZLNXBAoMVVK0zib9NcgF49Ctv/f/pNrf3ciGgae8JVQ= diff --git a/internal/domain/main-entities/device/dto.go b/internal/domain/main-entities/device/dto.go index 0a9aba7a..6d21f63c 100644 --- a/internal/domain/main-entities/device/dto.go +++ b/internal/domain/main-entities/device/dto.go @@ -2,22 +2,25 @@ package device import ( ecore "simrs-vx/internal/domain/base-entities/core" + ein "simrs-vx/internal/domain/main-entities/infra" ei "simrs-vx/internal/domain/main-entities/item" eu "simrs-vx/internal/domain/main-entities/uom" ) type CreateDto struct { - Code string `json:"code"` - Name string `json:"name"` - Uom_Code string `json:"uom_code"` - Item_Id *uint `json:"item_id"` + Code string `json:"code"` + Name string `json:"name"` + Uom_Code string `json:"uom_code"` + Infra_Id *uint16 `json:"infra_id"` + Item_Id *uint `json:"item_id"` } type ReadListDto struct { - Code string `json:"code"` - Name string `json:"name"` - Uom_Code string `json:"uom_code"` - Item_Id *uint `json:"item_id"` + Code string `json:"code"` + Name string `json:"name"` + Uom_Code string `json:"uom_code"` + Infra_Id *uint16 `json:"infra_id"` + Item_Id *uint `json:"item_id"` Page int `json:"page"` PageSize int `json:"page_size"` @@ -25,11 +28,12 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code string `json:"code"` - Name string `json:"name"` - Uom_Code string `json:"uom_code"` - Item_Id *uint `json:"item_id"` + Id uint16 `json:"id"` + Code string `json:"code"` + Name string `json:"name"` + Uom_Code string `json:"uom_code"` + Infra_Id *uint16 `json:"infra_id"` + Item_Id *uint `json:"item_id"` } type UpdateDto struct { @@ -49,12 +53,14 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Code string `json:"code"` - Name string `json:"name"` - Uom_Code string `json:"uom_code"` - Uom *eu.Uom `json:"uom,omitempty"` - Item_Id *uint `json:"item_id"` - Item *ei.Item `json:"item,omitempty"` + Code string `json:"code"` + Name string `json:"name"` + Uom_Code string `json:"uom_code"` + Uom *eu.Uom `json:"uom,omitempty"` + Infra_Id *uint16 `json:"infra_id"` + Infra *ein.Infra `json:"infra,omitempty"` + Item_Id *uint `json:"item_id"` + Item *ei.Item `json:"item,omitempty"` } func (d Device) ToResponse() ResponseDto { @@ -63,6 +69,8 @@ func (d Device) ToResponse() ResponseDto { Name: d.Name, Uom_Code: d.Uom_Code, Uom: d.Uom, + Infra_Id: d.Infra_Id, + Infra: d.Infra, Item_Id: d.Item_Id, Item: d.Item, } diff --git a/internal/domain/main-entities/device/entity.go b/internal/domain/main-entities/device/entity.go index bf75c746..c9f8fdd7 100644 --- a/internal/domain/main-entities/device/entity.go +++ b/internal/domain/main-entities/device/entity.go @@ -2,16 +2,19 @@ package device import ( ecore "simrs-vx/internal/domain/base-entities/core" + ein "simrs-vx/internal/domain/main-entities/infra" ei "simrs-vx/internal/domain/main-entities/item" eu "simrs-vx/internal/domain/main-entities/uom" ) type Device struct { - ecore.Main // adjust this according to the needs - Code string `json:"code" gorm:"unique;size:10"` - Name string `json:"name" gorm:"size:50"` - Uom_Code string `json:"uom_code" gorm:"size:10"` - Uom *eu.Uom `json:"uom,omitempty" gorm:"foreignKey:Uom_Code;references:Code"` - Item_Id *uint `json:"item_id"` - Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` + ecore.Main // adjust this according to the needs + Code string `json:"code" gorm:"unique;size:10"` + Name string `json:"name" gorm:"size:50"` + Uom_Code string `json:"uom_code" gorm:"size:10"` + Uom *eu.Uom `json:"uom,omitempty" gorm:"foreignKey:Uom_Code;references:Code"` + Infra_Id *uint16 `json:"infra_id"` + Infra *ein.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Id;references:Id"` + Item_Id *uint `json:"item_id"` + Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` } diff --git a/internal/domain/main-entities/material/dto.go b/internal/domain/main-entities/material/dto.go index ec565e59..ce4311d4 100644 --- a/internal/domain/main-entities/material/dto.go +++ b/internal/domain/main-entities/material/dto.go @@ -2,24 +2,27 @@ package material import ( ecore "simrs-vx/internal/domain/base-entities/core" + ein "simrs-vx/internal/domain/main-entities/infra" ei "simrs-vx/internal/domain/main-entities/item" eu "simrs-vx/internal/domain/main-entities/uom" ) type CreateDto struct { - Code string `json:"code"` - Name string `json:"name"` - Uom_Code string `json:"uom_code"` - Stock *int `json:"stock"` - Item_Id *uint `json:"item_id"` + Code string `json:"code"` + Name string `json:"name"` + Uom_Code string `json:"uom_code"` + Infra_Id *uint16 `json:"infra_id"` + Stock *int `json:"stock"` + Item_Id *uint `json:"item_id"` } type ReadListDto struct { - Code string `json:"code"` - Name string `json:"name"` - Uom_Code string `json:"uom_code"` - Stock *int `json:"stock"` - Item_Id *uint `json:"item_id"` + Code string `json:"code"` + Name string `json:"name"` + Uom_Code string `json:"uom_code"` + Infra_Id *uint16 `json:"infra_id"` + Stock *int `json:"stock"` + Item_Id *uint `json:"item_id"` Page int `json:"page"` PageSize int `json:"page_size"` @@ -27,12 +30,13 @@ type ReadListDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code string `json:"code"` - Name string `json:"name"` - Uom_Code string `json:"uom_code"` - Stock *int `json:"stock"` - Item_Id *uint `json:"item_id"` + Id uint16 `json:"id"` + Code string `json:"code"` + Name string `json:"name"` + Uom_Code string `json:"uom_code"` + Infra_Id *uint16 `json:"infra_id"` + Stock *int `json:"stock"` + Item_Id *uint `json:"item_id"` } type UpdateDto struct { @@ -52,13 +56,15 @@ type MetaDto struct { type ResponseDto struct { ecore.Main - Code string `json:"code"` - Name string `json:"name"` - Uom_Code string `json:"uom_code"` - Uom *eu.Uom `json:"uom,omitempty"` - Stock *int `json:"stock"` - Item_Id *uint `json:"item_id"` - Item *ei.Item `json:"item,omitempty"` + Code string `json:"code"` + Name string `json:"name"` + Uom_Code string `json:"uom_code"` + Uom *eu.Uom `json:"uom,omitempty"` + Infra_Id *uint16 `json:"infra_id"` + Infra *ein.Infra `json:"infra,omitempty"` + Stock *int `json:"stock"` + Item_Id *uint `json:"item_id"` + Item *ei.Item `json:"item,omitempty"` } func (d Material) ToResponse() ResponseDto { @@ -67,6 +73,8 @@ func (d Material) ToResponse() ResponseDto { Name: d.Name, Uom_Code: d.Uom_Code, Uom: d.Uom, + Infra_Id: d.Infra_Id, + Infra: d.Infra, Stock: d.Stock, Item_Id: d.Item_Id, Item: d.Item, diff --git a/internal/domain/main-entities/material/entity.go b/internal/domain/main-entities/material/entity.go index c14aac78..cdfd8bfd 100644 --- a/internal/domain/main-entities/material/entity.go +++ b/internal/domain/main-entities/material/entity.go @@ -2,17 +2,20 @@ package material import ( ecore "simrs-vx/internal/domain/base-entities/core" + ein "simrs-vx/internal/domain/main-entities/infra" ei "simrs-vx/internal/domain/main-entities/item" eu "simrs-vx/internal/domain/main-entities/uom" ) type Material struct { - ecore.Main // adjust this according to the needs - Code string `json:"code" gorm:"unique;size:10"` - Name string `json:"name" gorm:"size:50"` - Uom_Code string `json:"uom_code" gorm:"size:10"` - Uom *eu.Uom `json:"uom,omitempty" gorm:"foreignKey:Uom_Code;references:Code"` - Stock *int `json:"stock"` - Item_Id *uint `json:"item_id"` - Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` + ecore.Main // adjust this according to the needs + Code string `json:"code" gorm:"unique;size:10"` + Name string `json:"name" gorm:"size:50"` + Uom_Code string `json:"uom_code" gorm:"size:10"` + Uom *eu.Uom `json:"uom,omitempty" gorm:"foreignKey:Uom_Code;references:Code"` + Infra_Id *uint16 `json:"infra_id"` + Infra *ein.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Id;references:Id"` + Stock *int `json:"stock"` + Item_Id *uint `json:"item_id"` + Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` }