Skip to content

Commit

Permalink
Merge pull request #120 from tnpfldyd/BE-feature/cache-server/swagger
Browse files Browse the repository at this point in the history
์บ์‹œ์„œ๋ฒ„ ์Šค์›จ๊ฑฐ ์ ์šฉ
  • Loading branch information
Conut-1 authored Nov 29, 2023
2 parents c38463b + 08e5699 commit 2086ff3
Show file tree
Hide file tree
Showing 17 changed files with 341 additions and 45 deletions.
7 changes: 1 addition & 6 deletions nestjs-BE/cache-server/src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { Controller, Get } from '@nestjs/common';
import { Controller } from '@nestjs/common';
import { AppService } from './app.service';

@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}

@Get()
getHello(): string {
return this.appService.getHello();
}
}
6 changes: 1 addition & 5 deletions nestjs-BE/cache-server/src/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!';
}
}
export class AppService {}
10 changes: 10 additions & 0 deletions nestjs-BE/cache-server/src/base/base.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,22 @@ export abstract class BaseService<T extends HasUuid> {
}

async remove(key: string) {
const storeData = this.getDataFromCacheOrDB(key);
if (!storeData) return;
this.cache.delete(key);
const insertTemporaryData = this.temporaryDatabaseService.get(
this.className,
key,
'insert',
);
const updateTemporaryData = this.temporaryDatabaseService.get(
this.className,
key,
'update',
);
if (updateTemporaryData) {
this.temporaryDatabaseService.delete(this.className, key, 'update');
}
if (insertTemporaryData) {
this.temporaryDatabaseService.delete(this.className, key, 'insert');
} else {
Expand Down
59 changes: 50 additions & 9 deletions nestjs-BE/cache-server/src/boards/boards.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,69 @@ import {
import { BoardsService } from './boards.service';
import { CreateBoardDto } from './dto/create-board.dto';
import { UpdateBoardDto } from './dto/update-board.dto';
import { ApiTags, ApiResponse, ApiOperation } from '@nestjs/swagger';

@Controller('boards')
@ApiTags('boards')
export class BoardsController {
constructor(private readonly boardsService: BoardsService) {}

@Post()
@ApiOperation({ summary: 'Create board' })
@ApiResponse({
status: 201,
description: 'The board has been successfully created.',
})
@ApiResponse({
status: 400,
description: 'Bad Request. Invalid input data.',
})
create(@Body() createBoardDto: CreateBoardDto) {
return this.boardsService.create(createBoardDto);
}

@Get(':uuid')
findOne(@Param('uuid') uuid: string) {
return this.boardsService.findOne(uuid);
@Get(':board_uuid')
@ApiOperation({ summary: 'Get board by board_uuid' })
@ApiResponse({
status: 200,
description: 'Return the board data.',
})
@ApiResponse({
status: 404,
description: 'Board not found.',
})
findOne(@Param('board_uuid') boardUuid: string) {
return this.boardsService.findOne(boardUuid);
}

@Patch(':uuid')
update(@Param('uuid') uuid: string, @Body() updateBoardDto: UpdateBoardDto) {
return this.boardsService.update(uuid, updateBoardDto);
@Patch(':board_uuid')
@ApiOperation({ summary: 'Update board by board_uuid' })
@ApiResponse({
status: 200,
description: 'Board has been successfully updated.',
})
@ApiResponse({
status: 404,
description: 'Board not found.',
})
update(
@Param('board_uuid') boardUuid: string,
@Body() updateBoardDto: UpdateBoardDto,
) {
return this.boardsService.update(boardUuid, updateBoardDto);
}

@Delete(':uuid')
remove(@Param('uuid') uuid: string) {
return this.boardsService.remove(uuid);
@Delete(':board_uuid')
@ApiOperation({ summary: 'Remove board by board_uuid' })
@ApiResponse({
status: 200,
description: 'Board has been successfully removed.',
})
@ApiResponse({
status: 404,
description: 'Board not found.',
})
remove(@Param('board_uuid') boardUuid: string) {
return this.boardsService.remove(boardUuid);
}
}
9 changes: 8 additions & 1 deletion nestjs-BE/cache-server/src/boards/dto/create-board.dto.ts
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
export class CreateBoardDto {}
import { ApiProperty } from '@nestjs/swagger';
export class CreateBoardDto {
@ApiProperty({
example: { key1: 'value1', key2: 'value2' },
description: 'JSON data as an object',
})
data: Record<string, string>;
}
7 changes: 7 additions & 0 deletions nestjs-BE/cache-server/src/boards/dto/update-board.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { PartialType } from '@nestjs/swagger';
import { CreateBoardDto } from './create-board.dto';
import { ApiProperty } from '@nestjs/swagger';

export class UpdateBoardDto extends PartialType(CreateBoardDto) {
uuid?: string;

@ApiProperty({
example: { key1: 'value1', key2: 'value2' },
description: 'JSON data as an object for updating the board',
})
data: Record<string, string>;
}
2 changes: 1 addition & 1 deletion nestjs-BE/cache-server/src/config/swagger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DocumentBuilder } from '@nestjs/swagger';
export const swaggerConfig = new DocumentBuilder()
.setTitle('mind-sync db-api')
.setTitle('mind-sync cache-server-api')
.setDescription('API description')
.setVersion('1.0')
.build();
16 changes: 16 additions & 0 deletions nestjs-BE/cache-server/src/profiles/dto/create-profile.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
import { ApiProperty } from '@nestjs/swagger';

export class CreateProfileDto {
@ApiProperty({
example: 'user-uuid-123',
description: 'User UUID for the profile',
})
user_id: string;

@ApiProperty({
example: 'profile-image.png',
description: 'Image URL for the profile',
})
image: string;

@ApiProperty({
example: 'Sample nickname',
description: 'Nickname for the profile',
})
nickname: string;
}
8 changes: 8 additions & 0 deletions nestjs-BE/cache-server/src/profiles/dto/profile-space.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { ApiProperty } from '@nestjs/swagger';

export class ProfileSpaceDto {
@ApiProperty({
example: 'profile-uuid-123',
description: 'UUID of the profile',
})
profile_uuid: string;

@ApiProperty({ example: 'space-uuid-456', description: 'UUID of the space' })
space_uuid: string;
}
15 changes: 15 additions & 0 deletions nestjs-BE/cache-server/src/profiles/dto/update-profile.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreateProfileDto } from './create-profile.dto';
import { ApiProperty } from '@nestjs/swagger';

export class UpdateProfileDto extends PartialType(CreateProfileDto) {
@ApiProperty({
example: 'new nickname',
description: 'Updated nickname of the profile',
required: false,
})
nickname?: string;

@ApiProperty({
example: 'new image.png',
description: 'Updated image URL for the profile',
required: false,
})
image?: string;

uuid?: string;
}
89 changes: 77 additions & 12 deletions nestjs-BE/cache-server/src/profiles/profiles.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,114 @@ import { ProfilesService } from './profiles.service';
import { CreateProfileDto } from './dto/create-profile.dto';
import { UpdateProfileDto } from './dto/update-profile.dto';
import { ProfileSpaceDto } from './dto/profile-space.dto';
import { ApiTags, ApiResponse, ApiOperation } from '@nestjs/swagger';

@Controller('profiles')
@ApiTags('profiles')
export class ProfilesController {
constructor(private readonly profilesService: ProfilesService) {}

@Post()
@ApiOperation({ summary: 'Create profile' })
@ApiResponse({
status: 201,
description: 'The profile has been successfully created.',
})
@ApiResponse({
status: 400,
description: 'Bad Request. Invalid input data.',
})
create(@Body() createProfileDto: CreateProfileDto) {
return this.profilesService.create(createProfileDto);
}

@Get(':uuid')
findOne(@Param('uuid') uuid: string) {
return this.profilesService.findOne(uuid);
@Get(':profile_uuid')
@ApiOperation({ summary: 'Get profile by profile_uuid' })
@ApiResponse({
status: 200,
description: 'Return the profile data.',
})
@ApiResponse({
status: 404,
description: 'Profile not found.',
})
findOne(@Param('profile_uuid') profileUuid: string) {
return this.profilesService.findOne(profileUuid);
}

@Patch(':uuid')
@Patch(':profile_uuid')
@ApiOperation({ summary: 'Update profile by profile_uuid' })
@ApiResponse({
status: 200,
description: 'Profile has been successfully updated.',
})
@ApiResponse({
status: 404,
description: 'Profile not found.',
})
update(
@Param('uuid') uuid: string,
@Param('profile_uuid') profileUuid: string,
@Body() updateProfileDto: UpdateProfileDto,
) {
return this.profilesService.update(uuid, updateProfileDto);
return this.profilesService.update(profileUuid, updateProfileDto);
}

@Delete(':uuid')
remove(@Param('uuid') uuid: string) {
return this.profilesService.remove(uuid);
@Delete(':profile_uuid')
@ApiOperation({ summary: 'Remove profile by profile_uuid' })
@ApiResponse({
status: 200,
description: 'Profile has been successfully removed.',
})
@ApiResponse({
status: 404,
description: 'Profile not found.',
})
remove(@Param('profile_uuid') profileUuid: string) {
return this.profilesService.remove(profileUuid);
}

@Post('/spaces')
@ApiOperation({ summary: 'Join space' })
@ApiResponse({
status: 201,
description: 'Joined the space successfully.',
})
@ApiResponse({
status: 400,
description: 'Bad Request. Invalid input data.',
})
joinSpace(@Body() profileSpaceDto: ProfileSpaceDto) {
return this.profilesService.joinSpace(profileSpaceDto);
}

@Delete(':profile_uuid/spaces/:space_uuid')
@ApiOperation({ summary: 'Leave space' })
@ApiResponse({
status: 200,
description: 'Left the space successfully.',
})
@ApiResponse({
status: 404,
description: 'Profile or space not found.',
})
leaveSpace(
@Param('profile_uuid') profileUuid: string,
@Param('space_uuid') spaceUuid: string,
) {
return this.profilesService.leaveSpace(profileUuid, spaceUuid);
}

@Get('users/:uuid')
findUsers(@Param('uuid') uuid: string) {
return this.profilesService.findUsers(uuid);
@Get('users/:space_uuid')
@ApiOperation({ summary: 'Find users in a space' })
@ApiResponse({
status: 200,
description: 'Return the list of users in the space.',
})
@ApiResponse({
status: 404,
description: 'Space not found.',
})
findUsers(@Param('space_uuid') spaceUuid: string) {
return this.profilesService.findUsers(spaceUuid);
}
}
8 changes: 8 additions & 0 deletions nestjs-BE/cache-server/src/spaces/dto/create-space.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { ApiProperty } from '@nestjs/swagger';

export class CreateSpaceDto {
@ApiProperty({ example: 'Sample Space', description: 'Name of the space' })
name: string;

@ApiProperty({
example: 'space-icon.png',
description: 'Profile icon for the space',
})
icon: string;
}
15 changes: 15 additions & 0 deletions nestjs-BE/cache-server/src/spaces/dto/update-space.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
import { PartialType } from '@nestjs/mapped-types';
import { CreateSpaceDto } from './create-space.dto';
import { ApiProperty } from '@nestjs/swagger';

export class UpdateSpaceDto extends PartialType(CreateSpaceDto) {
@ApiProperty({
example: 'new space',
description: 'Updated space name',
required: false,
})
name?: string;

@ApiProperty({
example: 'new image',
description: 'Updated space icon',
required: false,
})
icon?: string;

uuid?: string;
}
Loading

0 comments on commit 2086ff3

Please sign in to comment.