Skip to content

Commit

Permalink
Add controller for retrieving the document list in the workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
devleejb committed Jan 18, 2024
1 parent ed1c265 commit e5c1621
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApiProperty } from "@nestjs/swagger";
import { WorkspaceDocumentDomain } from "./workspace-document-domain.type";

export class FindWorkspaceUsersResponse {
export class FindWorkspaceDocumentsResponse {
@ApiProperty({
type: [WorkspaceDocumentDomain],
description: "List of found workspace documents",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
import { Body, Controller, Get, Param, Post, Req } from "@nestjs/common";
import {
Body,
Controller,
DefaultValuePipe,
Get,
Param,
ParseIntPipe,
Post,
Query,
Req,
} from "@nestjs/common";
import { WorkspaceDocumentsService } from "./workspace-documents.service";
import {
ApiBearerAuth,
Expand All @@ -7,13 +17,15 @@ import {
ApiFoundResponse,
ApiNotFoundResponse,
ApiOperation,
ApiQuery,
ApiTags,
} from "@nestjs/swagger";
import { AuthroizedRequest } from "src/utils/types/req.type";
import { CreateWorkspaceDocumentDto } from "./dto/create-workspace-document.dto";
import { CreateWorkspaceDocumentResponse } from "./types/create-workspace-document-response.type";
import { HttpExceptionResponse } from "src/utils/types/http-exception-response.type";
import { FindWorkspaceDocumentResponse } from "./types/find-workspace-document-response.type";
import { FindWorkspaceDocumentsResponse } from "./types/find-workspace-documents-response.type";

@ApiTags("Workspace.Documents")
@ApiBearerAuth()
Expand All @@ -40,6 +52,38 @@ export class WorkspaceDocumentsController {
return this.workspaceDocumentsService.findOne(req.user.id, workspaceId, documentId);
}

@Get("")
@ApiOperation({
summary: "Retrieve the Documents in Workspace",
description: "Return the documents in the workspace. This API supports KeySet pagination.",
})
@ApiFoundResponse({ type: FindWorkspaceDocumentsResponse })
@ApiNotFoundResponse({
type: HttpExceptionResponse,
description: "The workspace does not exist, or the user lacks the appropriate permissions.",
})
@ApiQuery({
name: "page_size",
type: Number,
description: "Page size to fetch (Default to 10)",
required: false,
})
@ApiQuery({
name: "cursor",
type: String,
description:
"API returns a limited set of results after a given cursor. If no value is provided, it returns the first page.",
required: false,
})
async findMany(
@Req() req: AuthroizedRequest,
@Param("workspace_id") workspaceId: string,
@Query("page_size", new DefaultValuePipe(10), ParseIntPipe) pageSize: number,
@Query("cursor", new DefaultValuePipe(undefined)) cursor?: string
): Promise<FindWorkspaceDocumentsResponse> {
return this.workspaceDocumentsService.findMany(req.user.id, workspaceId, pageSize, cursor);
}

@Post()
@ApiOperation({
summary: "Create a Document in a Workspace",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable, NotFoundException } from "@nestjs/common";
import { Prisma } from "@prisma/client";
import { PrismaService } from "src/db/prisma.service";
import { FindWorkspaceUsersResponse } from "./types/find-workspace-documents-response.type";
import { FindWorkspaceDocumentsResponse } from "./types/find-workspace-documents-response.type";

@Injectable()
export class WorkspaceDocumentsService {
Expand Down Expand Up @@ -52,7 +52,7 @@ export class WorkspaceDocumentsService {
workspaceId: string,
pageSize: number,
cursor?: string
): Promise<FindWorkspaceUsersResponse> {
): Promise<FindWorkspaceDocumentsResponse> {
try {
await this.prismaService.userWorkspace.findFirstOrThrow({
where: {
Expand Down

0 comments on commit e5c1621

Please sign in to comment.