Skip to content

Commit 74edeaa

Browse files
committed
fix: change dataverseId to collectionId, and update GetGuestbookResponsesById
1 parent b2ba964 commit 74edeaa

20 files changed

Lines changed: 405 additions & 256 deletions

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ This changelog follows the principles of [Keep a Changelog](https://keepachangel
88

99
### Added
1010

11-
- Guestbooks: Added `downloadGuestbookResponsesByDataverseId` and `downloadGuestbookResponsesOfAGuestbook` use cases and repository support for exporting guestbook responses as raw CSV content.
11+
- Guestbooks: Added `getGuestbookResponsesByGuestbookId` use case and repository support for retrieving paginated guestbook responses as structured JSON.
12+
- Guestbooks: Added `downloadGuestbookResponsesByCollectionId` and `downloadGuestbookResponsesOfAGuestbook` use cases and repository support for exporting guestbook responses as raw CSV content.
1213
- Guestbooks: Added optional `includeStats` support to `getGuestbooksByCollectionId`, returning `usageCount` and `responseCount` when requested.
1314

1415
### Changed

docs/useCases.md

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ The different use cases currently available in the package are classified below,
130130
- [Guestbooks read use cases](#guestbooks-read-use-cases)
131131
- [Get a Guestbook](#get-a-guestbook)
132132
- [Get Guestbooks By Collection Id](#get-guestbooks-by-collection-id)
133+
- [Get Guestbook Responses Byg Guestbook Id](#get-guestbook-responses-byg-guestbook-id)
134+
- [Download Guestbook Responses By Collection Id](#download-guestbook-responses-by-collection-id)
135+
- [Download Guestbook Responses Of A Guestbook](#download-guestbook-responses-of-a-guestbook)
133136
- [Guestbooks write use cases](#guestbooks-write-use-cases)
134137
- [Create a Guestbook](#create-a-guestbook)
135138
- [Set Guestbook Enabled](#set-guestbook-enabled)
@@ -2951,38 +2954,62 @@ getGuestbooksByCollectionId
29512954

29522955
_See [use case](../src/guestbooks/domain/useCases/GetGuestbooksByCollectionId.ts) implementation_.
29532956

2954-
#### Download Guestbook Responses By Dataverse Id
2957+
#### Get Guestbook Responses Byg Guestbook Id
29552958

2956-
Downloads all guestbook responses for a dataverse collection and returns the raw response body, typically CSV content.
2959+
Returns paginated [GuestbookResponse](../src/guestbooks/domain/models/GuestbookResponse.ts) entries for a guestbook.
29572960

29582961
##### Example call:
29592962

29602963
```typescript
2961-
import { downloadGuestbookResponsesByDataverseId } from '@iqss/dataverse-client-javascript'
2964+
import { getGuestbookResponsesByGuestbookId } from '@iqss/dataverse-client-javascript'
29622965

2963-
const dataverseId = 'root'
2966+
const guestbookId = 123
2967+
const limit = 10
2968+
const offset = 0
29642969

2965-
downloadGuestbookResponsesByDataverseId.execute(dataverseId).then((csvResponse: string) => {
2966-
/* ... */
2967-
})
2970+
getGuestbookResponsesByGuestbookId
2971+
.execute(guestbookId, limit, offset)
2972+
.then((guestbookResponses: GuestbookResponse[]) => {
2973+
/* ... */
2974+
})
2975+
```
2976+
2977+
_See [use case](../src/guestbooks/domain/useCases/getGuestbookResponsesByGuestbookId.ts) implementation_.
2978+
2979+
#### Download Guestbook Responses By Collection Id
2980+
2981+
Downloads all guestbook responses for a collection and returns the raw response body, typically CSV content.
2982+
2983+
##### Example call:
2984+
2985+
```typescript
2986+
import { downloadGuestbookResponsesByCollectionId } from '@iqss/dataverse-client-javascript'
2987+
2988+
const collectionIdOrAlias = 'root'
2989+
2990+
downloadGuestbookResponsesByCollectionId
2991+
.execute(collectionIdOrAlias)
2992+
.then((csvResponse: string) => {
2993+
/* ... */
2994+
})
29682995
```
29692996

2970-
_See [use case](../src/guestbooks/domain/useCases/DownloadGuestbookResponsesByDataverseId.ts) implementation_.
2997+
_See [use case](../src/guestbooks/domain/useCases/DownloadGuestbookResponsesByCollectionId.ts) implementation_.
29712998

29722999
#### Download Guestbook Responses Of A Guestbook
29733000

2974-
Downloads guestbook responses for one guestbook in a dataverse collection and returns the raw response body, typically CSV content.
3001+
Downloads guestbook responses for one guestbook in a collection and returns the raw response body, typically CSV content.
29753002

29763003
##### Example call:
29773004

29783005
```typescript
29793006
import { downloadGuestbookResponsesOfAGuestbook } from '@iqss/dataverse-client-javascript'
29803007

2981-
const dataverseId = 'root'
3008+
const collectionIdOrAlias = 'root'
29823009
const guestbookId = 123
29833010

29843011
downloadGuestbookResponsesOfAGuestbook
2985-
.execute(dataverseId, guestbookId)
3012+
.execute(collectionIdOrAlias, guestbookId)
29863013
.then((csvResponse: string) => {
29873014
/* ... */
29883015
})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Guestbook } from '../models/Guestbook'
2+
import { GuestbookResponse } from '../models/GuestbookResponse'
3+
4+
export interface GuestbookResponsesDTO {
5+
guestbook: Guestbook
6+
responses: GuestbookResponse[]
7+
pagination?: GuestbookResponsesPaginationDTO
8+
}
9+
10+
export interface GuestbookResponsesPaginationDTO {
11+
next?: string
12+
totalResponses: number
13+
}
Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
export interface GuestbookResponse {
2-
[key: string]: unknown
3-
guestbookId?: number
4-
dataverseId?: number
2+
id: number
3+
dataset: string
4+
datasetPid: string
5+
date: string
6+
type: EventType
7+
fileName?: string
8+
fileId?: number
9+
filePid?: string
10+
userName: string
11+
email?: string
12+
institution?: string
13+
position?: string
14+
customQuestions?: GuestbookResponseCustomQuestion[]
15+
}
16+
17+
export interface GuestbookResponseCustomQuestion {
18+
question: string
19+
response: string
20+
}
21+
22+
export enum EventType {
23+
ACCESS_REQUEST = 'AccessRequest',
24+
DOWNLOAD = 'Download',
25+
SUBSET = 'Subset',
26+
EXPLORE = 'Explore'
527
}

src/guestbooks/domain/repositories/IGuestbooksRepository.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ export interface IGuestbooksRepository {
1313
includeStats?: boolean,
1414
includeInherited?: boolean
1515
): Promise<Guestbook[]>
16-
getGuestbookResponsesByDataverseId(
17-
dataverseId: number | string,
18-
guestbookId?: number
16+
getGuestbookResponsesByGuestbookId(
17+
guestbookId: number,
18+
limit?: number,
19+
offset?: number
1920
): Promise<GuestbookResponse[]>
20-
downloadGuestbookResponsesByDataverseId(
21-
dataverseId: number | string,
21+
downloadGuestbookResponsesByCollectionId(
22+
collectionIdOrAlias: number | string,
2223
guestbookId?: number
2324
): Promise<string>
2425
setGuestbookEnabled(

src/guestbooks/domain/useCases/DownloadGuestbookResponsesByDataverseId.ts renamed to src/guestbooks/domain/useCases/DownloadGuestbookResponsesByCollectionId.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
import { UseCase } from '../../../core/domain/useCases/UseCase'
22
import { IGuestbooksRepository } from '../repositories/IGuestbooksRepository'
33

4-
export class DownloadGuestbookResponsesByDataverseId implements UseCase<string> {
4+
export class DownloadGuestbookResponsesByCollectionId implements UseCase<string> {
55
constructor(private readonly guestbooksRepository: IGuestbooksRepository) {}
66

77
/**
8-
* Downloads all guestbook responses for a dataverse collection.
8+
* Downloads all guestbook responses for a collection.
99
*
10-
* The dataverse can be identified by either its alias/identifier or numeric database id.
10+
* The collection can be identified by either its alias/identifier or numeric database id.
1111
* The returned string is the raw response body from the Dataverse API, which is typically
1212
* saved by callers as a CSV file or printed directly.
1313
*
14-
* @param {number | string} dataverseId - Dataverse alias/identifier or numeric database id.
14+
* @param {number | string} collectionIdOrAlias - Collection alias/identifier or numeric database id.
1515
* @returns {Promise<string>} Raw response body returned by the Dataverse API.
1616
*/
17-
async execute(dataverseId: number | string): Promise<string> {
18-
return await this.guestbooksRepository.downloadGuestbookResponsesByDataverseId(dataverseId)
17+
async execute(collectionIdOrAlias: number | string): Promise<string> {
18+
return await this.guestbooksRepository.downloadGuestbookResponsesByCollectionId(
19+
collectionIdOrAlias
20+
)
1921
}
2022
}

src/guestbooks/domain/useCases/DownloadGuestbookResponsesOfAGuestbook.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ export class DownloadGuestbookResponsesOfAGuestbook implements UseCase<string> {
55
constructor(private readonly guestbooksRepository: IGuestbooksRepository) {}
66

77
/**
8-
* Downloads guestbook responses for one guestbook in a dataverse collection.
8+
* Downloads guestbook responses for one guestbook in a collection.
99
*
10-
* The dataverse can be identified by either its alias/identifier or numeric database id.
10+
* The collection can be identified by either its alias/identifier or numeric database id.
1111
* The returned string is the raw response body from the Dataverse API, which is typically
1212
* saved by callers as a CSV file or printed directly.
1313
*
14-
* @param {number | string} dataverseId - Dataverse alias/identifier or numeric database id.
14+
* @param {number | string} collectionIdOrAlias - Collection alias/identifier or numeric database id.
1515
* @param {number} guestbookId - Guestbook identifier to restrict the export.
1616
* @returns {Promise<string>} Raw response body returned by the Dataverse API.
1717
*/
18-
async execute(dataverseId: number | string, guestbookId: number): Promise<string> {
19-
return await this.guestbooksRepository.downloadGuestbookResponsesByDataverseId(
20-
dataverseId,
18+
async execute(collectionIdOrAlias: number | string, guestbookId: number): Promise<string> {
19+
return await this.guestbooksRepository.downloadGuestbookResponsesByCollectionId(
20+
collectionIdOrAlias,
2121
guestbookId
2222
)
2323
}

src/guestbooks/domain/useCases/GetGuestbookResponsesByDataverseId.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { UseCase } from '../../../core/domain/useCases/UseCase'
2+
import { GuestbookResponse } from '../models/GuestbookResponse'
3+
import { IGuestbooksRepository } from '../repositories/IGuestbooksRepository'
4+
5+
export class GetGuestbookResponsesByGuestbookId implements UseCase<GuestbookResponse[]> {
6+
constructor(private readonly guestbooksRepository: IGuestbooksRepository) {}
7+
8+
/**
9+
* Returns guestbook responses for one guestbook.
10+
*
11+
* @param {number} guestbookId - Guestbook identifier.
12+
* @param {number} limit - Maximum number of responses to return.
13+
* @param {number} offset - Number of responses to skip.
14+
* @returns {Promise<GuestbookResponse[]>}
15+
*/
16+
async execute(guestbookId: number, limit = 10, offset = 0): Promise<GuestbookResponse[]> {
17+
return await this.guestbooksRepository.getGuestbookResponsesByGuestbookId(
18+
guestbookId,
19+
limit,
20+
offset
21+
)
22+
}
23+
}

src/guestbooks/domain/useCases/GetGuestbookResponsesOfAGuestbook.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)