-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from DEXPRO-Solutions-GmbH/feat/get-record
Add function to get record
- Loading branch information
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |