Upgrade Go version to 1.23.0 and update dependencies. Introduce new application structure with Clean Architecture principles, including message processing, NATS integration, and PostgreSQL repository. Add configuration management using Koanf and structured logging with Zap. Remove legacy GraphQL integration and related files. Implement dependency injection with Google Wire.

This commit is contained in:
windyboy
2025-11-14 08:42:26 +08:00
parent bafbbf470c
commit a574cfcf27
31 changed files with 1565 additions and 1374 deletions
+13
View File
@@ -0,0 +1,13 @@
package mapper
import "caatsm/internal/domain"
// Mapper defines the interface for mapping between domain models and database models
type Mapper interface {
// ToDBRow converts a domain.ParsedMessage to a database row representation
ToDBRow(msg *domain.ParsedMessage) ([]interface{}, error)
// FromDBRow converts a database row to a domain.ParsedMessage
FromDBRow(row []interface{}) (*domain.ParsedMessage, error)
}
+69
View File
@@ -0,0 +1,69 @@
package mapper
import (
"caatsm/internal/domain"
"encoding/json"
"fmt"
"github.com/google/uuid"
)
// TelegramMapper maps between domain.ParsedMessage and database rows
type TelegramMapper struct{}
// NewTelegramMapper creates a new telegram mapper
func NewTelegramMapper() *TelegramMapper {
return &TelegramMapper{}
}
// ToDBRow converts a domain.ParsedMessage to a database row representation
func (m *TelegramMapper) ToDBRow(msg *domain.ParsedMessage) ([]interface{}, error) {
// Parse UUID
var msgUUID uuid.UUID
var err error
if msg.Uuid != "" {
msgUUID, err = uuid.Parse(msg.Uuid)
if err != nil {
return nil, fmt.Errorf("invalid UUID: %w", err)
}
} else {
msgUUID = uuid.New()
}
// Marshal BodyData to JSONB
var bodyDataJSON []byte
if msg.BodyData != nil {
bodyDataJSON, err = json.Marshal(msg.BodyData)
if err != nil {
return nil, fmt.Errorf("failed to marshal body data: %w", err)
}
}
// SecondaryAddresses is already a string, so we can use it directly
secondaryAddresses := msg.SecondaryAddresses
return []interface{}{
msgUUID, // uuid
msg.MessageID, // message_id
msg.DateTime, // date_time
msg.PriorityIndicator, // priority_indicator
msg.PrimaryAddress, // primary_address
secondaryAddresses, // secondary_addresses (TEXT)
msg.Originator, // originator
msg.OriginatorDateTime, // originator_date_time
msg.Category, // category
msg.Content, // content (TEXT, original message)
bodyDataJSON, // body_data (JSONB)
msg.ReceivedAt, // received_at
msg.ParsedAt, // parsed_at
msg.DispatchedAt, // dispatched_at
msg.NeedDispatch, // need_dispatch
}, nil
}
// FromDBRow converts a database row to a domain.ParsedMessage
func (m *TelegramMapper) FromDBRow(row []interface{}) (*domain.ParsedMessage, error) {
// This is a placeholder - will be implemented if needed for queries
// For now, we only need ToDBRow for inserts
return nil, fmt.Errorf("FromDBRow not implemented")
}