From 792c7cc9d4b883c2003d825da530325897e752f5 Mon Sep 17 00:00:00 2001 From: Munawwirul Jamal Date: Tue, 9 Dec 2025 13:43:41 +0700 Subject: [PATCH] feat/user: added registration entity --- .../migrations/20251209064304.sql | 12 ++++ cmd/main-migration/migrations/atlas.sum | 5 +- .../domain/main-entities/registration/dto.go | 71 +++++++++++++++++++ .../main-entities/registration/entity.go | 15 ++++ internal/interface/migration/main-entities.go | 2 + 5 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 cmd/main-migration/migrations/20251209064304.sql create mode 100644 internal/domain/main-entities/registration/dto.go create mode 100644 internal/domain/main-entities/registration/entity.go diff --git a/cmd/main-migration/migrations/20251209064304.sql b/cmd/main-migration/migrations/20251209064304.sql new file mode 100644 index 00000000..fc289e20 --- /dev/null +++ b/cmd/main-migration/migrations/20251209064304.sql @@ -0,0 +1,12 @@ +-- Create "Registration" table +CREATE TABLE "public"."Registration" ( + "Id" bigserial NOT NULL, + "CreatedAt" timestamptz NULL, + "UpdatedAt" timestamptz NULL, + "DeletedAt" timestamptz NULL, + "Employee_Id" bigint NULL, + "Installation_Code" character varying(20) NULL, + PRIMARY KEY ("Id"), + CONSTRAINT "fk_Registration_Employee" FOREIGN KEY ("Employee_Id") REFERENCES "public"."Employee" ("Id") ON UPDATE NO ACTION ON DELETE NO ACTION, + CONSTRAINT "fk_Registration_Installation" FOREIGN KEY ("Installation_Code") REFERENCES "public"."Installation" ("Code") ON UPDATE NO ACTION ON DELETE NO ACTION +); diff --git a/cmd/main-migration/migrations/atlas.sum b/cmd/main-migration/migrations/atlas.sum index 3ec1b876..c953a07b 100644 --- a/cmd/main-migration/migrations/atlas.sum +++ b/cmd/main-migration/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:qjr3k9/ymXjw1nopw49c6+fWtu0n+H8sQgsioqUC9Fo= +h1:JGe2DnXv3QZTmdne3HWeAGA4rppck8cJaiZ0RgoM+Sg= 20250904105930.sql h1:MEM6blCgke9DzWQSTnLzasbPIrcHssNNrJqZpSkEo6k= 20250904141448.sql h1:J8cmYNk4ZrG9fhfbi2Z1IWz7YkfvhFqTzrLFo58BPY0= 20250908062237.sql h1:Pu23yEW/aKkwozHoOuROvHS/GK4ngARJGdO7FB7HZuI= @@ -144,4 +144,5 @@ h1:qjr3k9/ymXjw1nopw49c6+fWtu0n+H8sQgsioqUC9Fo= 20251202160848.sql h1:Kd2/TziKSMezrt4XgbjQcYvY/Lo9rX0qw7/Lz0/oyKk= 20251202180207.sql h1:IHmSMIO3ia+YV5GULixbdlV1joaUAWtnjQHPd8+HKiM= 20251202231005.sql h1:lua0KKoeBptSfs/6ehZE6Azo6YUlNkOJwGFyb1HQWkY= -20251203205052.sql h1:az/hGpk7u4YKT7gU+UuEw9guqB9AqdckPF1cYavQ3CA= +20251203205052.sql h1:nk0VK2Uv4bHE3SBfHo/aevVZxtHzr7zAzvmMU8TCCtk= +20251209064304.sql h1:/vp48I71991yaVsOw/g+eFsFydgLGEo+Xfen7Lp8WB4= diff --git a/internal/domain/main-entities/registration/dto.go b/internal/domain/main-entities/registration/dto.go new file mode 100644 index 00000000..b7837aee --- /dev/null +++ b/internal/domain/main-entities/registration/dto.go @@ -0,0 +1,71 @@ +package doctor + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" + ee "simrs-vx/internal/domain/main-entities/employee" + ei "simrs-vx/internal/domain/main-entities/installation" +) + +type CreateDto struct { + Employee_Id uint `json:"employee_id"` + Installation_Code string `json:"installation_code" validate:"maxLength=20"` +} + +type ReadListDto struct { + FilterDto + Includes string `json:"includes"` + Pagination ecore.Pagination +} + +type FilterDto struct { + Employee_Id *uint `json:"employee-id"` + Installation_Code *string `json:"installation-code"` +} + +type ReadDetailDto struct { + Id *uint16 `json:"id"` + Code *string `json:"code"` + Employee_Id *uint `json:"employee_id"` +} + +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 + Employee_Id uint `json:"employee_id"` + Employee *ee.Employee `json:"employee,omitempty"` + Installation_Code string `json:"installation_code"` + Installation *ei.Installation `json:"installation,omitempty"` +} + +func (d Registration) ToResponse() ResponseDto { + resp := ResponseDto{ + Employee_Id: d.Employee_Id, + Employee: d.Employee, + Installation_Code: d.Installation_Code, + Installation: d.Installation, + } + resp.Main = d.Main + return resp +} + +func ToResponseList(data []Registration) []ResponseDto { + resp := make([]ResponseDto, len(data)) + for i, u := range data { + resp[i] = u.ToResponse() + } + return resp +} diff --git a/internal/domain/main-entities/registration/entity.go b/internal/domain/main-entities/registration/entity.go new file mode 100644 index 00000000..52d81f40 --- /dev/null +++ b/internal/domain/main-entities/registration/entity.go @@ -0,0 +1,15 @@ +package doctor + +import ( + ecore "simrs-vx/internal/domain/base-entities/core" + ee "simrs-vx/internal/domain/main-entities/employee" + ei "simrs-vx/internal/domain/main-entities/installation" +) + +type Registration struct { + ecore.Main // adjust this according to the needs + Employee_Id uint `json:"employee_id"` + Employee *ee.Employee `json:"employee,omitempty" gorm:"foreignKey:Employee_Id;references:Id"` + Installation_Code string `json:"installation_code" gorm:"size:20"` + Installation *ei.Installation `json:"installation,omitempty" gorm:"foreignKey:Installation_Code;references:Code"` +} diff --git a/internal/interface/migration/main-entities.go b/internal/interface/migration/main-entities.go index 34530d78..aa4ed3f6 100644 --- a/internal/interface/migration/main-entities.go +++ b/internal/interface/migration/main-entities.go @@ -88,6 +88,7 @@ import ( proceduresrc "simrs-vx/internal/domain/main-entities/procedure-src" province "simrs-vx/internal/domain/main-entities/province" regency "simrs-vx/internal/domain/main-entities/regency" + registration "simrs-vx/internal/domain/main-entities/registration" rehab "simrs-vx/internal/domain/main-entities/rehab" responsibledoctorhist "simrs-vx/internal/domain/main-entities/responsible-doctor-hist" resume "simrs-vx/internal/domain/main-entities/resume" @@ -140,6 +141,7 @@ func getMainEntities() []any { &proceduresrc.ProcedureSrc{}, &employee.Employee{}, &intern.Intern{}, + ®istration.Registration{}, &doctor.Doctor{}, &nurse.Nurse{}, &nutritionist.Nutritionist{},