add addresse
This commit is contained in:
parent
24e1d265d3
commit
7c3d6451bd
@ -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"`
|
||||
}
|
||||
|
||||
|
||||
@ -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"`
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
9
migrations/000038_add_type_to_letter_incoming.down.sql
Normal file
9
migrations/000038_add_type_to_letter_incoming.down.sql
Normal 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;
|
||||
11
migrations/000038_add_type_to_letter_incoming.up.sql
Normal file
11
migrations/000038_add_type_to_letter_incoming.up.sql
Normal 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;
|
||||
@ -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;
|
||||
10
migrations/000039_add_addressee_to_letter_incoming.up.sql
Normal file
10
migrations/000039_add_addressee_to_letter_incoming.up.sql
Normal 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;
|
||||
Loading…
x
Reference in New Issue
Block a user