refactor: Update ARR body parsing logic

This commit is contained in:
windyboy
2024-07-23 12:01:58 +08:00
parent 77a7c7eae0
commit 3b9b64ec9e
6 changed files with 82 additions and 1442 deletions
+18 -19
View File
@@ -4,7 +4,6 @@ package repository
import ( import (
"context" "context"
"encoding/json"
"time" "time"
"github.com/Khan/genqlient/graphql" "github.com/Khan/genqlient/graphql"
@@ -13,29 +12,29 @@ import (
// input type for inserting data into table "aviation.telegrams" // input type for inserting data into table "aviation.telegrams"
type Aviation_telegrams_insert_input struct { type Aviation_telegrams_insert_input struct {
Body_and_footer string `json:"body_and_footer"` Body_and_footer string `json:"body_and_footer"`
Body_data json.RawMessage `json:"body_data"` Body_data string `json:"body_data"`
Category string `json:"category"` Category string `json:"category"`
Date_time string `json:"date_time"` Date_time string `json:"date_time"`
Dispatched_at time.Time `json:"dispatched_at"` Dispatched_at time.Time `json:"dispatched_at"`
Id int `json:"id"` Id int `json:"id"`
Message_id string `json:"message_id"` Message_id string `json:"message_id"`
Need_dispatch bool `json:"need_dispatch"` Need_dispatch bool `json:"need_dispatch"`
Originator string `json:"originator"` Originator string `json:"originator"`
Originator_date_time string `json:"originator_date_time"` Originator_date_time string `json:"originator_date_time"`
Parsed_at time.Time `json:"parsed_at"` Parsed_at time.Time `json:"parsed_at"`
Primary_address string `json:"primary_address"` Primary_address string `json:"primary_address"`
Priority_indicator string `json:"priority_indicator"` Priority_indicator string `json:"priority_indicator"`
Received_at time.Time `json:"received_at"` 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"` 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. // 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 } func (v *Aviation_telegrams_insert_input) GetBody_and_footer() string { return v.Body_and_footer }
// GetBody_data returns Aviation_telegrams_insert_input.Body_data, and is useful for accessing the field via an interface. // 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 } func (v *Aviation_telegrams_insert_input) GetBody_data() string { return v.Body_data }
// GetCategory returns Aviation_telegrams_insert_input.Category, and is useful for accessing the field via an interface. // GetCategory returns Aviation_telegrams_insert_input.Category, and is useful for accessing the field via an interface.
func (v *Aviation_telegrams_insert_input) GetCategory() string { return v.Category } func (v *Aviation_telegrams_insert_input) GetCategory() string { return v.Category }
@@ -76,7 +75,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 } 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. // 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 return v.Secondary_addresses
} }
+1 -1
View File
@@ -6,7 +6,7 @@ operations:
generated: generated.go generated: generated.go
bindings: bindings:
jsonb: jsonb:
type: encoding/json.RawMessage type: string
timestamp: timestamp:
type: time.Time type: time.Time
uuid: uuid:
+17 -87
View File
@@ -7,14 +7,14 @@
"SuiteHasProgrammaticFocus": false, "SuiteHasProgrammaticFocus": false,
"SpecialSuiteFailureReasons": null, "SpecialSuiteFailureReasons": null,
"PreRunStats": { "PreRunStats": {
"TotalSpecs": 3, "TotalSpecs": 1,
"SpecsThatWillRun": 1 "SpecsThatWillRun": 1
}, },
"StartTime": "2024-07-23T11:25:30.889407931+08:00", "StartTime": "2024-07-23T12:01:15.75278901+08:00",
"EndTime": "2024-07-23T11:25:30.892377154+08:00", "EndTime": "2024-07-23T12:01:15.764655302+08:00",
"RunTime": 2969222, "RunTime": 11866337,
"SuiteConfig": { "SuiteConfig": {
"RandomSeed": 1721705130, "RandomSeed": 1721707275,
"RandomizeAllSpecs": false, "RandomizeAllSpecs": false,
"FocusStrings": [ "FocusStrings": [
"Repositories Hasura Repository should mutate a parsed message" "Repositories Hasura Repository should mutate a parsed message"
@@ -31,7 +31,7 @@
"DryRun": false, "DryRun": false,
"PollProgressAfter": 0, "PollProgressAfter": 0,
"PollProgressInterval": 0, "PollProgressInterval": 0,
"Timeout": 3599523895104, "Timeout": 3599595734975,
"EmitSpecProgress": false, "EmitSpecProgress": false,
"OutputInterceptorMode": "", "OutputInterceptorMode": "",
"SourceRoots": null, "SourceRoots": null,
@@ -41,76 +41,6 @@
"ParallelHost": "" "ParallelHost": ""
}, },
"SpecReports": [ "SpecReports": [
{
"ContainerHierarchyTexts": [
"Repositories",
"Just a simple test"
],
"ContainerHierarchyLocations": [
{
"FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go",
"LineNumber": 19
},
{
"FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go",
"LineNumber": 20
}
],
"ContainerHierarchyLabels": [
[],
[]
],
"LeafNodeType": "It",
"LeafNodeLocation": {
"FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go",
"LineNumber": 56
},
"LeafNodeLabels": [],
"LeafNodeText": "should not error",
"State": "skipped",
"StartTime": "2024-07-23T11:25:30.889468443+08:00",
"EndTime": "0001-01-01T00:00:00Z",
"RunTime": 0,
"ParallelProcess": 1,
"NumAttempts": 0,
"MaxFlakeAttempts": 0,
"MaxMustPassRepeatedly": 0
},
{
"ContainerHierarchyTexts": [
"Repositories",
"Just a simple test"
],
"ContainerHierarchyLocations": [
{
"FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go",
"LineNumber": 19
},
{
"FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go",
"LineNumber": 20
}
],
"ContainerHierarchyLabels": [
[],
[]
],
"LeafNodeType": "It",
"LeafNodeLocation": {
"FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go",
"LineNumber": 60
},
"LeafNodeLabels": [],
"LeafNodeText": "name should be new",
"State": "skipped",
"StartTime": "2024-07-23T11:25:30.889483979+08:00",
"EndTime": "0001-01-01T00:00:00Z",
"RunTime": 0,
"ParallelProcess": 1,
"NumAttempts": 0,
"MaxFlakeAttempts": 0,
"MaxMustPassRepeatedly": 0
},
{ {
"ContainerHierarchyTexts": [ "ContainerHierarchyTexts": [
"Repositories", "Repositories",
@@ -119,11 +49,11 @@
"ContainerHierarchyLocations": [ "ContainerHierarchyLocations": [
{ {
"FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go", "FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go",
"LineNumber": 19 "LineNumber": 17
}, },
{ {
"FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go", "FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go",
"LineNumber": 66 "LineNumber": 64
} }
], ],
"ContainerHierarchyLabels": [ "ContainerHierarchyLabels": [
@@ -133,14 +63,14 @@
"LeafNodeType": "It", "LeafNodeType": "It",
"LeafNodeLocation": { "LeafNodeLocation": {
"FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go", "FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go",
"LineNumber": 72 "LineNumber": 70
}, },
"LeafNodeLabels": [], "LeafNodeLabels": [],
"LeafNodeText": "should mutate a parsed message", "LeafNodeText": "should mutate a parsed message",
"State": "passed", "State": "passed",
"StartTime": "2024-07-23T11:25:30.889488379+08:00", "StartTime": "2024-07-23T12:01:15.752849553+08:00",
"EndTime": "2024-07-23T11:25:30.89235263+08:00", "EndTime": "2024-07-23T12:01:15.764585492+08:00",
"RunTime": 2864253, "RunTime": 11735991,
"ParallelProcess": 1, "ParallelProcess": 1,
"NumAttempts": 1, "NumAttempts": 1,
"MaxFlakeAttempts": 0, "MaxFlakeAttempts": 0,
@@ -150,11 +80,11 @@
"SpecEventType": "Node", "SpecEventType": "Node",
"CodeLocation": { "CodeLocation": {
"FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go", "FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go",
"LineNumber": 72 "LineNumber": 70
}, },
"TimelineLocation": { "TimelineLocation": {
"Order": 1, "Order": 1,
"Time": "2024-07-23T11:25:30.889491289+08:00" "Time": "2024-07-23T12:01:15.752859429+08:00"
}, },
"Message": "should mutate a parsed message", "Message": "should mutate a parsed message",
"NodeType": "It" "NodeType": "It"
@@ -163,14 +93,14 @@
"SpecEventType": "Node (End)", "SpecEventType": "Node (End)",
"CodeLocation": { "CodeLocation": {
"FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go", "FileName": "/home/windy/project/airport/projects/new-telegram/caatsm/internal/repository/hasura_test.go",
"LineNumber": 72 "LineNumber": 70
}, },
"TimelineLocation": { "TimelineLocation": {
"Order": 3, "Order": 3,
"Time": "2024-07-23T11:25:30.892349748+08:00" "Time": "2024-07-23T12:01:15.764576564+08:00"
}, },
"Message": "should mutate a parsed message", "Message": "should mutate a parsed message",
"Duration": 2858459, "Duration": 11717183,
"NodeType": "It" "NodeType": "It"
} }
] ]
+7 -5
View File
@@ -2,6 +2,7 @@ package repository
import ( import (
"context" "context"
"encoding/json"
"os" "os"
"caatsm/internal/domain" "caatsm/internal/domain"
@@ -28,14 +29,15 @@ func NewHasuraRepo(endpoint, secret string) *HasuraRepository {
// InsertParsedMessage inserts a new ParsedMessage into the Hasura GraphQL API // InsertParsedMessage inserts a new ParsedMessage into the Hasura GraphQL API
func (hr *HasuraRepository) InsertParsedMessage(pm *domain.ParsedMessage) error { func (hr *HasuraRepository) InsertParsedMessage(pm *domain.ParsedMessage) error {
bodyString, _ := json.Marshal(pm.BodyData)
variables := Aviation_telegrams_insert_input{ variables := Aviation_telegrams_insert_input{
// Id: 10, // Id: 10,
Body_and_footer: pm.BodyAndFooter, Body_and_footer: pm.BodyAndFooter,
// Body_data: pm.BodyData.(json.RawMessage), Body_data: string(bodyString),
Category: pm.Category, Category: pm.Category,
Date_time: pm.DateTime, Date_time: pm.DateTime,
Dispatched_at: pm.DispatchedAt, Dispatched_at: pm.DispatchedAt,
Uuid: uuid.New(), Uuid: uuid.New(),
} }
_, err := newMessage(context.Background(), hr.client, variables) _, err := newMessage(context.Background(), hr.client, variables)
if err != nil { if err != nil {
+39 -41
View File
@@ -2,11 +2,9 @@ package repository
import ( import (
"caatsm/internal/domain" "caatsm/internal/domain"
"context"
"testing" "testing"
"time" "time"
"github.com/hasura/go-graphql-client"
. "github.com/onsi/ginkgo/v2" . "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
) )
@@ -17,51 +15,51 @@ func TestConfig(t *testing.T) {
} }
var _ = Describe("Repositories", func() { var _ = Describe("Repositories", func() {
Context("Just a simple test", func() { // Context("Just a simple test", func() {
// Define a struct for the mutation input to match the expected GraphQL input // // Define a struct for the mutation input to match the expected GraphQL input
// Define a struct for the mutation input to match the expected GraphQL input // // Define a struct for the mutation input to match the expected GraphQL input
type aviation_user_insert_input struct { // type aviation_user_insert_input struct {
Name graphql.String `json:"name"` // Name graphql.String `json:"name"`
Email graphql.String `json:"email"` // Email graphql.String `json:"email"`
UpdateAt graphql.String `json:"update_at"` // Use string for timestamp // UpdateAt graphql.String `json:"update_at"` // Use string for timestamp
} // }
// Get the current time in RFC3339 format // // Get the current time in RFC3339 format
currentTime := time.Now().Format(time.RFC3339) // currentTime := time.Now().Format(time.RFC3339)
input := aviation_user_insert_input{ // input := aviation_user_insert_input{
Name: graphql.String("new"), // Name: graphql.String("new"),
Email: graphql.String("2@2.com"), // Email: graphql.String("2@2.com"),
UpdateAt: graphql.String(currentTime), // Use formatted string // UpdateAt: graphql.String(currentTime), // Use formatted string
} // }
// Define the mutation // // Define the mutation
var mutation struct { // var mutation struct {
InsertAviationUserOne struct { // InsertAviationUserOne struct {
ID int `json:"id"` // ID int `json:"id"`
Name string // Name string
} `graphql:"insert_aviation_user_one(object: $object)"` // } `graphql:"insert_aviation_user_one(object: $object)"`
} // }
// Define the mutation variables // // Define the mutation variables
// Define the mutation variables // // Define the mutation variables
variables := map[string]interface{}{ // variables := map[string]interface{}{
"object": input, // "object": input,
} // }
// Define the mutation // // Define the mutation
client := graphql.NewClient("http://localhost:8080/v1/graphql", nil) // client := graphql.NewClient("http://localhost:8080/v1/graphql", nil)
err := client.Mutate(context.Background(), &mutation, variables) // err := client.Mutate(context.Background(), &mutation, variables)
It("should not error", func() { // It("should not error", func() {
Expect(err).NotTo(HaveOccurred()) // Expect(err).NotTo(HaveOccurred())
}) // })
It("name should be new", func() { // It("name should be new", func() {
Expect(mutation.InsertAviationUserOne.Name).To(Equal("new")) // Expect(mutation.InsertAviationUserOne.Name).To(Equal("new"))
}) // })
}) // })
Context("Hasura Repository", func() { Context("Hasura Repository", func() {
// var repository *HasuraRepository // var repository *HasuraRepository
@@ -82,8 +80,8 @@ var _ = Describe("Repositories", func() {
OriginatorDateTime: "originator_date_time", OriginatorDateTime: "originator_date_time",
Category: "category", Category: "category",
BodyAndFooter: "body_and_footer", BodyAndFooter: "body_and_footer",
// BodyData: &interface{}, BodyData: domain.ARR{AircraftID: "aircraft_id", Category: "ARR", DepartureAirport: "departure_airport", DepartureTime: "departure_time", ArrivalAirport: "arrival_airport", ArrivalTime: "arrival_time"},
ReceivedAt: time.Now(), ReceivedAt: time.Now(),
} }
err := repository.InsertParsedMessage(parseMessage) err := repository.InsertParsedMessage(parseMessage)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
-1289
View File
File diff suppressed because it is too large Load Diff