add addresse

This commit is contained in:
Aditya Siregar 2025-09-21 21:06:04 +07:00
parent 24e1d265d3
commit 7c3d6451bd
8 changed files with 71 additions and 0 deletions

View File

@ -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"`
}

View File

@ -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"`

View File

@ -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)
}

View File

@ -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,

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;