Skip to content

Commit

Permalink
Merge pull request #2 from DEXPRO-Solutions-GmbH/feat/get-record
Browse files Browse the repository at this point in the history
Add function to get record
  • Loading branch information
fabiante authored Dec 15, 2023
2 parents 1e5ab62 + a8e757b commit aa34513
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
45 changes: 45 additions & 0 deletions r_get_record.go
Original file line number Diff line number Diff line change
@@ -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
}
22 changes: 22 additions & 0 deletions r_get_record_test.go
Original file line number Diff line number Diff line change
@@ -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("[email protected]")
ctx = user.SetOnContext(ctx)

record, err := DefaultClient.GetRecord(ctx, uuid.MustParse("990ac5bf-1df5-45b8-82ca-41120621f826"))
require.NoError(t, err)
require.NotNil(t, record)
}

0 comments on commit aa34513

Please sign in to comment.