diff --git a/r_get_record.go b/r_get_record.go index 82d4d66..7e15565 100644 --- a/r_get_record.go +++ b/r_get_record.go @@ -2,33 +2,23 @@ package easclient import ( "context" - "time" + "encoding/xml" "github.com/google/uuid" ) -type RecordAttachment struct { - Body string `json:"body"` - Name string `json:"name"` - Size string `json:"size"` - Register string `json:"register"` - Author string `json:"author"` - Type string `json:"type"` - DocumentType string `json:"documentType"` - Id uuid.UUID `json:"id"` - FileId uuid.UUID `json:"fileId"` - MasterId uuid.UUID `json:"masterId"` - Version string `json:"version"` - ArchiveDateTime time.Time `json:"archiveDateTime"` -} - func (c *StoreClient) GetRecord(ctx context.Context, id uuid.UUID) (*Record, error) { req, err := c.newRequestXML(ctx) if err != nil { return nil, err } - var result Record + type RecordResponse struct { + XMLName xml.Name `xml:"records"` + Record *Record `xml:"record"` + } + + var result RecordResponse req.SetResult(&result) res, err := req.Get("/record/" + id.String()) @@ -40,5 +30,5 @@ func (c *StoreClient) GetRecord(ctx context.Context, id uuid.UUID) (*Record, err return nil, err } - return &result, nil + return result.Record, nil } diff --git a/r_store_search.go b/r_store_search.go index f1fef8f..d74c897 100644 --- a/r_store_search.go +++ b/r_store_search.go @@ -90,9 +90,9 @@ type SearchResponseChannel struct { Title string `xml:"title"` Link string `xml:"link"` Description string `xml:"description"` - TotalResults int `xml:"totalResults"` // TODO: Assert in unmarshal test - ItemsPerPage int `xml:"itemsPerPage"` // TODO: Assert in unmarshal test - StartIndex int `xml:"startIndex"` // TODO: Assert in unmarshal test + TotalResults int `xml:"totalResults"` + ItemsPerPage int `xml:"itemsPerPage"` + StartIndex int `xml:"startIndex"` Query struct { Role string `xml:"role,attr"` SearchTerms string `xml:"searchTerms,attr"` @@ -114,10 +114,10 @@ type SearchResponseItem struct { HistoryLink Link `xml:"historyLink"` VerifyLink Link `xml:"verifyLink"` DocumentType string `xml:"documentType"` - Fields []*RecordField `xml:"field"` // TODO: Assert and check in get attachment response if this is the correct way to handle recurring fields + Fields []*RecordField `xml:"field"` MasterId uuid.UUID `xml:"masterId"` ArchiveDateTime time.Time `xml:"archiveDateTime"` - ID uuid.UUID `xml:"id"` + Id uuid.UUID `xml:"id"` Version string `xml:"version"` ArchiverLogin string `xml:"archiverLogin"` Archiver string `xml:"archiver"` diff --git a/r_store_search_test.go b/r_store_search_test.go index f8456cb..c8c63e4 100644 --- a/r_store_search_test.go +++ b/r_store_search_test.go @@ -31,6 +31,7 @@ func TestStoreClient_Search(t *testing.T) { // assert search result in general assert.Equal(t, "Amazo*", response.Query.SearchTerms) assert.Greater(t, response.TotalResults, 0) + assert.Greater(t, response.ItemsPerPage, 0) assert.Greater(t, response.EffectiveResults, 0) // assert single hit @@ -55,6 +56,7 @@ func TestStoreClient_Search(t *testing.T) { // assert search result in general assert.Equal(t, "Amazo*", response.Query.SearchTerms) assert.Greater(t, response.TotalResults, 0) + assert.Greater(t, response.ItemsPerPage, 0) assert.Greater(t, response.EffectiveResults, 0) // assert single hit diff --git a/record.go b/record.go index f6319cf..63e31db 100644 --- a/record.go +++ b/record.go @@ -1,21 +1,33 @@ package easclient import ( - "encoding/xml" "time" "github.com/google/uuid" ) -type HeaderFields struct { - DocumentType string `json:"_documentType"` - MasterId uuid.UUID `json:"_masterId"` - ArchiveDateTime time.Time `json:"_archiveDateTime"` - Id uuid.UUID `json:"_id"` - Version string `json:"_version"` - ArchiverLogin string `json:"_archiverLogin"` - InitialArchiverLogin string `json:"_initialArchiverLogin"` - InitialArchiveDateTime time.Time `json:"_initialArchiveDateTime"` +type Record struct { + DocumentType string `xml:"documentType"` + MasterId uuid.UUID `xml:"masterId"` + ArchiveDateTime time.Time `xml:"archiveDateTime"` + ID uuid.UUID `xml:"id"` + Version string `xml:"version"` + ArchiverLogin string `xml:"archiverLogin"` + Archiver string `xml:"archiver"` + InitialArchiver string `xml:"initialArchiver"` + InitialArchiverLogin string `xml:"initialArchiverLogin"` + InitialArchiveDateTime time.Time `xml:"initialArchiveDateTime"` + Fields []*RecordField `xml:"field"` + Attachments []*RecordAttachment `xml:"attachment"` +} + +func (r *Record) GetHeaderFieldVal(name string) string { + for _, field := range r.Fields { + if field.Name == name { + return field.Value + } + } + return "" } type RecordField struct { @@ -23,26 +35,10 @@ type RecordField struct { Value string `xml:",chardata"` } -type Record struct { - XMLName xml.Name `xml:"records"` - Record struct { - DocumentType string `xml:"documentType"` - MasterId uuid.UUID `xml:"masterId"` - ArchiveDateTime time.Time `xml:"archiveDateTime"` - ID uuid.UUID `xml:"id"` - Version string `xml:"version"` - ArchiverLogin string `xml:"archiverLogin"` - Archiver string `xml:"archiver"` - InitialArchiver string `xml:"initialArchiver"` - InitialArchiverLogin string `xml:"initialArchiverLogin"` - InitialArchiveDateTime time.Time `xml:"initialArchiveDateTime"` - Field []*RecordField `xml:"field"` - Attachment struct { - Name string `xml:"name"` - Size string `xml:"size"` - Register string `xml:"register"` - Author string `xml:"author"` - ID string `xml:"id"` - } `xml:"attachment"` - } `xml:"record"` +type RecordAttachment struct { + Name string `xml:"name"` + Size int `xml:"size"` + Register string `xml:"register"` + Author string `xml:"author"` + ID uuid.UUID `xml:"id"` }