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")
}
@@ -0,0 +1,21 @@
package parser
import (
"caatsm/internal/domain"
"caatsm/internal/parsers"
)
// AviationParser implements the Parser interface using the existing parsers package
type AviationParser struct{}
// NewAviationParser creates a new aviation parser
func NewAviationParser() *AviationParser {
return &AviationParser{}
}
// Parse parses a raw message string and returns a ParsedMessage
func (p *AviationParser) Parse(rawText string) *domain.ParsedMessage {
// Use the existing Parse function from internal/parsers
return parsers.Parse(rawText)
}
+10
View File
@@ -0,0 +1,10 @@
package parser
import "caatsm/internal/domain"
// Parser defines the interface for parsing raw telegram messages
type Parser interface {
// Parse parses a raw message string and returns a ParsedMessage
Parse(rawText string) *domain.ParsedMessage
}
+7
View File
@@ -0,0 +1,7 @@
package parser
// ProvideParser creates a parser instance
func ProvideParser() Parser {
return NewAviationParser()
}
+8
View File
@@ -0,0 +1,8 @@
package adapter
// Publisher defines the interface for publishing parsed messages
type Publisher interface {
// Publish publishes a parsed message
Publish(message interface{}) error
}
+16
View File
@@ -0,0 +1,16 @@
package adapter
import (
"context"
"caatsm/internal/domain"
)
// Repository defines the interface for message persistence
type Repository interface {
// InsertOne inserts a single telegram message
InsertOne(ctx context.Context, msg *domain.ParsedMessage) error
// InsertBatch inserts multiple telegram messages in a batch
InsertBatch(ctx context.Context, msgs []*domain.ParsedMessage) error
}