add infra id into device and material

This commit is contained in:
dpurbosakti
2025-08-29 15:14:40 +07:00
parent 2fa3de8c53
commit c62bc414a9
6 changed files with 126 additions and 100 deletions
@@ -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
);
+2 -2
View File
@@ -1,2 +1,2 @@
h1:EYDfTQ6odgD5wgHGPw24RCXeKOoI17X2Bdn5MiCcftM=
20250829075746.sql h1:HZRqrJLqG8GB8W5gpmCR4Itds/Ya51xJdY57nHuXSac=
h1:GkE3HIJ9M82/ti7zJNqapdIZW4D9hFb21ii0uzbb5Es=
20250829081406.sql h1:ZLNXBAoMVVK0zib9NcgF49Ctv/f/pNrf3ciGgae8JVQ=
+27 -19
View File
@@ -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,
}
+10 -7
View File
@@ -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"`
}
+31 -23
View File
@@ -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,
@@ -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"`
}