Skip to content

Commit

Permalink
Add controller for retrieving a workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
devleejb committed Jan 18, 2024
1 parent af82f93 commit 3238cd4
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
9 changes: 9 additions & 0 deletions backend/src/utils/types/http-exception-response.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { HttpStatus } from "@nestjs/common";
import { ApiProperty } from "@nestjs/swagger";

export class HttpExceptionResponse {
@ApiProperty({ enum: HttpStatus, description: "Status Code of HTTP Response" })
statusCode: HttpStatus;
@ApiProperty({ type: String, description: "Description about the error" })
message: string;
}
12 changes: 12 additions & 0 deletions backend/src/workspaces/types/find-workspace-response.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ApiProperty } from "@nestjs/swagger";

export class FindWorkspaceResponse {
@ApiProperty({ type: String, description: "ID of found workspace" })
id: string;
@ApiProperty({ type: String, description: "Title of found workspace" })
title: string;
@ApiProperty({ type: Date, description: "Created date of found workspace" })
createdAt: Date;
@ApiProperty({ type: Date, description: "Updated date of found workspace" })
updatedAt: Date;
}
28 changes: 26 additions & 2 deletions backend/src/workspaces/workspaces.controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import { Body, Controller, Post, Req } from "@nestjs/common";
import { Body, Controller, Get, Param, Post, Req } from "@nestjs/common";
import { WorkspacesService } from "./workspaces.service";
import { CreateWorkspaceDto } from "./dto/CreateWorkspace.dto";
import { ApiBearerAuth, ApiBody, ApiCreatedResponse, ApiOperation, ApiTags } from "@nestjs/swagger";
import {
ApiBearerAuth,
ApiBody,
ApiCreatedResponse,
ApiFoundResponse,
ApiNotFoundResponse,
ApiOperation,
ApiTags,
} from "@nestjs/swagger";
import { AuthroizedRequest } from "src/utils/types/req.type";
import { CreateWorkspaceResponse } from "./types/create-workspace-response.type";
import { FindWorkspaceResponse } from "./types/find-workspace-response.type";
import { HttpExceptionResponse } from "src/utils/types/http-exception-response.type";

@ApiTags("Workspaces")
@ApiBearerAuth()
Expand All @@ -24,4 +34,18 @@ export class WorkspacesController {
): Promise<CreateWorkspaceResponse> {
return this.workspacesService.create(req.user.id, createWorkspaceDto.title);
}

@Get(":id")
@ApiOperation({
summary: "Retrieve a Workspace",
description: "If the user has the access permissions, return a workspace.",
})
@ApiFoundResponse({ type: FindWorkspaceResponse })
@ApiNotFoundResponse({
type: HttpExceptionResponse,
description: "The Workspace does not exist, or the user lacks the appropriate permissions.",
})
async findOne(@Req() req: AuthroizedRequest, @Param("id") workspaceId: string) {
return this.workspacesService.findOne(req.user.id, workspaceId);
}
}
2 changes: 1 addition & 1 deletion backend/src/workspaces/workspaces.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class WorkspacesService {
throw new NotFoundException();
}

return await this.prismaService.workspace.findUnique({
return this.prismaService.workspace.findUnique({
where: {
id: workspaceId,
},
Expand Down

0 comments on commit 3238cd4

Please sign in to comment.