-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #246 from Quickchive/refactor-#245/divide-domain
refactor: divide domain
- Loading branch information
Showing
23 changed files
with
860 additions
and
771 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
import { | ||
Controller, | ||
UseGuards, | ||
Post, | ||
UseInterceptors, | ||
Body, | ||
Patch, | ||
Delete, | ||
Param, | ||
ParseIntPipe, | ||
Query, | ||
ParseBoolPipe, | ||
Get, | ||
} from '@nestjs/common'; | ||
import { | ||
ApiTags, | ||
ApiBearerAuth, | ||
ApiOperation, | ||
ApiCreatedResponse, | ||
ApiConflictResponse, | ||
ApiNotFoundResponse, | ||
ApiOkResponse, | ||
} from '@nestjs/swagger'; | ||
import { EntityManager } from 'typeorm'; | ||
import { AuthUser } from '../auth/auth-user.decorator'; | ||
import { JwtAuthGuard } from '../auth/jwt/jwt.guard'; | ||
import { ErrorOutput } from '../common/dtos/output.dto'; | ||
import { TransactionInterceptor } from '../common/interceptors/transaction.interceptor'; | ||
import { TransactionManager } from '../common/transaction.decorator'; | ||
import { | ||
AddCategoryOutput, | ||
AddCategoryBodyDto, | ||
UpdateCategoryOutput, | ||
UpdateCategoryBodyDto, | ||
DeleteCategoryOutput, | ||
AutoCategorizeOutput, | ||
} from './dtos/category.dto'; | ||
import { | ||
LoadPersonalCategoriesOutput, | ||
LoadFrequentCategoriesOutput, | ||
} from './dtos/load-personal-categories.dto'; | ||
import { User } from '../users/entities/user.entity'; | ||
import { CategoryService } from './category.service'; | ||
|
||
@Controller('categories') | ||
@ApiTags('Category') | ||
@ApiBearerAuth('Authorization') | ||
@UseGuards(JwtAuthGuard) | ||
export class CategoryController { | ||
constructor(private readonly categoryService: CategoryService) {} | ||
|
||
@ApiOperation({ | ||
summary: '카테고리 추가', | ||
description: '카테고리를 추가하는 메서드', | ||
}) | ||
@ApiCreatedResponse({ | ||
description: '카테고리 추가 성공 여부를 반환한다.', | ||
type: AddCategoryOutput, | ||
}) | ||
@ApiConflictResponse({ | ||
description: '동일한 이름의 카테고리가 존재할 경우', | ||
type: ErrorOutput, | ||
}) | ||
@ApiNotFoundResponse({ | ||
description: '존재하지 않는 것일 경우', | ||
type: ErrorOutput, | ||
}) | ||
@Post() | ||
@UseInterceptors(TransactionInterceptor) | ||
async addCategory( | ||
@AuthUser() user: User, | ||
@Body() addCategoryBody: AddCategoryBodyDto, | ||
@TransactionManager() queryRunnerManager: EntityManager, | ||
): Promise<AddCategoryOutput> { | ||
return this.categoryService.addCategory( | ||
user, | ||
addCategoryBody, | ||
queryRunnerManager, | ||
); | ||
} | ||
|
||
@ApiOperation({ | ||
summary: '카테고리 수정', | ||
description: '카테고리 이름을 수정하는 메서드', | ||
}) | ||
@ApiCreatedResponse({ | ||
description: '카테고리 수정 성공 여부를 반환한다.', | ||
type: UpdateCategoryOutput, | ||
}) | ||
@Patch() | ||
@UseInterceptors(TransactionInterceptor) | ||
async updateCategory( | ||
@AuthUser() user: User, | ||
@Body() updateCategoryBody: UpdateCategoryBodyDto, | ||
@TransactionManager() queryRunnerManager: EntityManager, | ||
): Promise<UpdateCategoryOutput> { | ||
return this.categoryService.updateCategory( | ||
user, | ||
updateCategoryBody, | ||
queryRunnerManager, | ||
); | ||
} | ||
|
||
@ApiOperation({ | ||
summary: '카테고리 삭제', | ||
description: '카테고리를 삭제하는 메서드', | ||
}) | ||
@ApiOkResponse({ | ||
description: '카테고리 삭제 성공 여부를 반환한다.', | ||
type: DeleteCategoryOutput, | ||
}) | ||
@ApiNotFoundResponse({ | ||
description: '존재하지 않는 카테고리를 삭제하려고 할 경우', | ||
type: ErrorOutput, | ||
}) | ||
@Delete(':categoryId') | ||
@UseInterceptors(TransactionInterceptor) | ||
async deleteCategory( | ||
@AuthUser() user: User, | ||
@Param('categoryId', new ParseIntPipe()) categoryId: number, | ||
@Query('deleteContentFlag', new ParseBoolPipe()) deleteContentFlag: boolean, | ||
@TransactionManager() queryRunnerManager: EntityManager, | ||
): Promise<DeleteCategoryOutput> { | ||
return this.categoryService.deleteCategory( | ||
user, | ||
categoryId, | ||
deleteContentFlag, | ||
queryRunnerManager, | ||
); | ||
} | ||
|
||
@ApiOperation({ | ||
summary: '자신의 카테고리 목록 조회', | ||
description: '자신의 카테고리 목록을 조회하는 메서드', | ||
}) | ||
@ApiOkResponse({ | ||
description: '카테고리 목록을 반환한다.', | ||
type: LoadPersonalCategoriesOutput, | ||
}) | ||
@ApiBearerAuth('Authorization') | ||
@UseGuards(JwtAuthGuard) | ||
@Get() | ||
async loadPersonalCategories( | ||
@AuthUser() user: User, | ||
): Promise<LoadPersonalCategoriesOutput> { | ||
return this.categoryService.loadPersonalCategories(user); | ||
} | ||
|
||
@ApiOperation({ | ||
summary: '자주 저장한 카테고리 조회', | ||
description: '자주 저장한 카테고리를 3개까지 조회하는 메서드', | ||
}) | ||
@ApiOkResponse({ | ||
description: '자주 저장한 카테고리를 최대 3개까지 반환한다.', | ||
type: LoadFrequentCategoriesOutput, | ||
}) | ||
@ApiBearerAuth('Authorization') | ||
@UseGuards(JwtAuthGuard) | ||
@Get('frequent') | ||
async loadFrequentCategories( | ||
@AuthUser() user: User, | ||
): Promise<LoadFrequentCategoriesOutput> { | ||
return this.categoryService.loadFrequentCategories(user); | ||
} | ||
|
||
@ApiOperation({ | ||
summary: '아티클 카테고리 자동 지정', | ||
description: | ||
'아티클에 적절한 카테고리를 유저의 카테고리 목록에서 찾는 메서드', | ||
}) | ||
@ApiBearerAuth('Authorization') | ||
@UseGuards(JwtAuthGuard) | ||
@Get('auto-categorize') | ||
async autoCategorize( | ||
@AuthUser() user: User, | ||
@Query('link') link: string, | ||
): Promise<AutoCategorizeOutput> { | ||
return this.categoryService.autoCategorize(user, link); | ||
} | ||
} |
8 changes: 4 additions & 4 deletions
8
src/contents/entities/category.entity.ts → src/categories/category.entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ContentsModule } from '../contents/contents.module'; | ||
import { CategoryService } from './category.service'; | ||
import { CategoryUtil } from '../contents/util/category.util'; | ||
import { OpenaiModule } from '../openai/openai.module'; | ||
import { UsersModule } from '../users/users.module'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { Category } from './category.entity'; | ||
import { CategoryController } from './category.controller'; | ||
import { ContentRepository } from '../contents/repository/content.repository'; | ||
import { CategoryRepository } from './category.repository'; | ||
import { ContentUtil } from '../contents/util/content.util'; | ||
|
||
@Module({ | ||
imports: [ | ||
TypeOrmModule.forFeature([Category]), | ||
ContentsModule, | ||
OpenaiModule, | ||
UsersModule, | ||
], | ||
controllers: [CategoryController], | ||
providers: [ | ||
CategoryService, | ||
CategoryUtil, | ||
ContentRepository, | ||
CategoryRepository, | ||
ContentUtil, | ||
], | ||
exports: [CategoryRepository], | ||
}) | ||
export class CategoryModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.