diff --git a/cmd/main-migration/migrations/20251106144745.sql b/cmd/main-migration/migrations/20251106144745.sql new file mode 100644 index 00000000..4e10ec66 --- /dev/null +++ b/cmd/main-migration/migrations/20251106144745.sql @@ -0,0 +1,26 @@ +-- Create "AuthPartner" table +CREATE TABLE "public"."AuthPartner" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Code" character varying(50) NULL, + "Name" character varying(100) NULL, + "SecretKey" character varying(255) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "uni_AuthPartner_Code" UNIQUE ("Code"), + CONSTRAINT "uni_AuthPartner_Name" UNIQUE ("Name") +); +-- Create "ExtUser" table +CREATE TABLE "public"."ExtUser" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Name" character varying(100) NULL, + "AuthPartner_Code" character varying(30) NULL, + "User_Name" character varying(50) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_ExtUser_AuthPartner" FOREIGN KEY ("AuthPartner_Code") REFERENCES "public"."AuthPartner" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_ExtUser_User" FOREIGN KEY ("User_Name") REFERENCES "public"."User" ("Name") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/main-migration/migrations/20251107012049.sql b/cmd/main-migration/migrations/20251107012049.sql new file mode 100644 index 00000000..42718253 --- /dev/null +++ b/cmd/main-migration/migrations/20251107012049.sql @@ -0,0 +1,15 @@ +-- Create "UserFes" table +CREATE TABLE "public"."UserFes" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Name" character varying(100) NULL, + "AuthPartner_Code" character varying(30) NULL, + "User_Name" character varying(50) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_UserFes_AuthPartner" FOREIGN KEY ("AuthPartner_Code") REFERENCES "public"."AuthPartner" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_UserFes_User" FOREIGN KEY ("User_Name") REFERENCES "public"."User" ("Name") ON UPDATE NO ACTION ON DELETE NO ACTION +); +-- Drop "ExtUser" table +DROP TABLE "public"."ExtUser"; diff --git a/cmd/main-migration/migrations/20251107064812.sql b/cmd/main-migration/migrations/20251107064812.sql new file mode 100644 index 00000000..2e5c78cf --- /dev/null +++ b/cmd/main-migration/migrations/20251107064812.sql @@ -0,0 +1,2 @@ +-- Modify "Room" table +ALTER TABLE "public"."Room" ADD COLUMN "Infra_Coode" character varying(10) NULL, ADD COLUMN "Unit_Code" character varying(10) NULL, ADD COLUMN "Specialist_Code" character varying(10) NULL, ADD COLUMN "Subspecialist_Code" character varying(10) NULL; diff --git a/cmd/main-migration/migrations/20251107064937.sql b/cmd/main-migration/migrations/20251107064937.sql new file mode 100644 index 00000000..d1111390 --- /dev/null +++ b/cmd/main-migration/migrations/20251107064937.sql @@ -0,0 +1,2 @@ +-- Rename a column from "Infra_Coode" to "Infra_Code" +ALTER TABLE "public"."Room" RENAME COLUMN "Infra_Coode" TO "Infra_Code"; diff --git a/cmd/main-migration/migrations/20251107071420.sql b/cmd/main-migration/migrations/20251107071420.sql new file mode 100644 index 00000000..a9727884 --- /dev/null +++ b/cmd/main-migration/migrations/20251107071420.sql @@ -0,0 +1,6 @@ +-- Modify "Infra" table +ALTER TABLE "public"."Infra" ADD COLUMN "Parent_Code" character varying(10) NULL, ADD COLUMN "Item_Code" character varying(50) NULL; +-- Create index "idx_Infra_Code" to table: "Infra" +CREATE UNIQUE INDEX "idx_Infra_Code" ON "public"."Infra" ("Code"); +-- Modify "Room" table +ALTER TABLE "public"."Room" DROP CONSTRAINT "fk_Room_Specialist", DROP CONSTRAINT "fk_Room_Subspecialist", DROP CONSTRAINT "fk_Room_Unit", DROP COLUMN "Infra_Id", DROP COLUMN "Unit_Id", DROP COLUMN "Specialist_Id", DROP COLUMN "Subspecialist_Id", ADD CONSTRAINT "fk_Room_Specialist" FOREIGN KEY ("Specialist_Code") REFERENCES "public"."Specialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Room_Subspecialist" FOREIGN KEY ("Subspecialist_Code") REFERENCES "public"."Subspecialist" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Room_Unit" FOREIGN KEY ("Unit_Code") REFERENCES "public"."Unit" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251107074318.sql b/cmd/main-migration/migrations/20251107074318.sql new file mode 100644 index 00000000..5156b74e --- /dev/null +++ b/cmd/main-migration/migrations/20251107074318.sql @@ -0,0 +1,4 @@ +-- Modify "Nurse" table +ALTER TABLE "public"."Nurse" DROP CONSTRAINT "fk_Nurse_Infra"; +-- Modify "Infra" table +ALTER TABLE "public"."Infra" DROP CONSTRAINT "uni_Infra_Code"; diff --git a/cmd/main-migration/migrations/20251107075050.sql b/cmd/main-migration/migrations/20251107075050.sql new file mode 100644 index 00000000..fee27fee --- /dev/null +++ b/cmd/main-migration/migrations/20251107075050.sql @@ -0,0 +1,4 @@ +-- Modify "Nurse" table +ALTER TABLE "public"."Nurse" ADD CONSTRAINT "fk_Nurse_Infra" FOREIGN KEY ("Infra_Code") REFERENCES "public"."Infra" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; +-- Modify "Room" table +ALTER TABLE "public"."Room" ADD CONSTRAINT "fk_Room_Infra" FOREIGN KEY ("Infra_Code") REFERENCES "public"."Infra" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251107080604.sql b/cmd/main-migration/migrations/20251107080604.sql new file mode 100644 index 00000000..246be1fa --- /dev/null +++ b/cmd/main-migration/migrations/20251107080604.sql @@ -0,0 +1,2 @@ +-- Modify "Item" table +ALTER TABLE "public"."Item" ADD COLUMN "Infra_Code" character varying(10) NULL; diff --git a/cmd/main-migration/migrations/20251107081830.sql b/cmd/main-migration/migrations/20251107081830.sql new file mode 100644 index 00000000..a7490211 --- /dev/null +++ b/cmd/main-migration/migrations/20251107081830.sql @@ -0,0 +1,6 @@ +-- Modify "Device" table +ALTER TABLE "public"."Device" ADD COLUMN "Infra_Code" character varying(10) NULL, ADD COLUMN "Item_Code" character varying(50) NULL; +-- Modify "Material" table +ALTER TABLE "public"."Material" ADD COLUMN "Infra_Code" character varying(10) NULL, ADD COLUMN "Item_Code" character varying(50) NULL; +-- Modify "Medicine" table +ALTER TABLE "public"."Medicine" ADD COLUMN "Infra_Code" character varying(10) NULL, ADD COLUMN "Item_Code" character varying(50) NULL; diff --git a/cmd/main-migration/migrations/20251107091033.sql b/cmd/main-migration/migrations/20251107091033.sql new file mode 100644 index 00000000..dc0a8f60 --- /dev/null +++ b/cmd/main-migration/migrations/20251107091033.sql @@ -0,0 +1,4 @@ +-- Modify "Infra" table +ALTER TABLE "public"."Infra" ALTER COLUMN "Code" SET NOT NULL; +-- Modify "Item" table +ALTER TABLE "public"."Item" DROP COLUMN "Infra_Id"; diff --git a/cmd/main-migration/migrations/20251107091209.sql b/cmd/main-migration/migrations/20251107091209.sql new file mode 100644 index 00000000..d10ae684 --- /dev/null +++ b/cmd/main-migration/migrations/20251107091209.sql @@ -0,0 +1,2 @@ +-- Modify "Infra" table +ALTER TABLE "public"."Infra" DROP CONSTRAINT "fk_Infra_Childrens", DROP CONSTRAINT "fk_Infra_Item", DROP COLUMN "Parent_Id", ADD CONSTRAINT "fk_Infra_Childrens" FOREIGN KEY ("Parent_Code") REFERENCES "public"."Infra" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION, ADD CONSTRAINT "fk_Infra_Item" FOREIGN KEY ("Item_Code") REFERENCES "public"."Item" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION; diff --git a/cmd/main-migration/migrations/20251107091541.sql b/cmd/main-migration/migrations/20251107091541.sql new file mode 100644 index 00000000..a3445d0c --- /dev/null +++ b/cmd/main-migration/migrations/20251107091541.sql @@ -0,0 +1,2 @@ +-- Modify "Infra" table +ALTER TABLE "public"."Infra" DROP COLUMN "Item_Id"; diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index dc9df4a2..30f9fd3c 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:Jut0rnI38bZU7g1hei5bIcYGzWrt4KxfWzasGJcbwi0= +h1:6umIsneejLUg0V9wUaB2HuCvEHD+2v/dwbxg+y23+wo= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -75,11 +75,23 @@ h1:Jut0rnI38bZU7g1hei5bIcYGzWrt4KxfWzasGJcbwi0= 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= +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:jjpcAi0B/geEOKWmmR6+1UhWMhjstWhWQcz9lUWrtTY= +20251107064937.sql h1:1nPu0THBf+YquFIJSE4pc1dA7r3EydH92cpp26ozysw= +20251107071420.sql h1:Q+e+OqjdiuK/sghDQ5NxjU+u2zYl+vh/eRBlUz9Idhg= +20251107074318.sql h1:VbOWMw2rClEWgMnDSejXPqXkFoQ4odVsHn3/UAEiCYA= +20251107075050.sql h1:ZZaKJEWXIJ94/0/2Gzzz+HXjmebEs5eP8iUIot26/c8= +20251107080604.sql h1:aq+tINa0ULCZlJcUK2jaeGh6rRH4jJz3e2NrK47m0Ec= +20251107081830.sql h1:Bl9kniyLWeMqd3nrvgCgiUpdcJWp8qX1F41JAM1WbiE= +20251107091033.sql h1:ETTCaAHBT6wipXrEGXIepxLMdD2LNzprPAp99+jnW0w= +20251107091209.sql h1:BUI9JlTzZxCdVHsrRbOye7m47AJEvXNhCaCVv/HzILs= +20251107091541.sql h1:/tW2uXv/o0Q2E4lQzlYNgEftvDqjf3c2AQpZ83Vb6zc= diff --git a/internal/domain/main-entities/auth-partner/dto.go b/internal/domain/main-entities/auth-partner/dto.go new file mode 100644 index 00000000..2b1589fb --- /dev/null +++ b/internal/domain/main-entities/auth-partner/dto.go @@ -0,0 +1,70 @@ +package authpartner + +import ( + // internal - domain - main-entities + ecore "simrs-vx/internal/domain/base-entities/core" +) + +type CreateDto struct { + Code string `json:"code"` + Name string `json:"name"` + SecretKey string `json:"secretKey"` +} + +type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Pagination ecore.Pagination + Sort string `json:"sort"` +} + +type FilterDto struct { + Code *string `json:"code"` + Name *string `json:"name"` +} + +type ReadDetailDto struct { + Id *uint16 `json:"id"` + Code *string `json:"code"` + Includes string `json:"includes"` +} + +type UpdateDto struct { + Id uint16 `json:"id"` + CreateDto +} + +type DeleteDto struct { + Id uint16 `json:"id"` +} + +type MetaDto struct { + PageNumber int `json:"page_number"` + PageSize int `json:"page_size"` + Count int `json:"count"` +} + +type ResponseDto struct { + ecore.Main + Code string `json:"code"` + Name string `json:"name"` + SecretKey string `json:"secretKey"` +} + +func (d AuthPartner) ToResponse() ResponseDto { + resp := ResponseDto{ + Code: d.Code, + Name: d.Name, + SecretKey: d.SecretKey, + } + resp.Main = d.Main + return resp +} + +func ToResponseList(data []AuthPartner) []ResponseDto { + resp := make([]ResponseDto, len(data)) + for i, u := range data { + resp[i] = u.ToResponse() + } + return resp +} diff --git a/internal/domain/main-entities/auth-partner/entity.go b/internal/domain/main-entities/auth-partner/entity.go new file mode 100644 index 00000000..b4ad8e49 --- /dev/null +++ b/internal/domain/main-entities/auth-partner/entity.go @@ -0,0 +1,12 @@ +package authpartner + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" +) + +type AuthPartner struct { + ecore.Main // adjust this according to the needs + Code string `json:"code" gorm:"unique;size:50"` + Name string `json:"name" gorm:"unique;size:100"` + SecretKey string `json:"secretKey" gorm:"size:255"` +} diff --git a/internal/domain/main-entities/device/dto.go b/internal/domain/main-entities/device/dto.go index 1c874576..36e90a0c 100644 --- a/internal/domain/main-entities/device/dto.go +++ b/internal/domain/main-entities/device/dto.go @@ -8,11 +8,11 @@ import ( ) type CreateDto struct { - Code string `json:"code" validate:"maxLength=10"` - Name string `json:"name" validate:"maxLength=50"` - Uom_Code string `json:"uom_code" validate:"maxLength=10"` - Infra_Id *uint16 `json:"infra_id"` - Item_Id *uint `json:"item_id"` + Code string `json:"code" validate:"maxLength=10"` + Name string `json:"name" validate:"maxLength=50"` + Uom_Code string `json:"uom_code" validate:"maxLength=10"` + Infra_Code *string `json:"infra_code"` + Item_Code *string `json:"item_code"` } type ReadListDto struct { @@ -32,17 +32,18 @@ type FilterDto struct { } type ReadDetailDto struct { - Id uint16 `json:"id"` + 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 { diff --git a/internal/domain/main-entities/device/entity.go b/internal/domain/main-entities/device/entity.go index ca54c08d..c68b7c3e 100644 --- a/internal/domain/main-entities/device/entity.go +++ b/internal/domain/main-entities/device/entity.go @@ -14,7 +14,9 @@ type Device struct { 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_Code *string `json:"infra_code" gorm:"size:10"` Infra *ein.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Id;references:Id"` Item_Id *uint `json:"item_id"` + Item_Code *string `json:"item_code" gorm:"size:50"` Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` } diff --git a/internal/domain/main-entities/infra/dto.go b/internal/domain/main-entities/infra/dto.go index de566fad..dfe271e5 100644 --- a/internal/domain/main-entities/infra/dto.go +++ b/internal/domain/main-entities/infra/dto.go @@ -9,15 +9,15 @@ import ( ) type CreateDto struct { - Code string `json:"code" validate:"maxLength=10"` - Name string `json:"name" validate:"maxLength=50"` - InfraGroup_Code ero.InfraGroupCode `json:"infraGroup_code" validate:"maxLength=15"` - Parent_Id *uint16 `json:"parent_id"` - Item_Id *uint `json:"item_id"` - Unit_Id *uint16 `json:"unit_id"` - Specialist_Id *uint16 `json:"specialist_id"` - Subspecialist_Id *uint16 `json:"subspecialist_id"` - Infra_Id *uint16 `json:"-"` // for room + Code string `json:"code" validate:"maxLength=10"` + Name string `json:"name" validate:"maxLength=50"` + InfraGroup_Code ero.InfraGroupCode `json:"infraGroup_code" validate:"maxLength=15"` + Parent_Code *string `json:"parent_code"` + Item_Code *string `json:"-"` + Unit_Code *string `json:"unit_code"` + Specialist_Code *string `json:"specialist_code"` + Subspecialist_Code *string `json:"subspecialist_code"` + Infra_Code *string `json:"infra_code"` // for room } type ReadListDto struct { @@ -32,24 +32,25 @@ type FilterDto struct { Code string `json:"code"` Name string `json:"name"` InfraGroup_Code ero.InfraGroupCode `json:"infraGroup-code"` - Parent_Id *uint16 `json:"parent-id"` - Item_Id *uint `json:"item-id"` + Parent_Code *string `json:"parent-code"` + Item_Id *string `json:"item-code"` Search string `json:"search" gormhelper:"searchColumns=Code,Name"` } type ReadDetailDto struct { - Id uint16 `json:"id"` - Code *string `json:"code"` - Item_Id *uint `json:"item_id"` + Id *uint16 `json:"id"` + Code *string `json:"code"` + Item_Code *string `json:"item_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 { @@ -63,10 +64,10 @@ type ResponseDto struct { Code string `json:"code"` Name string `json:"name"` InfraGroup_Code ero.InfraGroupCode `json:"infraGroup_code"` - Parent_Id *uint16 `json:"parent_id"` + Parent_Code *string `json:"parent_code"` Parent *Infra `json:"parent,omitempty"` Childrens []Infra `json:"childrens,omitempty"` - Item_Id *uint `json:"item_id"` + Item_Code *string `json:"item_code"` Item *ei.Item `json:"item,omitempty"` Rooms []erb.Basic `json:"rooms,omitempty"` } @@ -76,12 +77,12 @@ func (d Infra) ToResponse() ResponseDto { Code: d.Code, Name: d.Name, InfraGroup_Code: d.InfraGroup_Code, - Parent_Id: d.Parent_Id, - Parent: d.Parent, - Childrens: d.Childrens, - Item_Id: d.Item_Id, - Item: d.Item, - Rooms: d.Rooms, + Parent_Code: d.Parent_Code, + // Parent: d.Parent, + Childrens: d.Childrens, + Item_Code: d.Item_Code, + Item: d.Item, + Rooms: d.Rooms, } resp.SmallMain = d.SmallMain return resp diff --git a/internal/domain/main-entities/infra/entity.go b/internal/domain/main-entities/infra/entity.go index 3d8c6f99..51cc8eaa 100644 --- a/internal/domain/main-entities/infra/entity.go +++ b/internal/domain/main-entities/infra/entity.go @@ -3,6 +3,7 @@ package infra import ( ecore "simrs-vx/internal/domain/base-entities/core" ei "simrs-vx/internal/domain/main-entities/item" + erb "simrs-vx/internal/domain/main-entities/room/base" ero "simrs-vx/internal/domain/references/organization" @@ -10,13 +11,13 @@ import ( type Infra struct { ecore.SmallMain // adjust this according to the needs - Code string `json:"code" gorm:"unique;size:10"` + Code string `json:"code" gorm:"uniqueIndex;size:10;not null"` Name string `json:"name" gorm:"size:50"` InfraGroup_Code ero.InfraGroupCode `json:"infraGroup_code" gorm:"size:15"` - Parent_Id *uint16 `json:"parent_id"` - Parent *Infra `json:"parent" gorm:"foreignKey:Parent_Id;references:Id"` - Childrens []Infra `json:"childrens" gorm:"foreignKey:Parent_Id"` // may need references to self - Item_Id *uint `json:"item_id"` - Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` - Rooms []erb.Basic `json:"rooms" gorm:"foreignKey:Infra_Id"` + Parent_Code *string `json:"parent_code" gorm:"size:10"` + Parent *Infra `json:"parent" gorm:"foreignKey:Parent_Code;references:Code"` + Childrens []Infra `json:"childrens" gorm:"foreignKey:Parent_Code;references:Code"` + Item_Code *string `json:"item_code" gorm:"size:50"` + Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Code;references:Code"` + Rooms []erb.Basic `json:"rooms" gorm:"foreignKey:Infra_Code;references:Code"` } diff --git a/internal/domain/main-entities/item/dto.go b/internal/domain/main-entities/item/dto.go index 22be4c1a..f20ce217 100644 --- a/internal/domain/main-entities/item/dto.go +++ b/internal/domain/main-entities/item/dto.go @@ -11,7 +11,7 @@ type CreateDto struct { Name string `json:"name" validate:"maxLength=100"` ItemGroup_Code ero.ItemGroupCode `json:"itemGroup_code" validate:"maxLength=10"` Uom_Code *string `json:"uom_code" validate:"maxLength=10"` - Infra_Id *uint16 `json:"infra_id"` + Infra_Code *string `json:"infra_code"` Stock *int `json:"stock"` } @@ -27,23 +27,24 @@ type FilterDto struct { Name string `json:"name"` ItemGroup_Code ero.ItemGroupCode `json:"itemGroup-code"` Uom_Code *string `json:"uom-code"` - Infra_Id *uint16 `json:"infra-id"` + Infra_Code *string `json:"infra-code"` Stock *int `json:"stock"` 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 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 { @@ -59,7 +60,7 @@ type ResponseDto struct { ItemGroup_Code ero.ItemGroupCode `json:"itemGroup_code"` Uom_Code *string `json:"uom_code"` Uom *eu.Uom `json:"uom,omitempty"` - Infra_Id *uint16 `json:"infra_id"` + Infra_Code *string `json:"infra_code"` Stock *int `json:"stock"` } @@ -70,7 +71,7 @@ func (d Item) ToResponse() ResponseDto { ItemGroup_Code: d.ItemGroup_Code, Uom_Code: d.Uom_Code, Uom: d.Uom, - Infra_Id: d.Infra_Id, + Infra_Code: d.Infra_Code, Stock: d.Stock, } resp.Main = d.Main diff --git a/internal/domain/main-entities/item/entity.go b/internal/domain/main-entities/item/entity.go index e0ff4e21..fc721713 100644 --- a/internal/domain/main-entities/item/entity.go +++ b/internal/domain/main-entities/item/entity.go @@ -14,6 +14,6 @@ type Item struct { ItemGroup_Code ero.ItemGroupCode `json:"itemGroup_code" gorm:"size:15"` 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_Code *string `json:"infra_code" gorm:"size:10"` Stock *int `json:"stock"` } diff --git a/internal/domain/main-entities/material/dto.go b/internal/domain/main-entities/material/dto.go index 18a93723..fbedbf43 100644 --- a/internal/domain/main-entities/material/dto.go +++ b/internal/domain/main-entities/material/dto.go @@ -8,12 +8,12 @@ import ( ) type CreateDto struct { - Code string `json:"code" validate:"maxLength=10"` - Name string `json:"name" validate:"maxLength=50"` - Uom_Code string `json:"uom_code" validate:"maxLength=10"` - Infra_Id *uint16 `json:"infra_id"` - Stock *int `json:"stock"` - Item_Id *uint `json:"item_id"` + Code string `json:"code" validate:"maxLength=10"` + Name string `json:"name" validate:"maxLength=50"` + Uom_Code string `json:"uom_code" validate:"maxLength=10"` + Infra_Code *string `json:"infra_code"` + Stock *int `json:"stock"` + Item_Code *string `json:"item_code"` } type ReadListDto struct { @@ -24,28 +24,29 @@ type ReadListDto struct { } type FilterDto struct { - 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"` - Search string `json:"search" gormhelper:"searchColumns=Code,Name"` + Code string `json:"code"` + Name string `json:"name"` + Uom_Code string `json:"uom-code"` + Infra_Code *string `json:"infra-code"` + Stock *int `json:"stock"` + Item_Code *string `json:"item-code"` + Search string `json:"search" gormhelper:"searchColumns=Code,Name"` } type ReadDetailDto struct { - Id uint16 `json:"id"` + Id *uint16 `json:"id"` Code *string `json:"code"` Item_Id *uint `json:"item_id"` } 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 { @@ -56,28 +57,28 @@ 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"` - 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"` + Code string `json:"code"` + Name string `json:"name"` + Uom_Code string `json:"uom_code"` + Uom *eu.Uom `json:"uom,omitempty"` + Infra_Code *string `json:"infra_code"` + Infra *ein.Infra `json:"infra,omitempty"` + Stock *int `json:"stock"` + Item_Code *string `json:"item_code"` + Item *ei.Item `json:"item,omitempty"` } func (d Material) ToResponse() ResponseDto { resp := ResponseDto{ - Code: d.Code, - 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, + Code: d.Code, + Name: d.Name, + Uom_Code: d.Uom_Code, + Uom: d.Uom, + Infra_Code: d.Infra_Code, + Infra: d.Infra, + Stock: d.Stock, + Item_Code: d.Item_Code, + Item: d.Item, } resp.Main = d.Main return resp diff --git a/internal/domain/main-entities/material/entity.go b/internal/domain/main-entities/material/entity.go index cdfd8bfd..50e6907e 100644 --- a/internal/domain/main-entities/material/entity.go +++ b/internal/domain/main-entities/material/entity.go @@ -14,8 +14,10 @@ type Material struct { 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_Code *string `json:"infra_code" gorm:"size:10"` Infra *ein.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Id;references:Id"` Stock *int `json:"stock"` Item_Id *uint `json:"item_id"` + Item_Code *string `json:"item_code" gorm:"size:50"` Item *ei.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` } diff --git a/internal/domain/main-entities/medicine/dto.go b/internal/domain/main-entities/medicine/dto.go index 82431fc1..945db1e5 100644 --- a/internal/domain/main-entities/medicine/dto.go +++ b/internal/domain/main-entities/medicine/dto.go @@ -16,9 +16,9 @@ type CreateDto struct { MedicineMethod_Code *string `json:"medicineMethod_code" validate:"maxLength=10"` Uom_Code *string `json:"uom_code" validate:"maxLength=10"` Dose uint8 `json:"dose"` - Infra_Id *uint16 `json:"infra_id"` + Infra_Code *string `json:"infra_code"` Stock *int `json:"stock"` - Item_Id *uint `json:"item_id"` + Item_Code *string `json:"item_code"` } type ReadListDto struct { @@ -35,25 +35,26 @@ type FilterDto struct { MedicineMethod_Code *string `json:"medicineMethod-code"` Uom_Code *string `json:"uom-code"` Dose uint8 `json:"dose"` - Infra_Id *uint16 `json:"infra-id"` + Infra_Code *string `json:"infra-code"` Stock *int `json:"stock"` - Item_Id *uint `json:"item-id"` + 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"` - Item_Id *uint `json:"item_id"` + Id *uint16 `json:"id"` + Code *string `json:"code"` + Item_Code *uint `json:"item_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 { @@ -73,10 +74,10 @@ type ResponseDto struct { Uom_Code *string `json:"uom_code"` Uom *eu.Uom `json:"uom"` Dose uint8 `json:"dose"` - Infra_Id *uint16 `json:"infra_id"` + Infra_Code *string `json:"infra_code"` Infra *ein.Infra `json:"infra,omitempty"` Stock *int `json:"stock"` - Item_Id *uint `json:"item_id"` + Item_Code *string `json:"item_code"` Item *eit.Item `json:"item,omitempty"` } @@ -91,10 +92,10 @@ func (d Medicine) ToResponse() ResponseDto { Uom_Code: d.Uom_Code, Uom: d.Uom, Dose: d.Dose, - Infra_Id: d.Infra_Id, + Infra_Code: d.Infra_Code, Infra: d.Infra, Stock: d.Stock, - Item_Id: d.Item_Id, + Item_Code: d.Item_Code, Item: d.Item, } resp.Main = d.Main diff --git a/internal/domain/main-entities/medicine/entity.go b/internal/domain/main-entities/medicine/entity.go index d538f496..bbcfec78 100644 --- a/internal/domain/main-entities/medicine/entity.go +++ b/internal/domain/main-entities/medicine/entity.go @@ -21,8 +21,10 @@ type Medicine struct { Uom *eu.Uom `json:"uom" gorm:"foreignKey:Uom_Code;references:Code"` Dose uint8 `json:"dose"` Infra_Id *uint16 `json:"infra_id"` + Infra_Code *string `json:"infra_code" gorm:"size:10"` Infra *ein.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Id;references:Id"` Stock *int `json:"stock"` Item_Id *uint `json:"item_id"` + Item_Code *string `json:"item_code" gorm:"size:50"` Item *eit.Item `json:"item,omitempty" gorm:"foreignKey:Item_Id;references:Id"` } diff --git a/internal/domain/main-entities/room/base/entity.go b/internal/domain/main-entities/room/base/entity.go index e45a441d..d5651ac9 100644 --- a/internal/domain/main-entities/room/base/entity.go +++ b/internal/domain/main-entities/room/base/entity.go @@ -8,14 +8,14 @@ import ( ) type Basic struct { - ecore.SmallMain // adjust this according to the needs - Infra_Id *uint16 `json:"infra_id"` - Unit_Id *uint16 `json:"unit_id"` - Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Id"` - Specialist_Id *uint16 `json:"specialist_id"` - Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Id"` - Subspecialist_Id *uint16 `json:"subspecialist_id"` - Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Id"` + ecore.SmallMain // adjust this according to the needs + Infra_Code *string `json:"infra_code" gorm:"size:10"` + Unit_Code *string `json:"unit_code" gorm:"size:10"` + Unit *eu.Unit `json:"unit,omitempty" gorm:"foreignKey:Unit_Code;references:Code"` + Specialist_Code *string `json:"specialist_code" gorm:"size:10"` + Specialist *es.Specialist `json:"specialist,omitempty" gorm:"foreignKey:Specialist_Code;references:Code"` + Subspecialist_Code *string `json:"subspecialist_code" gorm:"size:10"` + Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty" gorm:"foreignKey:Subspecialist_Code;references:Code"` } func (Basic) TableName() string { diff --git a/internal/domain/main-entities/room/dto.go b/internal/domain/main-entities/room/dto.go index 0ca2e8d4..2ff41c3a 100644 --- a/internal/domain/main-entities/room/dto.go +++ b/internal/domain/main-entities/room/dto.go @@ -9,10 +9,10 @@ import ( ) type CreateDto struct { - Infra_Id *uint16 `json:"infra_id"` - Unit_Id *uint16 `json:"unit_id"` - Specialist_Id *uint16 `json:"specialist_id"` - Subspecialist_Id *uint16 `json:"subspecialist_id"` + Infra_Code *string `json:"infra_code"` + Unit_Code *string `json:"unit_code"` + Specialist_Code *string `json:"specialist_code"` + Subspecialist_Code *string `json:"subspecialist_code"` } type ReadListDto struct { @@ -22,10 +22,10 @@ type ReadListDto struct { } type FilterDto struct { - Infra_Id *uint16 `json:"infra-id"` - Unit_Id *uint16 `json:"unit-id"` - Specialist_Id *uint16 `json:"specialist-id"` - Subspecialist_Id *uint16 `json:"subspecialist-id"` + Infra_Code *string `json:"infra-code"` + Unit_Code *string `json:"unit-code"` + Specialist_Code *string `json:"specialist-code"` + Subspecialist_Code *string `json:"subspecialist-code"` } type ReadDetailDto struct { @@ -49,26 +49,26 @@ type MetaDto struct { type ResponseDto struct { ecore.SmallMain - Infra_Id *uint16 `json:"infra_id"` - Infra *ei.Infra `json:"infra,omitempty"` - Unit_Id *uint16 `json:"unit_id"` - Unit *eu.Unit `json:"unit,omitempty"` - Specialist_Id *uint16 `json:"specialist_id"` - Specialist *es.Specialist `json:"specialist,omitempty"` - Subspecialist_Id *uint16 `json:"subspecialist_id"` - Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty"` + Infra_Code *string `json:"infra_code"` + Infra *ei.Infra `json:"infra,omitempty"` + Unit_Code *string `json:"unit_code"` + Unit *eu.Unit `json:"unit,omitempty"` + Specialist_Code *string `json:"specialist_code"` + Specialist *es.Specialist `json:"specialist,omitempty"` + Subspecialist_Code *string `json:"subspecialist_code"` + Subspecialist *ess.Subspecialist `json:"subspecialist,omitempty"` } func (d Room) ToResponse() ResponseDto { resp := ResponseDto{ - Infra_Id: d.Infra_Id, - Infra: d.Infra, - Unit_Id: d.Unit_Id, - Unit: d.Unit, - Specialist_Id: d.Specialist_Id, - Specialist: d.Specialist, - Subspecialist_Id: d.Subspecialist_Id, - Subspecialist: d.Subspecialist, + Infra_Code: d.Infra_Code, + Infra: d.Infra, + Unit_Code: d.Unit_Code, + Unit: d.Unit, + Specialist_Code: d.Specialist_Code, + Specialist: d.Specialist, + Subspecialist_Code: d.Subspecialist_Code, + Subspecialist: d.Subspecialist, } resp.SmallMain = d.SmallMain return resp diff --git a/internal/domain/main-entities/room/entity.go b/internal/domain/main-entities/room/entity.go index 346c7741..49fb8cc6 100644 --- a/internal/domain/main-entities/room/entity.go +++ b/internal/domain/main-entities/room/entity.go @@ -7,5 +7,5 @@ import ( type Room struct { ebase.Basic - Infra *ei.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Id"` + Infra *ei.Infra `json:"infra,omitempty" gorm:"foreignKey:Infra_Code;references:Code"` } diff --git a/internal/domain/main-entities/user-fes/dto.go b/internal/domain/main-entities/user-fes/dto.go new file mode 100644 index 00000000..6cb3636b --- /dev/null +++ b/internal/domain/main-entities/user-fes/dto.go @@ -0,0 +1,75 @@ +// FES = From External Source +package userfes + +import ( + // internal - domain - main-entities + ecore "simrs-vx/internal/domain/base-entities/core" + eap "simrs-vx/internal/domain/main-entities/auth-partner" +) + +type CreateDto struct { + Name string `json:"name"` + AuthPartner_Code string `json:"authPartner_code"` + User_Name string `json:"user_name"` +} + +type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Pagination ecore.Pagination + Sort string `json:"sort"` +} + +type FilterDto struct { + Name *string `json:"name"` + AuthPartner_Code *string `json:"authPartner_code"` + User_Name *string `json:"user_name"` + Includes string `json:"includes"` +} + +type ReadDetailDto struct { + Id uint `json:"id"` + Includes string `json:"includes"` +} + +type UpdateDto struct { + Id uint `json:"id"` + CreateDto +} + +type DeleteDto struct { + Id uint `json:"id"` +} + +type MetaDto struct { + PageNumber int `json:"page_number"` + PageSize int `json:"page_size"` + Count int `json:"count"` +} + +type ResponseDto struct { + ecore.Main + Name string `json:"name"` + AuthPartner_Code string `json:"authPartner_code"` + AuthPartner *eap.AuthPartner `json:"authPartner,omitempty"` + User_Name string `json:"user_name"` +} + +func (d UserFes) ToResponse() ResponseDto { + resp := ResponseDto{ + Name: d.Name, + AuthPartner_Code: d.AuthPartner_Code, + AuthPartner: d.AuthPartner, + User_Name: d.User_Name, + } + resp.Main = d.Main + return resp +} + +func ToResponseList(data []UserFes) []ResponseDto { + resp := make([]ResponseDto, len(data)) + for i, u := range data { + resp[i] = u.ToResponse() + } + return resp +} diff --git a/internal/domain/main-entities/user-fes/entity.go b/internal/domain/main-entities/user-fes/entity.go new file mode 100644 index 00000000..7356166c --- /dev/null +++ b/internal/domain/main-entities/user-fes/entity.go @@ -0,0 +1,17 @@ +// FES = From External Source +package userfes + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" + eap "simrs-vx/internal/domain/main-entities/auth-partner" + eau "simrs-vx/internal/domain/main-entities/user" +) + +type UserFes struct { + ecore.Main // adjust this according to the needs + Name string `json:"name" gorm:"size:100"` + AuthPartner_Code string `json:"authPartner_code" gorm:"size:30"` + AuthPartner *eap.AuthPartner `json:"authPartner,omitempty" gorm:"foreignKey:AuthPartner_Code;references:Code"` + User_Name string `json:"user_name" gorm:"size:50"` + User *eau.User `json:"user,omitempty" gorm:"foreignKey:User_Name;references:Name"` +} diff --git a/internal/interface/main-handler/device/handler.go b/internal/interface/main-handler/device/handler.go index 1a3cb18d..c827f20f 100644 --- a/internal/interface/main-handler/device/handler.go +++ b/internal/interface/main-handler/device/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/interface/main-handler/infra/handler.go b/internal/interface/main-handler/infra/handler.go index 71a8f1ec..fedccf48 100644 --- a/internal/interface/main-handler/infra/handler.go +++ b/internal/interface/main-handler/infra/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/item/handler.go b/internal/interface/main-handler/item/handler.go index 124be7ef..a786e86b 100644 --- a/internal/interface/main-handler/item/handler.go +++ b/internal/interface/main-handler/item/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/interface/main-handler/main-handler.go b/internal/interface/main-handler/main-handler.go index 925f9dc6..6d0548e9 100644 --- a/internal/interface/main-handler/main-handler.go +++ b/internal/interface/main-handler/main-handler.go @@ -36,7 +36,9 @@ import ( /******************** actor ********************/ + doctor "simrs-vx/internal/interface/main-handler/doctor" employee "simrs-vx/internal/interface/main-handler/employee" + nurse "simrs-vx/internal/interface/main-handler/nurse" nutritionist "simrs-vx/internal/interface/main-handler/nutritionist" patient "simrs-vx/internal/interface/main-handler/patient" person "simrs-vx/internal/interface/main-handler/person" @@ -267,6 +269,8 @@ func SetRoutes() http.Handler { hc.RegCrud(r, "/v1/person-contact", personcontact.O) hc.RegCrud(r, "/v1/person-insurance", personinsurance.O) hc.RegCrud(r, "/v1/employee", employee.O) + hc.RegCrudByCode(r, "/v1/doctor", doctor.O) + hc.RegCrudByCode(r, "/v1/nurse", nurse.O) hc.RegCrud(r, "/v1/nutritionist", nutritionist.O) hc.RegCrud(r, "/v1/pharmacist", pharmacist.O) hk.GroupRoutes("/v1/user", r, hk.MapHandlerFunc{ @@ -300,22 +304,22 @@ func SetRoutes() http.Handler { hc.RegCrudByCode(r, "/v1/subspecialist", subspecialist.O) hc.RegCrudByCode(r, "/v1/specialist-position", specialistposition.O) hc.RegCrudByCode(r, "/v1/subspecialist-position", subspecialistposition.O) + hc.RegCrudByCode(r, "/v1/infra", infra.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) hc.RegCrud(r, "/v1/uom", uom.O) - hc.RegCrud(r, "/v1/item", item.O) + hc.RegCrudByCode(r, "/v1/item", item.O) hc.RegCrud(r, "/v1/item-price", itemprice.O) - hc.RegCrud(r, "/v1/infra", infra.O) 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.RegCrud(r, "/v1/ethnic", ethnic.O) hc.RegCrud(r, "/v1/insurance-company", insurancecompany.O) - hc.RegCrud(r, "/v1/medicine", medicine.O) - hc.RegCrud(r, "/v1/device", device.O) - hc.RegCrud(r, "/v1/material", material.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.RegCrud(r, "/v1/medical-action-src-item", medicalactionsrcitem.O) diff --git a/internal/interface/main-handler/material/handler.go b/internal/interface/main-handler/material/handler.go index 2b152625..10de8a92 100644 --- a/internal/interface/main-handler/material/handler.go +++ b/internal/interface/main-handler/material/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/interface/main-handler/medicine/handler.go b/internal/interface/main-handler/medicine/handler.go index 5a5b28e0..b6a3f185 100644 --- a/internal/interface/main-handler/medicine/handler.go +++ b/internal/interface/main-handler/medicine/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/interface/migration/main-entities.go b/internal/interface/migration/main-entities.go index af9fe034..f6c251c0 100644 --- a/internal/interface/migration/main-entities.go +++ b/internal/interface/migration/main-entities.go @@ -8,6 +8,7 @@ import ( antibioticinuse "simrs-vx/internal/domain/main-entities/antibiotic-in-use" antibioticsrccategory "simrs-vx/internal/domain/main-entities/antibiotic-src-category" appointment "simrs-vx/internal/domain/main-entities/appointment" + authpartner "simrs-vx/internal/domain/main-entities/auth-partner" chemo "simrs-vx/internal/domain/main-entities/chemo" chemoprotocol "simrs-vx/internal/domain/main-entities/chemo-protocol" consultation "simrs-vx/internal/domain/main-entities/consultation" @@ -92,6 +93,7 @@ import ( unitposition "simrs-vx/internal/domain/main-entities/unit-position" uom "simrs-vx/internal/domain/main-entities/uom" user "simrs-vx/internal/domain/main-entities/user" + userfes "simrs-vx/internal/domain/main-entities/user-fes" vehicle "simrs-vx/internal/domain/main-entities/vehicle" vehiclehist "simrs-vx/internal/domain/main-entities/vehicle-hist" village "simrs-vx/internal/domain/main-entities/village" @@ -105,7 +107,9 @@ import ( func getMainEntities() []any { return []any{ + &authpartner.AuthPartner{}, &user.User{}, + &userfes.UserFes{}, &division.Division{}, &divisionposition.DivisionPosition{}, &installation.Installation{}, diff --git a/internal/use-case/main-use-case/authentication/case.go b/internal/use-case/main-use-case/authentication/case.go index 6a980d71..6cf94142 100644 --- a/internal/use-case/main-use-case/authentication/case.go +++ b/internal/use-case/main-use-case/authentication/case.go @@ -9,28 +9,28 @@ import ( "github.com/golang-jwt/jwt" "github.com/google/uuid" - - "simrs-vx/internal/domain/main-entities/intern" - eu "simrs-vx/internal/domain/main-entities/user" - - pa "simrs-vx/internal/lib/auth" - el "simrs-vx/pkg/logger" - p "simrs-vx/pkg/password" - - ed "simrs-vx/internal/domain/main-entities/doctor" - ee "simrs-vx/internal/domain/main-entities/employee" - em "simrs-vx/internal/domain/main-entities/midwife" - en "simrs-vx/internal/domain/main-entities/nurse" - erc "simrs-vx/internal/domain/references/common" - erg "simrs-vx/internal/domain/references/organization" - a "github.com/karincake/apem" dg "github.com/karincake/apem/db-gorm-pg" ms "github.com/karincake/apem/ms-redis" d "github.com/karincake/dodol" l "github.com/karincake/lepet" + + pa "simrs-vx/internal/lib/auth" + pl "simrs-vx/pkg/logger" + p "simrs-vx/pkg/password" + + ed "simrs-vx/internal/domain/main-entities/doctor" + ee "simrs-vx/internal/domain/main-entities/employee" + "simrs-vx/internal/domain/main-entities/intern" + em "simrs-vx/internal/domain/main-entities/midwife" + en "simrs-vx/internal/domain/main-entities/nurse" + eu "simrs-vx/internal/domain/main-entities/user" + erc "simrs-vx/internal/domain/references/common" + erg "simrs-vx/internal/domain/references/organization" ) +const source = "authentication" + var authCfg AuthCfg func init() { @@ -40,13 +40,18 @@ func init() { // Generates token and store in redis at one place // just return the error code func GenToken(input eu.LoginDto) (*d.Data, error) { + event := pl.Event{ + Feature: "Create", + Source: source, + } + // Get User user := &eu.User{Name: input.Name} // if input.Position_Code != "" { // user.Position_Code = input.Position_Code // } if errCode := getAndCheck(user, user); errCode != "" { - return nil, d.FieldErrors{"authentication": d.FieldError{Code: errCode, Message: el.GenMessage(errCode)}} + return nil, d.FieldErrors{"authentication": d.FieldError{Code: errCode, Message: pl.GenMessage(errCode)}} } if user.LoginAttemptCount > 5 { @@ -54,7 +59,7 @@ func GenToken(input eu.LoginDto) (*d.Data, error) { now := time.Now() lastAllowdLogin := user.LastAllowdLogin if lastAllowdLogin.After(now.Add(-time.Hour * 1)) { - return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-tooMany", Message: el.GenMessage("auth-login-tooMany")}} + return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-tooMany", Message: pl.GenMessage("auth-login-tooMany")}} } else { tn := time.Now() user.LastAllowdLogin = &tn @@ -65,18 +70,18 @@ func GenToken(input eu.LoginDto) (*d.Data, error) { tn := time.Now() user.LastAllowdLogin = &tn dg.I.Save(&user) - return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-tooMany", Message: el.GenMessage("auth-login-tooMany")}} + return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-tooMany", Message: pl.GenMessage("auth-login-tooMany")}} } } if !p.Check(input.Password, user.Password) { user.LoginAttemptCount++ dg.I.Save(&user) - return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-incorrect", Message: el.GenMessage("auth-login-incorrect")}} + return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-incorrect", Message: pl.GenMessage("auth-login-incorrect")}} } else if user.Status_Code == erc.USCBlocked { - return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-blocked", Message: el.GenMessage("auth-login-blocked")}} + return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-blocked", Message: pl.GenMessage("auth-login-blocked")}} } else if user.Status_Code == erc.USCNew { - return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-unverified", Message: el.GenMessage("auth-login-unverified")}} + return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-login-unverified", Message: pl.GenMessage("auth-login-unverified")}} } // Access token prep @@ -115,7 +120,7 @@ func GenToken(input eu.LoginDto) (*d.Data, error) { employee := ee.Employee{} dg.I.Where("\"User_Id\" = ?", user.Id).First(&employee) if employee.Id == 0 { - return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noEmployee", Message: el.GenMessage("auth-noEmployee")}} + return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noEmployee", Message: pl.GenMessage("auth-noEmployee")}} } atClaims["employee_id"] = employee.Id outputData["employee_id"] = employee.Id @@ -134,7 +139,7 @@ func GenToken(input eu.LoginDto) (*d.Data, error) { doctor := ed.Doctor{} dg.I.Where("\"Employee_Id\" = ?", employee.Id).First(&doctor) if doctor.Id == 0 { - return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noDoctor", Message: el.GenMessage("auth-noDoctor")}} + return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noDoctor", Message: pl.GenMessage("auth-noDoctor")}} } atClaims["doctor_code"] = doctor.Code outputData["doctor_code"] = doctor.Code @@ -152,7 +157,7 @@ func GenToken(input eu.LoginDto) (*d.Data, error) { empData := en.Nurse{} dg.I.Where("\"Employee_Id\" = ?", employee.Id).First(&empData) if empData.Id == 0 { - return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noNurse", Message: el.GenMessage("auth-noNurse")}} + return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noNurse", Message: pl.GenMessage("auth-noNurse")}} } atClaims["nurse_code"] = empData.Code outputData["nurse_code"] = empData.Code @@ -160,40 +165,40 @@ func GenToken(input eu.LoginDto) (*d.Data, error) { empData := em.Midwife{} dg.I.Where("\"Employee_Id\" = ?", employee.Id).First(&empData) if empData.Id == 0 { - return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noMidwife", Message: el.GenMessage("auth-noMidwife")}} + return nil, d.FieldErrors{"authentication": d.FieldError{Code: "auth-noMidwife", Message: pl.GenMessage("auth-noMidwife")}} } atClaims["midwife_code"] = empData.Code outputData["midwife_code"] = empData.Code } - errorGetPosition := d.FieldErrors{"authentication": d.FieldError{Code: "auth-getData-failed", Message: el.GenMessage("auth-getData-failed")}} + errorGetPosition := d.FieldErrors{"authentication": d.FieldError{Code: "auth-getData-failed", Message: pl.GenMessage("auth-getData-failed")}} // division position - divisionPositions, err := getDivisionPosition(employee.Id) + divisionPositions, err := getDivisionPosition(employee.Id, &event) if err != nil { return nil, errorGetPosition } // installation position - installationPositions, err := getInstallationPosition(employee.Id) + installationPositions, err := getInstallationPosition(employee.Id, &event) if err != nil { return nil, errorGetPosition } // unit position - unitPositions, err := getUnitPosition(employee.Id) + unitPositions, err := getUnitPosition(employee.Id, &event) if err != nil { return nil, errorGetPosition } // specialist position - specialistPositions, err := getSpecialistPosition(employee.Id) + specialistPositions, err := getSpecialistPosition(employee.Id, &event) if err != nil { return nil, errorGetPosition } // subspecialist position - subspecialistPositions, err := getSubspecialistPosition(employee.Id) + subspecialistPositions, err := getSubspecialistPosition(employee.Id, &event) if err != nil { return nil, errorGetPosition } @@ -220,7 +225,7 @@ func GenToken(input eu.LoginDto) (*d.Data, error) { at := jwt.NewWithClaims(jwt.SigningMethodHS256, atClaims) ats, err := at.SignedString([]byte(atSecretKey)) if err != nil { - return nil, d.FieldErrors{"user": d.FieldError{Code: "token-sign-err", Message: el.GenMessage("token-sign-err")}} + return nil, d.FieldErrors{"user": d.FieldError{Code: "token-sign-err", Message: pl.GenMessage("token-sign-err")}} } outputData["accessToken"] = ats @@ -283,21 +288,21 @@ func VerifyToken(r *http.Request, tokenType TokenType) (data *jwt.Token, errCode func ExtractToken(r *http.Request, tokenType TokenType) (data *pa.AuthInfo, err error) { token, errCode, errDetail := VerifyToken(r, tokenType) if errCode != "" { - return nil, d.FieldError{Code: errCode, Message: el.GenMessage(errCode, errDetail)} + return nil, d.FieldError{Code: errCode, Message: pl.GenMessage(errCode, errDetail)} } claims, ok := token.Claims.(jwt.MapClaims) if ok && token.Valid { accessUuid, ok := claims["uuid"].(string) if !ok { - return nil, d.FieldError{Code: "token-invalid", Message: el.GenMessage("token-invalid", "uuid not available")} + return nil, d.FieldError{Code: "token-invalid", Message: pl.GenMessage("token-invalid", "uuid not available")} } user_id, myErr := strconv.ParseInt(fmt.Sprintf("%.f", claims["user_id"]), 10, 64) if myErr != nil { - return nil, d.FieldError{Code: "token-invalid", Message: el.GenMessage("token-invalid", "uuid is not available")} + return nil, d.FieldError{Code: "token-invalid", Message: pl.GenMessage("token-invalid", "uuid is not available")} } accessUuidRedis := ms.I.Get(accessUuid) if accessUuidRedis.String() == "" { - return nil, d.FieldError{Code: "token-unidentified", Message: el.GenMessage("token-unidentified")} + return nil, d.FieldError{Code: "token-unidentified", Message: pl.GenMessage("token-unidentified")} } data = &pa.AuthInfo{ @@ -324,41 +329,3 @@ func ExtractToken(r *http.Request, tokenType TokenType) (data *pa.AuthInfo, err func GetConfig() { a.ParseCfg(&authCfg) } - -func checkStrClaims(claim map[string]interface{}, key string) string { - if v, exist := claim[key]; exist && v != nil { - return v.(string) - } - return "" -} - -func checkStrPtrClaims(claim map[string]interface{}, key string) *string { - if v, exist := claim[key]; exist && v != nil { - val := v.(string) - return &val - } - return nil -} - -func checkIntClaims(claim map[string]interface{}, key string) int { - if v, exist := claim[key]; exist && v != nil { - return v.(int) - } - return 0 -} - -func checkIntPtrClaims(claim map[string]interface{}, key string) *int { - if v, exist := claim[key]; exist && v != nil { - val := int(v.(float64)) - return &val - } - return nil -} - -func checkUntPtrClaims(claim map[string]interface{}, key string) *uint { - if v, exist := claim[key]; exist && v != nil { - val := uint(v.(float64)) - return &val - } - return nil -} diff --git a/internal/use-case/main-use-case/authentication/helper.go b/internal/use-case/main-use-case/authentication/helper.go index bec64518..a919cfe9 100644 --- a/internal/use-case/main-use-case/authentication/helper.go +++ b/internal/use-case/main-use-case/authentication/helper.go @@ -1,6 +1,10 @@ package authentication import ( + dg "github.com/karincake/apem/db-gorm-pg" + + pl "simrs-vx/pkg/logger" + edp "simrs-vx/internal/domain/main-entities/division-position" eip "simrs-vx/internal/domain/main-entities/installation-position" esp "simrs-vx/internal/domain/main-entities/specialist-position" @@ -12,8 +16,6 @@ import ( usp "simrs-vx/internal/use-case/main-use-case/specialist-position" ussp "simrs-vx/internal/use-case/main-use-case/subspecialist-position" uup "simrs-vx/internal/use-case/main-use-case/unit-position" - - dg "github.com/karincake/apem/db-gorm-pg" ) // just return the error code @@ -28,43 +30,21 @@ func getAndCheck(input, condition any) (eCode string) { return "" } -func getDivisionPosition(employee_id uint) ([]string, error) { +func getDivisionPosition(employee_id uint, event *pl.Event) ([]string, error) { var result []string - // var employee ee.Employee - // if err := dg.I.Where("\"Employee_Id\" = ?", employee_id).First(&employee).Error; err != nil { - // if err == gorm.ErrRecordNotFound { - // return result, nil - // } - // return result, errors.New("no employee found") - // } - - //var divisionPositions []edp.DivisionPosition - //err := dg.I. - // Preload("Division"). - // Where("\"Employee_Id\" = ?", employee_id). - // Find(&divisionPositions).Error - //if err != nil { - // if err == gorm.ErrRecordNotFound { - // return result, nil - // } - // return result, err - //} - // get data division_position based on employee_id - dataDivisionPosition, err := udp.ReadList(edp.ReadListDto{ + data, _, err := udp.ReadListData(edp.ReadListDto{ FilterDto: edp.FilterDto{Employee_Id: &employee_id}, - Includes: "division"}) + Includes: "Division"}, event) if err != nil { return nil, err } - if list, ok := dataDivisionPosition.Data.([]edp.ResponseDto); ok { - if len(list) > 0 { - for _, dp := range list { - if dp.Division != nil { - result = append(result, "div-"+dp.Division.Code+"-"+dp.Code) - } + if len(data) > 0 { + for _, dp := range data { + if dp.Division != nil { + result = append(result, "div-"+dp.Division.Code+"-"+dp.Code) } } } @@ -72,23 +52,21 @@ func getDivisionPosition(employee_id uint) ([]string, error) { return result, nil } -func getInstallationPosition(employeeId uint) ([]string, error) { +func getInstallationPosition(employeeId uint, event *pl.Event) ([]string, error) { var result []string // get data unit_position based on employee_id - dataInstallationPosition, err := uip.ReadList(eip.ReadListDto{ + data, _, err := uip.ReadListData(eip.ReadListDto{ FilterDto: eip.FilterDto{Employee_Id: &employeeId}, - Includes: "installation"}) + Includes: "installation"}, event) if err != nil { return nil, err } - if list, ok := dataInstallationPosition.Data.([]eip.ResponseDto); ok { - if len(list) > 0 { - for _, dp := range list { - if dp.Installation != nil { - result = append(result, "inst-"+dp.Installation.Code+"-"+dp.Code) - } + if len(data) > 0 { + for _, dp := range data { + if dp.Installation != nil { + result = append(result, "inst-"+dp.Installation.Code+"-"+dp.Code) } } } @@ -96,23 +74,21 @@ func getInstallationPosition(employeeId uint) ([]string, error) { return result, nil } -func getUnitPosition(employeeId uint) ([]string, error) { +func getUnitPosition(employeeId uint, event *pl.Event) ([]string, error) { var result []string // get data unit_position based on employee_id - dataUnitPosition, err := uup.ReadList(eup.ReadListDto{ + data, _, err := uup.ReadListData(eup.ReadListDto{ FilterDto: eup.FilterDto{Employee_Id: &employeeId}, - Includes: "unit"}) + Includes: "unit"}, event) if err != nil { return nil, err } - if list, ok := dataUnitPosition.Data.([]eup.ResponseDto); ok { - if len(list) > 0 { - for _, dp := range list { - if dp.Unit != nil { - result = append(result, "unit-"+dp.Unit.Code+"-"+dp.Code) - } + if len(data) > 0 { + for _, dp := range data { + if dp.Unit != nil { + result = append(result, "unit-"+dp.Unit.Code+"-"+dp.Code) } } } @@ -120,23 +96,21 @@ func getUnitPosition(employeeId uint) ([]string, error) { return result, nil } -func getSpecialistPosition(employeeId uint) ([]string, error) { +func getSpecialistPosition(employeeId uint, event *pl.Event) ([]string, error) { var result []string // get data unit_position based on employee_id - dataSpecialistPosition, err := usp.ReadList(esp.ReadListDto{ + data, _, err := usp.ReadListData(esp.ReadListDto{ FilterDto: esp.FilterDto{Employee_Id: &employeeId}, - Includes: "specialist"}) + Includes: "specialist"}, event) if err != nil { return nil, err } - if list, ok := dataSpecialistPosition.Data.([]esp.ResponseDto); ok { - if len(list) > 0 { - for _, dp := range list { - if dp.Specialist != nil { - result = append(result, "spec-"+dp.Specialist.Code+"-"+dp.Code) - } + if len(data) > 0 { + for _, dp := range data { + if dp.Specialist != nil { + result = append(result, "spec-"+dp.Specialist.Code+"-"+dp.Code) } } } @@ -144,26 +118,47 @@ func getSpecialistPosition(employeeId uint) ([]string, error) { return result, nil } -func getSubspecialistPosition(employeeId uint) ([]string, error) { +func getSubspecialistPosition(employeeId uint, event *pl.Event) ([]string, error) { var result []string // get data unit_position based on employee_id - dataSubspecialistPosition, err := ussp.ReadList(essp.ReadListDto{ + data, _, err := ussp.ReadListData(essp.ReadListDto{ FilterDto: essp.FilterDto{Employee_Id: &employeeId}, - Includes: "subspecialist"}) + Includes: "subspecialist"}, event) if err != nil { return nil, err } - if list, ok := dataSubspecialistPosition.Data.([]essp.ResponseDto); ok { - if len(list) > 0 { - for _, dp := range list { - if dp.Subspecialist != nil { - result = append(result, "subspec-"+dp.Subspecialist.Code+"-"+dp.Code) - } + if len(data) > 0 { + for _, dp := range data { + if dp.Subspecialist != nil { + result = append(result, "subspec-"+dp.Subspecialist.Code+"-"+dp.Code) } } } return result, nil } + +func checkStrClaims(claim map[string]interface{}, key string) string { + if v, exist := claim[key]; exist && v != nil { + return v.(string) + } + return "" +} + +func checkStrPtrClaims(claim map[string]interface{}, key string) *string { + if v, exist := claim[key]; exist && v != nil { + val := v.(string) + return &val + } + return nil +} + +func checkUntPtrClaims(claim map[string]interface{}, key string) *uint { + if v, exist := claim[key]; exist && v != nil { + val := uint(v.(float64)) + return &val + } + return nil +} diff --git a/internal/use-case/main-use-case/device/case.go b/internal/use-case/main-use-case/device/case.go index ff548a4b..126dff9f 100644 --- a/internal/use-case/main-use-case/device/case.go +++ b/internal/use-case/main-use-case/device/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.Device 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.Device var err error diff --git a/internal/use-case/main-use-case/device/helper.go b/internal/use-case/main-use-case/device/helper.go index 08964464..21956cc5 100644 --- a/internal/use-case/main-use-case/device/helper.go +++ b/internal/use-case/main-use-case/device/helper.go @@ -30,8 +30,8 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Device) { data.Code = inputSrc.Code data.Name = inputSrc.Name data.Uom_Code = inputSrc.Uom_Code - data.Item_Id = inputSrc.Item_Id - data.Infra_Id = inputSrc.Infra_Id + data.Item_Code = inputSrc.Item_Code + data.Infra_Code = inputSrc.Infra_Code } func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { @@ -40,13 +40,13 @@ func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { Name: input.Name, ItemGroup_Code: ero.ITGCDevice, Uom_Code: &input.Uom_Code, - Infra_Id: input.Infra_Id, + Infra_Code: input.Infra_Code, } item, err := ui.CreateData(itemCreate, event, tx) if err != nil { return err } - input.Item_Id = &item.Id + input.Item_Code = &item.Code return nil } diff --git a/internal/use-case/main-use-case/device/lib.go b/internal/use-case/main-use-case/device/lib.go index 664db248..63c8cedb 100644 --- a/internal/use-case/main-use-case/device/lib.go +++ b/internal/use-case/main-use-case/device/lib.go @@ -81,6 +81,13 @@ 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.First(&data, input.Id).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/division/lib.go b/internal/use-case/main-use-case/division/lib.go index 62a10d5b..0b45ba11 100644 --- a/internal/use-case/main-use-case/division/lib.go +++ b/internal/use-case/main-use-case/division/lib.go @@ -52,7 +52,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.Di EXISTS ( SELECT 1 FROM "Division" c - WHERE c."Parent_Id" = "Division"."Id" + WHERE c."Parent_Code" = "Division"."Code" ) `) } diff --git a/internal/use-case/main-use-case/infra/case.go b/internal/use-case/main-use-case/infra/case.go index 7c227e8b..4771f3cb 100644 --- a/internal/use-case/main-use-case/infra/case.go +++ b/internal/use-case/main-use-case/infra/case.go @@ -38,12 +38,12 @@ func Create(input e.CreateDto) (*d.Data, error) { } if input.InfraGroup_Code == ero.IFGCRoom { - if input.Parent_Id == nil { + if input.Parent_Code == nil { event.Status = "failed" event.ErrInfo = pl.ErrorInfo{ Code: "data-create-fail", - Detail: "parent_id is required", - Raw: errors.New("parent_id is required"), + Detail: "parent_code is required", + Raw: errors.New("parent_code is required"), } return pl.SetLogError(&event, input) @@ -59,7 +59,7 @@ func Create(input e.CreateDto) (*d.Data, error) { } if input.InfraGroup_Code == ero.IFGCRoom { - input.Infra_Id = &data.Id + input.Infra_Code = &data.Code if err := createRoom(&input, &event, tx); err != nil { return err } diff --git a/internal/use-case/main-use-case/infra/helper.go b/internal/use-case/main-use-case/infra/helper.go index 35388c85..81de5389 100644 --- a/internal/use-case/main-use-case/infra/helper.go +++ b/internal/use-case/main-use-case/infra/helper.go @@ -29,8 +29,8 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Infra) { data.Code = inputSrc.Code data.Name = inputSrc.Name data.InfraGroup_Code = inputSrc.InfraGroup_Code - data.Parent_Id = inputSrc.Parent_Id - data.Item_Id = inputSrc.Item_Id + data.Parent_Code = inputSrc.Parent_Code + data.Item_Code = inputSrc.Item_Code } func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { @@ -42,23 +42,23 @@ func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { tmp := "unit" return &tmp }(), - Infra_Id: input.Parent_Id, + Infra_Code: input.Parent_Code, } item, err := ui.CreateData(itemCreate, event, tx) if err != nil { return err } - input.Item_Id = &item.Id + input.Item_Code = &item.Code return nil } func createRoom(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { roomCreate := er.CreateDto{ - Infra_Id: input.Infra_Id, - Unit_Id: input.Unit_Id, - Specialist_Id: input.Specialist_Id, - Subspecialist_Id: input.Subspecialist_Id, + Infra_Code: input.Infra_Code, + Unit_Code: input.Unit_Code, + Specialist_Code: input.Specialist_Code, + Subspecialist_Code: input.Subspecialist_Code, } _, err := ur.CreateData(roomCreate, event, tx) if err != nil { diff --git a/internal/use-case/main-use-case/infra/lib.go b/internal/use-case/main-use-case/infra/lib.go index 234104bb..5e0592c3 100644 --- a/internal/use-case/main-use-case/infra/lib.go +++ b/internal/use-case/main-use-case/infra/lib.go @@ -52,7 +52,7 @@ func ReadListData(input e.ReadListDto, event *pl.Event, dbx ...*gorm.DB) ([]e.In EXISTS ( SELECT 1 FROM "Infra" c - WHERE c."Parent_Id" = "Infra"."Id" + WHERE c."Parent_Code" = "Infra"."Code" ) `) } @@ -91,6 +91,13 @@ 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) + } + tx = tx.Preload("Parent"). Preload("Childrens"). Preload("Item"). @@ -99,7 +106,7 @@ func ReadDetailData(input e.ReadDetailDto, event *pl.Event, dbx ...*gorm.DB) (*e Preload("Rooms.Subspecialist"). Preload("Rooms.Unit") - if err := tx.First(&data, input.Id).Error; err != nil { + if err := tx.First(&data).Error; err != nil { if processedErr := pu.HandleReadError(err, event, source, input.Id, data); processedErr != nil { return nil, processedErr } @@ -119,7 +126,7 @@ func UpdateData(input e.UpdateDto, data *e.Infra, event *pl.Event, dbx ...*gorm. } else { tx = dg.I } - data.Parent = nil + // data.Parent = nil data.Childrens = nil data.Item = nil data.Rooms = nil diff --git a/internal/use-case/main-use-case/item/case.go b/internal/use-case/main-use-case/item/case.go index 914d777f..58ce3213 100644 --- a/internal/use-case/main-use-case/item/case.go +++ b/internal/use-case/main-use-case/item/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: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: &input.Code} var data *e.Item 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: uint16(input.Id)} + rdDto := e.ReadDetailDto{Code: input.Code} var data *e.Item var err error diff --git a/internal/use-case/main-use-case/item/helper.go b/internal/use-case/main-use-case/item/helper.go index 0ebfcd37..6f7e0c57 100644 --- a/internal/use-case/main-use-case/item/helper.go +++ b/internal/use-case/main-use-case/item/helper.go @@ -21,6 +21,6 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Item) { data.Name = inputSrc.Name data.ItemGroup_Code = inputSrc.ItemGroup_Code data.Uom_Code = inputSrc.Uom_Code - data.Infra_Id = inputSrc.Infra_Id + data.Infra_Code = inputSrc.Infra_Code data.Stock = inputSrc.Stock } diff --git a/internal/use-case/main-use-case/material/case.go b/internal/use-case/main-use-case/material/case.go index 42346dc6..5f5cec55 100644 --- a/internal/use-case/main-use-case/material/case.go +++ b/internal/use-case/main-use-case/material/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.Material 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.Material var err error diff --git a/internal/use-case/main-use-case/material/helper.go b/internal/use-case/main-use-case/material/helper.go index 9cfefe27..ee415107 100644 --- a/internal/use-case/main-use-case/material/helper.go +++ b/internal/use-case/main-use-case/material/helper.go @@ -30,8 +30,8 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Material) { data.Name = inputSrc.Name data.Uom_Code = inputSrc.Uom_Code data.Stock = inputSrc.Stock - data.Item_Id = inputSrc.Item_Id - data.Infra_Id = inputSrc.Infra_Id + data.Item_Code = inputSrc.Item_Code + data.Infra_Code = inputSrc.Infra_Code } func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { @@ -40,7 +40,7 @@ func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { Name: input.Name, ItemGroup_Code: ero.ITGCMaterial, Uom_Code: &input.Uom_Code, - Infra_Id: input.Infra_Id, + Infra_Code: input.Infra_Code, Stock: input.Stock, } item, err := ui.CreateData(itemCreate, event, tx) @@ -48,6 +48,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/medicine/case.go b/internal/use-case/main-use-case/medicine/case.go index 5855d33c..3e5bee2d 100644 --- a/internal/use-case/main-use-case/medicine/case.go +++ b/internal/use-case/main-use-case/medicine/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.Medicine 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.Medicine var err error diff --git a/internal/use-case/main-use-case/medicine/helper.go b/internal/use-case/main-use-case/medicine/helper.go index 388be819..1cf35762 100644 --- a/internal/use-case/main-use-case/medicine/helper.go +++ b/internal/use-case/main-use-case/medicine/helper.go @@ -33,9 +33,9 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Medicine) { data.MedicineMethod_Code = inputSrc.MedicineMethod_Code data.Uom_Code = inputSrc.Uom_Code data.Dose = inputSrc.Dose - data.Infra_Id = inputSrc.Infra_Id + data.Infra_Code = inputSrc.Infra_Code data.Stock = inputSrc.Stock - data.Item_Id = inputSrc.Item_Id + data.Item_Code = inputSrc.Item_Code } func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { @@ -44,7 +44,7 @@ func createItem(input *e.CreateDto, event *pl.Event, tx *gorm.DB) error { Name: input.Name, ItemGroup_Code: ero.ITGCMedicine, Uom_Code: input.Uom_Code, - Infra_Id: input.Infra_Id, + Infra_Code: input.Infra_Code, Stock: input.Stock, } item, err := ui.CreateData(itemCreate, event, tx) @@ -52,6 +52,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/medicine/lib.go b/internal/use-case/main-use-case/medicine/lib.go index 3b9d2fa1..f9fccb2e 100644 --- a/internal/use-case/main-use-case/medicine/lib.go +++ b/internal/use-case/main-use-case/medicine/lib.go @@ -81,8 +81,15 @@ 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) + } + tx = tx.Preload("Item") - if err := tx.First(&data, input.Id).Error; err != nil { + 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/room/helper.go b/internal/use-case/main-use-case/room/helper.go index cc64e8c5..5e97a653 100644 --- a/internal/use-case/main-use-case/room/helper.go +++ b/internal/use-case/main-use-case/room/helper.go @@ -17,8 +17,8 @@ func setData[T *e.CreateDto | *e.UpdateDto](input T, data *e.Room) { inputSrc = &inputTemp.CreateDto } - data.Infra_Id = inputSrc.Infra_Id - data.Unit_Id = inputSrc.Unit_Id - data.Specialist_Id = inputSrc.Specialist_Id - data.Subspecialist_Id = inputSrc.Subspecialist_Id + data.Infra_Code = inputSrc.Infra_Code + data.Unit_Code = inputSrc.Unit_Code + data.Specialist_Code = inputSrc.Specialist_Code + data.Subspecialist_Code = inputSrc.Subspecialist_Code }