diff --git a/pdsclient/pdsclient.go b/pdsclient/pdsclient.go index 305ed55..752d6c6 100644 --- a/pdsclient/pdsclient.go +++ b/pdsclient/pdsclient.go @@ -31,6 +31,12 @@ type createRecordResp struct { ValidationStatus *string `json:"validationStatus,omitempty"` } +type deleteRecordBody struct { + Repo syntax.DID `json:"repo"` + Collection syntax.NSID `json:"collection"` + RKey syntax.RecordKey `json:"rkey"` +} + // rkey is optional (pass empty string for server to create value) func (pc *PDSClient) CreateRecord(ctx context.Context, collection syntax.NSID, rkey syntax.RecordKey, record any) (syntax.ATURI, syntax.CID, error) { @@ -51,8 +57,38 @@ func (pc *PDSClient) CreateRecord(ctx context.Context, collection syntax.NSID, r return out.URI, out.CID, nil } -// TODO: PutRecrod -// TODO: DeleteRecord +func (pc *PDSClient) PutRecord(ctx context.Context, collection syntax.NSID, rkey syntax.RecordKey, record any) (syntax.CID, error) { + + body := createRecordBody{ + Repo: pc.AccountDID, + Collection: collection, + Record: record, + RKey: &rkey, + } + + var out createRecordResp + endpoint := syntax.NSID("com.atproto.repo.putRecord") + if err := pc.APIClient.Post(ctx, endpoint, body, out); err != nil { + return "", err + } + return out.CID, nil +} + +func (pc *PDSClient) DeleteRecord(ctx context.Context, collection syntax.NSID, rkey syntax.RecordKey) error { + + body := deleteRecordBody{ + Repo: pc.AccountDID, + Collection: collection, + RKey: rkey, + } + + endpoint := syntax.NSID("com.atproto.repo.deleteRecord") + if err := pc.APIClient.Post(ctx, endpoint, body, nil); err != nil { + return err + } + return nil +} + // TODO: GetRecord // TODO: ApplyWrites (?)