Skip to content

Commit

Permalink
Merge pull request #246 from Quickchive/refactor-#245/divide-domain
Browse files Browse the repository at this point in the history
refactor: divide domain
  • Loading branch information
stae1102 authored Jan 29, 2024
2 parents 78e4b41 + b33b26a commit 95e5c6d
Show file tree
Hide file tree
Showing 23 changed files with 860 additions and 771 deletions.
2 changes: 2 additions & 0 deletions src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { UsersModule } from '../users/users.module';
import { OAuthUtil } from './util/oauth.util';
import { ContentsModule } from '../contents/contents.module';
import { OAuthService } from './oauth.service';
import { CategoryModule } from '../categories/category.module';

const accessTokenExpiration = TWOHOUR;
export const refreshTokenExpirationInCache = 60 * 60 * 24 * 365; // 1 year
Expand All @@ -35,6 +36,7 @@ export const verifyEmailExpiration = 60 * 5;
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT,
}),
CategoryModule,
],
controllers: [AuthController, OAuthController],
providers: [
Expand Down
2 changes: 1 addition & 1 deletion src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { KakaoAuthorizeOutput, LoginWithKakaoDto } from './dtos/kakao.dto';
import { googleUserInfo } from './dtos/google.dto';
import { customJwtService } from './jwt/jwt.service';
import { UserRepository } from '../users/repository/user.repository';
import { CategoryRepository } from '../contents/repository/category.repository';
import { CategoryRepository } from '../categories/category.repository';
import { OAuthUtil } from './util/oauth.util';

@Injectable()
Expand Down
2 changes: 1 addition & 1 deletion src/auth/oauth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { LoginOutput } from './dtos/login.dto';
import { Payload } from './jwt/jwt.payload';
import { customJwtService } from './jwt/jwt.service';
import { OAuthUtil } from './util/oauth.util';
import { CategoryRepository } from '../contents/repository/category.repository';
import { CategoryRepository } from '../categories/category.repository';
import { User } from '../users/entities/user.entity';
import { UserRepository } from '../users/repository/user.repository';
import * as CryptoJS from 'crypto-js';
Expand Down
180 changes: 180 additions & 0 deletions src/categories/category.controller.ts
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);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsEnum, IsString, Length } from 'class-validator';
import { Column, Entity, ManyToOne, OneToMany, RelationId } from 'typeorm';
import { Content } from './content.entity';
import { CoreEntity } from '../../common/entities/core.entity';
import { Collection } from '../../collections/entities/collection.entity';
import { User } from '../../users/entities/user.entity';
import { Content } from '../contents/entities/content.entity';
import { CoreEntity } from '../common/entities/core.entity';
import { Collection } from '../collections/entities/collection.entity';
import { User } from '../users/entities/user.entity';

export enum IconName {
None = 'None',
Expand Down
31 changes: 31 additions & 0 deletions src/categories/category.module.ts
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 {}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {
Injectable,
NotFoundException,
} from '@nestjs/common';
import { Category } from '../entities/category.entity';
import { CategoryUtil } from '../util/category.util';
import { User } from '../../users/entities/user.entity';
import { Category } from './category.entity';
import { CategoryUtil } from '../contents/util/category.util';
import { User } from '../users/entities/user.entity';

@Injectable()
export class CategoryRepository extends Repository<Category> {
Expand Down
Loading

0 comments on commit 95e5c6d

Please sign in to comment.