refactor: Update ARR body parsing logic
The code changes in `pattern_test.go` update the ARR body parsing logic. The message body parsing now correctly handles ARR bodies with a different pattern format. This ensures accurate extraction of data based on patterns and improves the overall functionality of the code.
This commit is contained in:
@@ -3,10 +3,10 @@ package repository
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"caatsm/internal/domain"
|
||||
"caatsm/pkg/utils"
|
||||
|
||||
"github.com/Khan/genqlient/graphql"
|
||||
"github.com/google/uuid"
|
||||
@@ -30,6 +30,7 @@ func NewHasuraRepo(endpoint, secret string) *HasuraRepository {
|
||||
|
||||
// InsertParsedMessage inserts a new ParsedMessage into the Hasura GraphQL API
|
||||
func (hr *HasuraRepository) CreateNew(pm *domain.ParsedMessage) error {
|
||||
log := utils.GetSugaredLogger()
|
||||
bodyString, _ := json.Marshal(pm.BodyData)
|
||||
secondAddress, _ := json.Marshal(pm.SecondaryAddresses)
|
||||
variables := Aviation_telegrams_insert_input{
|
||||
@@ -51,6 +52,7 @@ func (hr *HasuraRepository) CreateNew(pm *domain.ParsedMessage) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("Inserted new message: %v\n", resp)
|
||||
// fmt.Printf("Inserted new message: %v\n", resp)
|
||||
log.Infof("Saved : %v\n", resp)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
CREATE SCHEMA IF NOT EXISTS aviation;
|
||||
|
||||
CREATE TABLE aviation.telegrams (
|
||||
uuid UUID PRIMARY KEY,
|
||||
message_id VARCHAR(255) ,
|
||||
date_time VARCHAR(255) ,
|
||||
priority_indicator VARCHAR(255) ,
|
||||
primary_address VARCHAR(255) ,
|
||||
secondary_addresses TEXT[], -- Array of strings
|
||||
originator VARCHAR(255),
|
||||
originator_date_time VARCHAR(255),
|
||||
category VARCHAR(255),
|
||||
body_and_footer TEXT,
|
||||
body_data JSONB, -- JSONB to store parsed body data
|
||||
received_at TIMESTAMP NOT NULL,
|
||||
parsed_at TIMESTAMP,
|
||||
dispatched_at TIMESTAMP,
|
||||
need_dispatch BOOLEAN
|
||||
);
|
||||
|
||||
-- Indexes for better query performance
|
||||
CREATE INDEX idx_telegrams_message_id ON aviation.telegrams (message_id);
|
||||
CREATE INDEX idx_telegrams_date_time ON aviation.telegrams (date_time);
|
||||
CREATE INDEX idx_telegrams_priority_indicator ON aviation.telegrams (priority_indicator);
|
||||
CREATE INDEX idx_telegrams_primary_address ON aviation.telegrams (primary_address);
|
||||
CREATE INDEX idx_telegrams_received_at ON aviation.telegrams (received_at);
|
||||
Reference in New Issue
Block a user