Skip to content

Commit

Permalink
feat: add content search
Browse files Browse the repository at this point in the history
  • Loading branch information
aliosmandev committed Apr 3, 2024
1 parent 6543265 commit 67a4ee1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
31 changes: 31 additions & 0 deletions apps/docs/content/2.api/1.contents.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,39 @@ async function getContentsWithQuery({ query, type=ContentStatusEnum.published, c
}
}
```
```ts [With pagination]
import { GetContentsType, ContentStatusEnum } from '@postiva/client'

async function getContentsWithPagination({ query, type=ContentStatusEnum.published, category }: GetContentsType) {
try {
const contents = await client.getContents({ query, type, category }).pagination({ size: 10, page: 1 })
console.log(contents);
} catch (error) {
console.error('Error fetching contents:', error);
}
}
```
::

### `searchContents`

- **Parameters**
- query: `string`
- **Returns:** [`Promise<Content[]>`](types#contentsresponse)

search contents by query.

```typescript
async function searchContents(query: string) {
try {
const content = await postivaClient.contents.searchContents(query);
console.log(content);
} catch (error) {
console.error('Error fetching content:', error);
}
}
```

### `getContentById`

- **Parameters**
Expand Down
15 changes: 14 additions & 1 deletion packages/library/src/classes/Contents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,20 @@ export class Contents {
};

const { data } = await this.fetcher.request<APIResponse<DetailContent>>(
`contents/slug/${slug}`,
`contents/search/${slug}`,
defaultOptions
);

return data;
}

async searchContents(query: string): Promise<Content[]> {
const defaultOptions = {
method: "GET",
};

const { data } = await this.fetcher.request<APIResponse<Content[]>>(
`contents/search?query=${query}`,
defaultOptions
);

Expand Down

0 comments on commit 67a4ee1

Please sign in to comment.