diff --git a/internal/contract/letter_contract.go b/internal/contract/letter_contract.go index 333f899..70122b1 100644 --- a/internal/contract/letter_contract.go +++ b/internal/contract/letter_contract.go @@ -43,8 +43,10 @@ type CreateIncomingLetterRequest struct { PriorityID *uuid.UUID `json:"priority_id,omitempty"` SenderInstitutionID *uuid.UUID `json:"sender_institution_id,omitempty"` SenderName *string `json:"sender_name,omitempty"` + Addressee *string `json:"addressee,omitempty"` ReceivedDate time.Time `json:"received_date"` DueDate *time.Time `json:"due_date,omitempty"` + Type string `json:"type"` // UTAMA or TEMBUSAN Attachments []CreateIncomingLetterAttachment `json:"attachments,omitempty"` } @@ -65,8 +67,10 @@ type IncomingLetterResponse struct { Priority *PriorityResponse `json:"priority,omitempty"` SenderInstitution *InstitutionResponse `json:"sender_institution,omitempty"` SenderName *string `json:"sender_name,omitempty"` + Addressee *string `json:"addressee,omitempty"` ReceivedDate time.Time `json:"received_date"` DueDate *time.Time `json:"due_date,omitempty"` + Type string `json:"type"` Status string `json:"status"` CreatedBy uuid.UUID `json:"created_by"` CreatedAt time.Time `json:"created_at"` @@ -82,8 +86,10 @@ type UpdateIncomingLetterRequest struct { PriorityID *uuid.UUID `json:"priority_id,omitempty"` SenderInstitutionID *uuid.UUID `json:"sender_institution_id,omitempty"` SenderName *string `json:"sender_name,omitempty"` + Addressee *string `json:"addressee,omitempty"` ReceivedDate *time.Time `json:"received_date,omitempty"` DueDate *time.Time `json:"due_date,omitempty"` + Type *string `json:"type,omitempty"` Status *string `json:"status,omitempty"` } diff --git a/internal/entities/letter_incoming.go b/internal/entities/letter_incoming.go index 44de3f9..09335c2 100644 --- a/internal/entities/letter_incoming.go +++ b/internal/entities/letter_incoming.go @@ -14,6 +14,13 @@ const ( LetterIncomingStatusCompleted LetterIncomingStatus = "completed" ) +type LetterIncomingType string + +const ( + LetterIncomingTypeUtama LetterIncomingType = "UTAMA" + LetterIncomingTypeTembusan LetterIncomingType = "TEMBUSAN" +) + type LetterIncoming struct { ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"` LetterNumber string `gorm:"uniqueIndex;not null" json:"letter_number"` @@ -23,8 +30,10 @@ type LetterIncoming struct { PriorityID *uuid.UUID `json:"priority_id,omitempty"` SenderInstitutionID *uuid.UUID `json:"sender_institution_id,omitempty"` SenderName *string `json:"sender_name,omitempty"` + Addressee *string `json:"addressee,omitempty"` ReceivedDate time.Time `json:"received_date"` DueDate *time.Time `json:"due_date,omitempty"` + Type LetterIncomingType `gorm:"not null;default:'UTAMA'" json:"type"` Status LetterIncomingStatus `gorm:"not null;default:'new'" json:"status"` CreatedBy uuid.UUID `gorm:"not null" json:"created_by"` CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"` diff --git a/internal/processor/letter_processor.go b/internal/processor/letter_processor.go index 97091bc..17ec986 100644 --- a/internal/processor/letter_processor.go +++ b/internal/processor/letter_processor.go @@ -60,6 +60,11 @@ func NewLetterProcessor(letterRepo *repository.LetterIncomingRepository, attachR func (p *LetterProcessorImpl) CreateIncomingLetter(ctx context.Context, req *contract.CreateIncomingLetterRequest) (*contract.IncomingLetterResponse, error) { userID := appcontext.FromGinContext(ctx).UserID + letterType := entities.LetterIncomingTypeUtama + if req.Type == "TEMBUSAN" { + letterType = entities.LetterIncomingTypeTembusan + } + entity := &entities.LetterIncoming{ LetterNumber: req.LetterNumber, ReferenceNumber: req.ReferenceNumber, @@ -68,8 +73,10 @@ func (p *LetterProcessorImpl) CreateIncomingLetter(ctx context.Context, req *con PriorityID: req.PriorityID, SenderInstitutionID: req.SenderInstitutionID, SenderName: req.SenderName, + Addressee: req.Addressee, ReceivedDate: req.ReceivedDate, DueDate: req.DueDate, + Type: letterType, Status: entities.LetterIncomingStatusNew, CreatedBy: userID, } @@ -256,12 +263,18 @@ func (p *LetterProcessorImpl) UpdateIncomingLetter(ctx context.Context, id uuid. if req.SenderName != nil { entity.SenderName = req.SenderName } + if req.Addressee != nil { + entity.Addressee = req.Addressee + } if req.ReceivedDate != nil { entity.ReceivedDate = *req.ReceivedDate } if req.DueDate != nil { entity.DueDate = req.DueDate } + if req.Type != nil { + entity.Type = entities.LetterIncomingType(*req.Type) + } if req.Status != nil { entity.Status = entities.LetterIncomingStatus(*req.Status) } diff --git a/internal/transformer/letter_transformer.go b/internal/transformer/letter_transformer.go index 8da9f8e..7a24f35 100644 --- a/internal/transformer/letter_transformer.go +++ b/internal/transformer/letter_transformer.go @@ -15,8 +15,10 @@ func LetterEntityToContract(e *entities.LetterIncoming, attachments []entities.L Subject: e.Subject, Description: e.Description, SenderName: e.SenderName, + Addressee: e.Addressee, ReceivedDate: e.ReceivedDate, DueDate: e.DueDate, + Type: string(e.Type), Status: string(e.Status), CreatedBy: e.CreatedBy, CreatedAt: e.CreatedAt, @@ -77,8 +79,10 @@ func LetterIncomingEntityToContract(e *entities.LetterIncoming) *contract.Incomi Subject: e.Subject, Description: e.Description, SenderName: e.SenderName, + Addressee: e.Addressee, ReceivedDate: e.ReceivedDate, DueDate: e.DueDate, + Type: string(e.Type), Status: string(e.Status), CreatedBy: e.CreatedBy, // Will be set conditionally CreatedAt: e.CreatedAt, diff --git a/migrations/000038_add_type_to_letter_incoming.down.sql b/migrations/000038_add_type_to_letter_incoming.down.sql new file mode 100644 index 0000000..74f13a1 --- /dev/null +++ b/migrations/000038_add_type_to_letter_incoming.down.sql @@ -0,0 +1,9 @@ +BEGIN; + +-- Drop index +DROP INDEX IF EXISTS idx_letters_incoming_type; + +-- Remove type column from letters_incoming table +ALTER TABLE letters_incoming DROP COLUMN IF EXISTS type; + +COMMIT; \ No newline at end of file diff --git a/migrations/000038_add_type_to_letter_incoming.up.sql b/migrations/000038_add_type_to_letter_incoming.up.sql new file mode 100644 index 0000000..272c09b --- /dev/null +++ b/migrations/000038_add_type_to_letter_incoming.up.sql @@ -0,0 +1,11 @@ +BEGIN; + +-- Add type column to letters_incoming table +ALTER TABLE letters_incoming +ADD COLUMN IF NOT EXISTS type TEXT DEFAULT 'UTAMA' +CHECK (type IN ('UTAMA', 'TEMBUSAN')); + +-- Add index for type column for better query performance +CREATE INDEX IF NOT EXISTS idx_letters_incoming_type ON letters_incoming(type); + +COMMIT; \ No newline at end of file diff --git a/migrations/000039_add_addressee_to_letter_incoming.down.sql b/migrations/000039_add_addressee_to_letter_incoming.down.sql new file mode 100644 index 0000000..fa9ca81 --- /dev/null +++ b/migrations/000039_add_addressee_to_letter_incoming.down.sql @@ -0,0 +1,9 @@ +BEGIN; + +-- Drop index +DROP INDEX IF EXISTS idx_letters_incoming_addressee; + +-- Remove addressee column from letters_incoming table +ALTER TABLE letters_incoming DROP COLUMN IF EXISTS addressee; + +COMMIT; \ No newline at end of file diff --git a/migrations/000039_add_addressee_to_letter_incoming.up.sql b/migrations/000039_add_addressee_to_letter_incoming.up.sql new file mode 100644 index 0000000..10b9d15 --- /dev/null +++ b/migrations/000039_add_addressee_to_letter_incoming.up.sql @@ -0,0 +1,10 @@ +BEGIN; + +-- Add addressee column to letters_incoming table +ALTER TABLE letters_incoming +ADD COLUMN IF NOT EXISTS addressee TEXT; + +-- Add index for addressee column for better search performance +CREATE INDEX IF NOT EXISTS idx_letters_incoming_addressee ON letters_incoming(addressee); + +COMMIT; \ No newline at end of file