refactor: Update BodyParser constructor to accept body parameter
This commit is contained in:
@@ -96,7 +96,8 @@ type ParsedMessage struct {
|
||||
Originator string `json:"originator,omitempty"` // 发件人: The sender of the message.
|
||||
OriginatorDateTime string `json:"originatorDateTime,omitempty"` // 发件日期时间: The date and time when the originator sent the message.
|
||||
Category string `json:"category,omitempty"` // 类别: The category of the message.
|
||||
BodyAndFooter string `json:"bodyAndFooter,omitempty"` // 正文和页脚: The body and footer of the message (e.g., 'CALLSIGN/ABC123\nFPL/AB1234-AB\n...').
|
||||
Text string `json:"bodyAndFooter,omitempty"` // 正文和页脚: The body and footer of the message (e.g., 'CALLSIGN/ABC123\nFPL/AB1234-AB\n...').
|
||||
Body string `json:"body,omitempty"` // 正文: The body of the message.
|
||||
BodyData interface{} `json:"bodyData,omitempty"` // 正文数据: Parsed body data.
|
||||
ReceivedAt time.Time `json:"receivedAt"` // 接收时间: The time when the message was received.
|
||||
ParsedAt time.Time `json:"parsedAt,omitempty"` // 解析时间: The time when the message was parsed.
|
||||
|
||||
@@ -152,7 +152,7 @@ func Parse(rawText string) (*domain.ParsedMessage, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bodyParser := NewBodyParser(message.BodyAndFooter)
|
||||
bodyParser := NewBodyParser(message.Body)
|
||||
category, bodyData, err := bodyParser.Parse()
|
||||
message.Category = category
|
||||
message.ParsedAt = time.Now()
|
||||
@@ -180,21 +180,21 @@ func cleanMessage(text string) string {
|
||||
|
||||
func ParseHeader(fullMessage string) (domain.ParsedMessage, error) {
|
||||
log := utils.GetSugaredLogger()
|
||||
fullMessage = cleanMessage(fullMessage)
|
||||
lines := strings.Split(fullMessage, "\n")
|
||||
cleaned := cleanMessage(fullMessage)
|
||||
lines := strings.Split(cleaned, "\n")
|
||||
|
||||
if len(lines) < 3 {
|
||||
log.Warnf("invalid message format: %s", fullMessage)
|
||||
return domain.ParsedMessage{}, fmt.Errorf("invalid message format: %s", fullMessage)
|
||||
return domain.ParsedMessage{Text: fullMessage}, fmt.Errorf("invalid message format: %s", fullMessage)
|
||||
}
|
||||
|
||||
_, messageID, dateTime, err := parseStartIndicator(lines[0])
|
||||
if err != nil {
|
||||
return domain.ParsedMessage{}, err
|
||||
return domain.ParsedMessage{Text: fullMessage}, err
|
||||
}
|
||||
|
||||
priorityIndicator, primaryAddress := parsePriorityAndPrimary(lines[1])
|
||||
secondaryAddresses, originator, originatorDateTime, bodyAndFooter := parseRemainingLines(lines[2:])
|
||||
secondaryAddresses, originator, originatorDateTime, body := parseRemainingLines(lines[2:])
|
||||
|
||||
return domain.ParsedMessage{
|
||||
MessageID: messageID,
|
||||
@@ -204,7 +204,8 @@ func ParseHeader(fullMessage string) (domain.ParsedMessage, error) {
|
||||
SecondaryAddresses: secondaryAddresses,
|
||||
Originator: originator,
|
||||
OriginatorDateTime: originatorDateTime,
|
||||
BodyAndFooter: bodyAndFooter,
|
||||
Text: fullMessage,
|
||||
Body: body,
|
||||
ReceivedAt: time.Now(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
// input type for inserting data into table "aviation.telegrams"
|
||||
type Aviation_telegrams_insert_input struct {
|
||||
Body_and_footer string `json:"body_and_footer"`
|
||||
Text string `json:"Text"`
|
||||
Body_data json.RawMessage `json:"body_data"`
|
||||
Category string `json:"category"`
|
||||
Date_time string `json:"date_time"`
|
||||
@@ -26,12 +26,12 @@ type Aviation_telegrams_insert_input struct {
|
||||
Primary_address string `json:"primary_address"`
|
||||
Priority_indicator string `json:"priority_indicator"`
|
||||
Received_at time.Time `json:"received_at"`
|
||||
Secondary_addresses json.RawMessage `json:"secondary_addresses"`
|
||||
Secondary_addresses string `json:"secondary_addresses"`
|
||||
Uuid uuid.UUID `json:"uuid"`
|
||||
}
|
||||
|
||||
// GetBody_and_footer returns Aviation_telegrams_insert_input.Body_and_footer, and is useful for accessing the field via an interface.
|
||||
func (v *Aviation_telegrams_insert_input) GetBody_and_footer() string { return v.Body_and_footer }
|
||||
// GetText returns Aviation_telegrams_insert_input.Text, and is useful for accessing the field via an interface.
|
||||
func (v *Aviation_telegrams_insert_input) GetText() string { return v.Text }
|
||||
|
||||
// GetBody_data returns Aviation_telegrams_insert_input.Body_data, and is useful for accessing the field via an interface.
|
||||
func (v *Aviation_telegrams_insert_input) GetBody_data() json.RawMessage { return v.Body_data }
|
||||
@@ -72,7 +72,7 @@ func (v *Aviation_telegrams_insert_input) GetPriority_indicator() string { retur
|
||||
func (v *Aviation_telegrams_insert_input) GetReceived_at() time.Time { return v.Received_at }
|
||||
|
||||
// GetSecondary_addresses returns Aviation_telegrams_insert_input.Secondary_addresses, and is useful for accessing the field via an interface.
|
||||
func (v *Aviation_telegrams_insert_input) GetSecondary_addresses() json.RawMessage {
|
||||
func (v *Aviation_telegrams_insert_input) GetSecondary_addresses() string {
|
||||
return v.Secondary_addresses
|
||||
}
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@ func (hr *HasuraRepository) CreateNew(pm *domain.ParsedMessage) error {
|
||||
Message_id: pm.MessageID,
|
||||
Priority_indicator: pm.PriorityIndicator,
|
||||
Primary_address: pm.PrimaryAddress,
|
||||
Secondary_addresses: secondAddress,
|
||||
Body_and_footer: pm.BodyAndFooter,
|
||||
Secondary_addresses: string(secondAddress),
|
||||
Text: pm.Text,
|
||||
Body_data: bodyString,
|
||||
Category: pm.Category,
|
||||
Date_time: pm.DateTime,
|
||||
|
||||
+512
-353
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user