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

feat(sdk-client): getCollection method for content #28635

Merged
merged 47 commits into from
May 31, 2024

Conversation

zJaaal
Copy link
Contributor

@zJaaal zJaaal commented May 22, 2024

Proposed Changes

  • Add Content Class to handle Content API Methods and expose it as a method of the Dotcms Client
  • Add GetCollection Class to handle the building of a query for collections and expose it as a method of Content Class

Usage example for standalone getCollection

This an example of a query with all possible methods it supports (could not be a real use case and it should be used from the client.content).

        const requestOptions: Omit<RequestInit, 'body' | 'method'> = {
            cache: 'no-cache' // To simulate a valid request
        };

        const serverUrl = 'http://localhost:8080';

        const contentType = 'forceSensitive';
        const client = new GetCollection(requestOptions, serverUrl, contentType);

        const response = await client
            .language(13) // Language Id
            .render(true) // To retrieve the content with the render
            .sortBy([
                // Sort by multiple fields
                {
                    field: 'name',
                    order: 'asc'
                },
                {
                    field: 'midichlorians',
                    order: 'desc'
                }
            ])
            .depth(2) // Depth of the content for relationships
            .limit(20) // Limit of content per page
            .page(3) // Page to fetch
            .query(
                (
                    qb // Lucene query to append to the main query for more complex queries
                ) =>
                    qb
                        .field('kyberCrystal')
                        .equals('red')
                        .and()
                        .equals('blue')
                        .field('master')
                        .equals('Yoda')
                        .or()
                        .equals('Obi-Wan')
            )
            .draft(true) // To retrieve the draft content
            .variant('legends-forceSensitive') // Variant of the content
            .rawQuery('+modDate:2024-05-28 +conhost:MyCoolSite') // Raw query to append to the main query
            .fetch(); // Fetch the content

@zJaaal zJaaal linked an issue May 22, 2024 that may be closed by this pull request
@zJaaal zJaaal requested a review from oidacra May 23, 2024 16:38
@zJaaal zJaaal requested a review from fmontes May 24, 2024 13:00
@zJaaal zJaaal requested a review from nicobytes May 29, 2024 14:50
@zJaaal zJaaal requested a review from rjvelazco May 29, 2024 17:11
@zJaaal zJaaal requested a review from fmontes May 30, 2024 18:48
@zJaaal
Copy link
Contributor Author

zJaaal commented May 30, 2024

We discussed all the remaining changes and decided to create another issue to address @fmontes feedback because we need refactors and naming changes that are out of scope of the issue. The ticket is pending to be created, I will share it when It's ready.

@zJaaal
Copy link
Contributor Author

zJaaal commented May 31, 2024

Here is the ticket that will continue the work of this PR #28711

@zJaaal zJaaal enabled auto-merge May 31, 2024 13:33
@zJaaal zJaaal added this pull request to the merge queue May 31, 2024
Merged via the queue into master with commit f73403e May 31, 2024
15 checks passed
@zJaaal zJaaal deleted the 28634-sdk-content-api-getcollection-method branch May 31, 2024 14:54
@zJaaal zJaaal restored the 28634-sdk-content-api-getcollection-method branch May 31, 2024 15:40
@zJaaal zJaaal deleted the 28634-sdk-content-api-getcollection-method branch May 31, 2024 15:41
spbolton pushed a commit that referenced this pull request Jun 3, 2024
## Proposed Changes
* Add `Content` Class to handle Content API Methods and expose it as a
method of the Dotcms Client
* Add `GetCollection` Class to handle the building of a query for
collections and expose it as a method of `Content` Class

## Usage example for standalone `getCollection`

This an example of a query with all possible methods it supports (could
not be a real use case and it should be used from the `client.content`).

```typescript
        const requestOptions: Omit<RequestInit, 'body' | 'method'> = {
            cache: 'no-cache' // To simulate a valid request
        };

        const serverUrl = 'http://localhost:8080';

        const contentType = 'forceSensitive';
        const client = new GetCollection(requestOptions, serverUrl, contentType);

        const response = await client
            .language(13) // Language Id
            .render(true) // To retrieve the content with the render
            .sortBy([
                // Sort by multiple fields
                {
                    field: 'name',
                    order: 'asc'
                },
                {
                    field: 'midichlorians',
                    order: 'desc'
                }
            ])
            .depth(2) // Depth of the content for relationships
            .limit(20) // Limit of content per page
            .page(3) // Page to fetch
            .query(
                (
                    qb // Lucene query to append to the main query for more complex queries
                ) =>
                    qb
                        .field('kyberCrystal')
                        .equals('red')
                        .and()
                        .equals('blue')
                        .field('master')
                        .equals('Yoda')
                        .or()
                        .equals('Obi-Wan')
            )
            .draft(true) // To retrieve the draft content
            .variant('legends-forceSensitive') // Variant of the content
            .rawQuery('+modDate:2024-05-28 +conhost:MyCoolSite') // Raw query to append to the main query
            .fetch(); // Fetch the content
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SDK: Content API getCollection Method
6 participants