# 코드 변경 내용과 설명서 동기화

공동 파일럿 채팅는 코드 문서를 최신 상태로 유지하는 데 도움을 줄 수 있습니다.

코드를 변경하여 문서를 최신 상태로 유지하는 것은 어려울 수 있습니다. 그러나 코드베이스를 유지 관리하고 개발자가 코드를 효과적으로 사용할 수 있도록 하려면 좋은 설명서가 필요합니다.
공동 파일럿 채팅 는 기존 코드 설명서를 업데이트하는 데 도움이 될 수 있습니다.

## 예제 시나리오

범주 이름으로 제품을 검색하는 TypeScript 함수가 있지만 설명서가 최신 상태가 아닌 시나리오를 상상해 보세요.

```typescript id=fetch-products-by-category
/**
 * Retrieves all products belonging to a specific category.
 * * @param categoryId - The unique identifier of the product category
 * @returns Promise that resolves to an array of Product objects
 * * @example
 * const products = await getByCategoryName(5);
 * // Returns: [{id: 1, name: "Product 1", categoryId: 5}, ...]
 * * @throws {PrismaClientKnownRequestError} If database query fails
 * @see {@link https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#findmany}
 */
async getByCategoryName(categoryId: number, page = 1, pageSize = 10): Promise<Products[]> {
  return await prisma.products.findMany({
    where: { categoryId },
    skip: (page - 1) * pageSize,
    take: pageSize,
    include: {
      reviews: {
        orderBy: { date: 'desc' },
        take: 5,
      },
    },
  });
}
```

## 예제 프롬프트

현재 코드에 따라 설명서를 업데이트하도록 요청할 공동 파일럿 채팅 수 있습니다.

```copilot copy prompt ref=fetch-products-by-category
Update the existing documentation for the getByCategoryName function to reflect the current implementation.
```

## 응답 예제

> \[!NOTE] 다음 응답이 예제입니다. 공동 파일럿 채팅 응답은 비결정적이므로 여기에 표시된 응답과 다른 응답을 얻을 수 있습니다.

Copilot는 `getByCategoryName` 함수에 대한 업데이트된 문서를 생성할 것이라고 설명합니다. 그런 다음, `page` 및 `pageSize` 매개 변수와 발생할 수 있는 `PrismaClientKnownRequestError` 오류가 포함된 업데이트된 문서를 제공합니다.

다음은 그 예입니다.

```typescript
/**
 * Retrieves all products belonging to a specific category with pagination and recent reviews.
 * * @param categoryId - The unique identifier of the product category
 * @param page - The page number for pagination (default: 1)
 * @param pageSize - Number of products per page (default: 10)
 * @returns Promise that resolves to an array of Product objects with their 5 most recent reviews
 * * @example
 * const products = await getByCategoryName(5, 2, 20);
 * // Returns: [{id: 1, name: "Product 1", categoryId: 5, reviews: [...5 recent reviews]}, ...]
 * * @throws {PrismaClientKnownRequestError} If database query fails
 * @see {@link https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#findmany}
 */
```

## 추가 읽기

* [GitHub Copilot 채팅에 대한 프롬프트 엔지니어링](/ko/copilot/using-github-copilot/prompt-engineering-for-github-copilot)
* [GitHub 부필로트 사용에 대한 모범 사례](/ko/copilot/using-github-copilot/best-practices-for-using-github-copilot)