Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to get record #2

Merged
merged 2 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"))
fabiante marked this conversation as resolved.
Show resolved Hide resolved
require.NoError(t, err)
require.NotNil(t, record)
}