Skip to content

Commit c023fd5

Browse files
committed
feat: Add Guestbook and Access Repository, and their use cases accordingly
1 parent 9c7e9d8 commit c023fd5

27 files changed

+1175
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ This changelog follows the principles of [Keep a Changelog](https://keepachangel
1616
- New Use Case: [Get a Template](./docs/useCases.md#get-a-template) under Templates.
1717
- New Use Case: [Delete a Template](./docs/useCases.md#delete-a-template) under Templates.
1818
- New Use Case: [Update Terms of Access](./docs/useCases.md#update-terms-of-access).
19+
- Guestbooks: Added use cases and repository support for Guestbook CRUD.
20+
- Access: Added a dedicated `access` module for guestbook-at-request and download terms/guestbook submission endpoints.
1921

2022
### Changed
2123

docs/useCases.md

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,19 @@ The different use cases currently available in the package are classified below,
123123
- [Get External Tools](#get-external-tools)
124124
- [Get Dataset External Tool Resolved](#get-dataset-external-tool-resolved)
125125
- [Get File External Tool Resolved](#get-file-external-tool-resolved)
126+
- [Guestbooks](#Guestbooks)
127+
- [Guestbooks read use cases](#guestbooks-read-use-cases)
128+
- [Get a Guestbook](#get-a-guestbook)
129+
- [Get Guestbooks By Collection Id](#get-guestbooks-by-collection-id)
130+
- [Guestbooks write use cases](#guestbooks-write-use-cases)
131+
- [Create a Guestbook](#create-a-guestbook)
132+
- [Set Guestbook Enabled](#set-guestbook-enabled)
133+
- [Access](#Access)
134+
- [Access write use cases](#access-write-use-cases)
135+
- [Submit Guestbook For Datafile Download](#submit-guestbook-for-datafile-download)
136+
- [Submit Guestbook For Datafiles Download](#submit-guestbook-for-datafiles-download)
137+
- [Submit Guestbook For Dataset Download](#submit-guestbook-for-dataset-download)
138+
- [Submit Guestbook For Dataset Version Download](#submit-guestbook-for-dataset-version-download)
126139

127140
## Collections
128141

@@ -2767,3 +2780,188 @@ getFileExternalToolResolved
27672780
```
27682781

27692782
_See [use case](../src/externalTools/domain/useCases/GetfileExternalToolResolved.ts) implementation_.
2783+
2784+
## Guestbooks
2785+
2786+
### Guestbooks Read Use Cases
2787+
2788+
#### Get a Guestbook
2789+
2790+
Returns a [Guestbook](../src/guestbooks/domain/models/Guestbook.ts) by its id.
2791+
2792+
##### Example call:
2793+
2794+
```typescript
2795+
import { getGuestbook } from '@iqss/dataverse-client-javascript'
2796+
2797+
const guestbookId = 123
2798+
2799+
getGuestbook.execute(guestbookId).then((guestbook: Guestbook) => {
2800+
/* ... */
2801+
})
2802+
```
2803+
2804+
_See [use case](../src/guestbooks/domain/useCases/GetGuestbook.ts) implementation_.
2805+
2806+
#### Get Guestbooks By Collection Id
2807+
2808+
Returns all [Guestbook](../src/guestbooks/domain/models/Guestbook.ts) entries available for a collection.
2809+
2810+
##### Example call:
2811+
2812+
```typescript
2813+
import { getGuestbooksBycollectionId } from '@iqss/dataverse-client-javascript'
2814+
2815+
const collectionIdOrAlias = 'root'
2816+
2817+
getGuestbooksBycollectionId.execute(collectionIdOrAlias).then((guestbooks: Guestbook[]) => {
2818+
/* ... */
2819+
})
2820+
```
2821+
2822+
_See [use case](../src/guestbooks/domain/useCases/GetGuestbooksByCollectionId.ts) implementation_.
2823+
2824+
### Guestbooks Write Use Cases
2825+
2826+
#### Create a Guestbook
2827+
2828+
Creates a guestbook on a collection using [CreateGuestbookDTO](../src/guestbooks/domain/dtos/CreateGuestbookDTO.ts).
2829+
2830+
##### Example call:
2831+
2832+
```typescript
2833+
import { createGuestbook } from '@iqss/dataverse-client-javascript'
2834+
2835+
const collectionIdOrAlias = 'root'
2836+
const guestbook: CreateGuestbookDTO = {
2837+
name: 'my test guestbook',
2838+
enabled: true,
2839+
emailRequired: true,
2840+
nameRequired: true,
2841+
institutionRequired: false,
2842+
positionRequired: false,
2843+
customQuestions: [
2844+
{
2845+
question: 'Describe yourself',
2846+
required: false,
2847+
displayOrder: 1,
2848+
type: 'textarea',
2849+
hidden: false
2850+
}
2851+
]
2852+
}
2853+
2854+
createGuestbook.execute(guestbook, collectionIdOrAlias).then(() => {
2855+
/* ... */
2856+
})
2857+
```
2858+
2859+
_See [use case](../src/guestbooks/domain/useCases/CreateGuestbook.ts) implementation_.
2860+
2861+
#### Set Guestbook Enabled
2862+
2863+
Enables or disables a guestbook in a collection.
2864+
2865+
##### Example call:
2866+
2867+
```typescript
2868+
import { setGuestbookEnabled } from '@iqss/dataverse-client-javascript'
2869+
2870+
const collectionIdOrAlias = 'root'
2871+
const guestbookId = 123
2872+
2873+
setGuestbookEnabled.execute(collectionIdOrAlias, guestbookId, false).then(() => {
2874+
/* ... */
2875+
})
2876+
```
2877+
2878+
_See [use case](../src/guestbooks/domain/useCases/SetGuestbookEnabled.ts) implementation_.
2879+
2880+
## Access
2881+
2882+
### Access Write Use Cases
2883+
2884+
#### Submit Guestbook For Datafile Download
2885+
2886+
Submits guestbook answers for a datafile and returns a signed URL.
2887+
2888+
##### Example call:
2889+
2890+
```typescript
2891+
import { submitGuestbookForDatafileDownload } from '@iqss/dataverse-client-javascript'
2892+
2893+
submitGuestbookForDatafileDownload
2894+
.execute(10, {
2895+
guestbookResponse: {
2896+
answers: [
2897+
{ id: 123, value: 'Good' },
2898+
{ id: 124, value: ['Multi', 'Line'] }
2899+
]
2900+
}
2901+
})
2902+
.then((signedUrl: string) => {
2903+
/* ... */
2904+
})
2905+
```
2906+
2907+
_See [use case](../src/access/domain/useCases/SubmitGuestbookForDatafileDownload.ts) implementation_.
2908+
2909+
#### Submit Guestbook For Datafiles Download
2910+
2911+
Submits guestbook answers for multiple files and returns a signed URL.
2912+
2913+
##### Example call:
2914+
2915+
```typescript
2916+
import { submitGuestbookForDatafilesDownload } from '@iqss/dataverse-client-javascript'
2917+
2918+
submitGuestbookForDatafilesDownload
2919+
.execute([10, 11], {
2920+
guestbookResponse: { answers: [{ id: 123, value: 'Good' }] }
2921+
})
2922+
.then((signedUrl: string) => {
2923+
/* ... */
2924+
})
2925+
```
2926+
2927+
_See [use case](../src/access/domain/useCases/SubmitGuestbookForDatafilesDownload.ts) implementation_.
2928+
2929+
#### Submit Guestbook For Dataset Download
2930+
2931+
Submits guestbook answers for dataset download and returns a signed URL.
2932+
2933+
##### Example call:
2934+
2935+
```typescript
2936+
import { submitGuestbookForDatasetDownload } from '@iqss/dataverse-client-javascript'
2937+
2938+
submitGuestbookForDatasetDownload
2939+
.execute('doi:10.5072/FK2/XXXXXX', {
2940+
guestbookResponse: { answers: [{ id: 123, value: 'Good' }] }
2941+
})
2942+
.then((signedUrl: string) => {
2943+
/* ... */
2944+
})
2945+
```
2946+
2947+
_See [use case](../src/access/domain/useCases/SubmitGuestbookForDatasetDownload.ts) implementation_.
2948+
2949+
#### Submit Guestbook For Dataset Version Download
2950+
2951+
Submits guestbook answers for a specific dataset version and returns a signed URL.
2952+
2953+
##### Example call:
2954+
2955+
```typescript
2956+
import { submitGuestbookForDatasetVersionDownload } from '@iqss/dataverse-client-javascript'
2957+
2958+
submitGuestbookForDatasetVersionDownload
2959+
.execute(10, ':latest', {
2960+
guestbookResponse: { answers: [{ id: 123, value: 'Good' }] }
2961+
})
2962+
.then((signedUrl: string) => {
2963+
/* ... */
2964+
})
2965+
```
2966+
2967+
_See [use case](../src/access/domain/useCases/SubmitGuestbookForDatasetVersionDownload.ts) implementation_.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export interface GuestbookAnswerDTO {
2+
id: number | string
3+
value: string | string[]
4+
}
5+
6+
export interface GuestbookResponseDTO {
7+
guestbookResponse: {
8+
answers: GuestbookAnswerDTO[]
9+
}
10+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { GuestbookResponseDTO } from '../dtos/GuestbookResponseDTO'
2+
3+
export interface IAccessRepository {
4+
submitGuestbookForDatafileDownload(
5+
fileId: number | string,
6+
guestbookResponse: GuestbookResponseDTO
7+
): Promise<string>
8+
9+
submitGuestbookForDatafilesDownload(
10+
fileIds: string | Array<number | string>,
11+
guestbookResponse: GuestbookResponseDTO
12+
): Promise<string>
13+
14+
submitGuestbookForDatasetDownload(
15+
datasetId: number | string,
16+
guestbookResponse: GuestbookResponseDTO
17+
): Promise<string>
18+
19+
submitGuestbookForDatasetVersionDownload(
20+
datasetId: number | string,
21+
versionId: string,
22+
guestbookResponse: GuestbookResponseDTO
23+
): Promise<string>
24+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { UseCase } from '../../../core/domain/useCases/UseCase'
2+
import { GuestbookResponseDTO } from '../dtos/GuestbookResponseDTO'
3+
import { IAccessRepository } from '../repositories/IAccessRepository'
4+
5+
export class SubmitGuestbookForDatafileDownload implements UseCase<string> {
6+
constructor(private readonly accessRepository: IAccessRepository) {}
7+
8+
/**
9+
* Submits a guestbook response for a single datafile download request and returns a signed URL.
10+
*
11+
* @param {number | string} fileId - Datafile identifier (numeric id or persistent id).
12+
* @param {GuestbookResponseDTO} guestbookResponse - Guestbook response payload.
13+
* @returns {Promise<string>} - Signed URL for the download.
14+
*/
15+
async execute(fileId: number | string, guestbookResponse: GuestbookResponseDTO): Promise<string> {
16+
return await this.accessRepository.submitGuestbookForDatafileDownload(fileId, guestbookResponse)
17+
}
18+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { UseCase } from '../../../core/domain/useCases/UseCase'
2+
import { GuestbookResponseDTO } from '../dtos/GuestbookResponseDTO'
3+
import { IAccessRepository } from '../repositories/IAccessRepository'
4+
5+
export class SubmitGuestbookForDatafilesDownload implements UseCase<string> {
6+
constructor(private readonly accessRepository: IAccessRepository) {}
7+
8+
/**
9+
* Submits a guestbook response for multiple datafiles download request and returns a signed URL.
10+
*
11+
* @param {string | Array<number | string>} fileIds - Comma-separated string or array of file ids.
12+
* @param {GuestbookResponseDTO} guestbookResponse - Guestbook response payload.
13+
* @returns {Promise<string>} - Signed URL for the download.
14+
*/
15+
async execute(
16+
fileIds: string | Array<number | string>,
17+
guestbookResponse: GuestbookResponseDTO
18+
): Promise<string> {
19+
return await this.accessRepository.submitGuestbookForDatafilesDownload(
20+
fileIds,
21+
guestbookResponse
22+
)
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { UseCase } from '../../../core/domain/useCases/UseCase'
2+
import { GuestbookResponseDTO } from '../dtos/GuestbookResponseDTO'
3+
import { IAccessRepository } from '../repositories/IAccessRepository'
4+
5+
export class SubmitGuestbookForDatasetDownload implements UseCase<string> {
6+
constructor(private readonly accessRepository: IAccessRepository) {}
7+
8+
/**
9+
* Submits a guestbook response for dataset download request and returns a signed URL.
10+
*
11+
* @param {number | string} datasetId - Dataset identifier (numeric id or persistent id).
12+
* @param {GuestbookResponseDTO} guestbookResponse - Guestbook response payload.
13+
* @returns {Promise<string>} - Signed URL for the download.
14+
*/
15+
async execute(
16+
datasetId: number | string,
17+
guestbookResponse: GuestbookResponseDTO
18+
): Promise<string> {
19+
return await this.accessRepository.submitGuestbookForDatasetDownload(
20+
datasetId,
21+
guestbookResponse
22+
)
23+
}
24+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { UseCase } from '../../../core/domain/useCases/UseCase'
2+
import { GuestbookResponseDTO } from '../dtos/GuestbookResponseDTO'
3+
import { IAccessRepository } from '../repositories/IAccessRepository'
4+
5+
export class SubmitGuestbookForDatasetVersionDownload implements UseCase<string> {
6+
constructor(private readonly accessRepository: IAccessRepository) {}
7+
8+
/**
9+
* Submits a guestbook response for a specific dataset version download request and returns a signed URL.
10+
*
11+
* @param {number | string} datasetId - Dataset identifier (numeric id or persistent id).
12+
* @param {string} versionId - Dataset version identifier (for example, ':latest' or '1.0').
13+
* @param {GuestbookResponseDTO} guestbookResponse - Guestbook response payload.
14+
* @returns {Promise<string>} - Signed URL for the download.
15+
*/
16+
async execute(
17+
datasetId: number | string,
18+
versionId: string,
19+
guestbookResponse: GuestbookResponseDTO
20+
): Promise<string> {
21+
return await this.accessRepository.submitGuestbookForDatasetVersionDownload(
22+
datasetId,
23+
versionId,
24+
guestbookResponse
25+
)
26+
}
27+
}

src/access/index.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { AccessRepository } from './infra/repositories/AccessRepository'
2+
import { SubmitGuestbookForDatafileDownload } from './domain/useCases/SubmitGuestbookForDatafileDownload'
3+
import { SubmitGuestbookForDatafilesDownload } from './domain/useCases/SubmitGuestbookForDatafilesDownload'
4+
import { SubmitGuestbookForDatasetDownload } from './domain/useCases/SubmitGuestbookForDatasetDownload'
5+
import { SubmitGuestbookForDatasetVersionDownload } from './domain/useCases/SubmitGuestbookForDatasetVersionDownload'
6+
7+
const accessRepository = new AccessRepository()
8+
9+
const submitGuestbookForDatafileDownload = new SubmitGuestbookForDatafileDownload(accessRepository)
10+
const submitGuestbookForDatafilesDownload = new SubmitGuestbookForDatafilesDownload(
11+
accessRepository
12+
)
13+
const submitGuestbookForDatasetDownload = new SubmitGuestbookForDatasetDownload(accessRepository)
14+
const submitGuestbookForDatasetVersionDownload = new SubmitGuestbookForDatasetVersionDownload(
15+
accessRepository
16+
)
17+
18+
export {
19+
submitGuestbookForDatafileDownload,
20+
submitGuestbookForDatafilesDownload,
21+
submitGuestbookForDatasetDownload,
22+
submitGuestbookForDatasetVersionDownload
23+
}
24+
25+
export { GuestbookResponseDTO } from './domain/dtos/GuestbookResponseDTO'

0 commit comments

Comments
 (0)