Skip to content

Commit 147a6b8

Browse files
feat: updateVisibility 구현
1 parent aecb87b commit 147a6b8

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

apps/backend/src/workspace/workspace.controller.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe('WorkspaceController', () => {
2727
generateInviteUrl: jest.fn(),
2828
processInviteUrl: jest.fn(),
2929
checkAccess: jest.fn(),
30+
updateVisibility: jest.fn(),
3031
},
3132
},
3233
{

apps/backend/src/workspace/workspace.controller.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
Post,
44
Delete,
55
Get,
6+
Patch,
67
UseGuards,
78
Request,
89
Body,
@@ -27,6 +28,8 @@ export enum WorkspaceResponseMessage {
2728
WORKSPACE_INVITED = '워크스페이스 게스트 초대 링크가 생성되었습니다.',
2829
WORKSPACE_JOINED = '워크스페이스에 게스트로 등록되었습니다.',
2930
WORKSPACE_ACCESS_CHECKED = '워크스페이스에 대한 사용자의 접근 권한이 확인되었습니다.',
31+
WORKSPACE_UPDATED_TO_PUBLIC = '워크스페이스가 공개로 설정되었습니다.',
32+
WORKSPACE_UPDATED_TO_PRIVATE = '워크스페이스가 비공개로 설정되었습니다.',
3033
}
3134

3235
@Controller('workspace')
@@ -152,4 +155,34 @@ export class WorkspaceController {
152155
message: WorkspaceResponseMessage.WORKSPACE_ACCESS_CHECKED,
153156
};
154157
}
158+
159+
@ApiResponse({
160+
type: MessageResponseDto,
161+
})
162+
@ApiOperation({
163+
summary: '워크스페이스를 비공개에서 공개로 설정합니다.',
164+
})
165+
@Patch('/:id/public')
166+
@UseGuards(JwtAuthGuard) // 로그인 인증
167+
@HttpCode(HttpStatus.OK)
168+
async makeWorkspacePublic(@Request() req, @Param('id') id: string) {
169+
const userId = req.user.sub; // 인증된 사용자 ID
170+
await this.workspaceService.updateVisibility(userId, id, 'public');
171+
return { message: WorkspaceResponseMessage.WORKSPACE_UPDATED_TO_PUBLIC };
172+
}
173+
174+
@ApiResponse({
175+
type: MessageResponseDto,
176+
})
177+
@ApiOperation({
178+
summary: '워크스페이스를 공개에서 비공개로 설정합니다.',
179+
})
180+
@Patch('/:id/private')
181+
@UseGuards(JwtAuthGuard) // 로그인 인증
182+
@HttpCode(HttpStatus.OK)
183+
async makeWorkspacePrivate(@Request() req, @Param('id') id: string) {
184+
const userId = req.user.sub; // 인증된 사용자 ID
185+
await this.workspaceService.updateVisibility(userId, id, 'private');
186+
return { message: WorkspaceResponseMessage.WORKSPACE_UPDATED_TO_PRIVATE };
187+
}
155188
}

apps/backend/src/workspace/workspace.service.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,34 @@ export class WorkspaceService {
263263
});
264264
}
265265
}
266+
267+
async updateVisibility(
268+
userId: number,
269+
workspaceId: string,
270+
visibility: 'public' | 'private',
271+
): Promise<void> {
272+
// 워크스페이스가 존재하는지 확인
273+
const workspace = await this.workspaceRepository.findOneBy({
274+
snowflakeId: workspaceId,
275+
});
276+
277+
if (!workspace) {
278+
throw new WorkspaceNotFoundException();
279+
}
280+
281+
// Role Repository에서 해당 workspace의 owner인지 확인
282+
const role = await this.roleRepository.findOneBy({
283+
workspaceId: workspace.id,
284+
userId: userId,
285+
role: 'owner',
286+
});
287+
// 아니면 exception 뱉기
288+
if (!role) {
289+
throw new NotWorkspaceOwnerException();
290+
}
291+
292+
// 가시성 변경
293+
workspace.visibility = visibility;
294+
await this.workspaceRepository.save(workspace);
295+
}
266296
}

0 commit comments

Comments
 (0)