diff --git a/go.mod b/go.mod index afda176..f36bb8e 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/DEXPRO-Solutions-GmbH/easclient go 1.21.4 require ( + github.com/google/uuid v1.4.0 github.com/joho/godotenv v1.5.1 github.com/stretchr/testify v1.8.4 gopkg.in/resty.v1 v1.12.0 diff --git a/go.sum b/go.sum index 7ec77b2..d7bed96 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= +github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/r_get_record.go b/r_get_record.go new file mode 100644 index 0000000..ac748ad --- /dev/null +++ b/r_get_record.go @@ -0,0 +1,45 @@ +package easclient + +import ( + "context" + "fmt" + "time" + + "github.com/google/uuid" +) + +type Record struct { + 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"` + } `json:"headerFields"` + RecordFields map[string]string `json:"recordFields"` + Attachments []any `json:"attachments"` +} + +func (c *StoreClient) GetRecord(ctx context.Context, id uuid.UUID) (*Record, error) { + req, err := c.newRequest(ctx) + if err != nil { + return nil, err + } + + var result Record + + req.SetResult(&result) + res, err := req.Get("/record/" + id.String()) + if err != nil { + return nil, err + } + + if status := res.StatusCode(); status != 200 { + return nil, fmt.Errorf("unexpected response status %v", status) + } + + return &result, nil +} diff --git a/r_get_record_test.go b/r_get_record_test.go new file mode 100644 index 0000000..5df4322 --- /dev/null +++ b/r_get_record_test.go @@ -0,0 +1,22 @@ +package easclient_test + +import ( + "context" + "testing" + + "github.com/DEXPRO-Solutions-GmbH/easclient" + "github.com/google/uuid" + "github.com/stretchr/testify/require" +) + +func TestStoreClient_GetRecord(t *testing.T) { + testPrelude(t) + + ctx := context.Background() + user := easclient.NewUserClaims("test@dexpro.de") + ctx = user.SetOnContext(ctx) + + record, err := DefaultClient.GetRecord(ctx, uuid.MustParse("990ac5bf-1df5-45b8-82ca-41120621f826")) + require.NoError(t, err) + require.NotNil(t, record) +}