-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
카테고리 관련 배포
- Loading branch information
Showing
12 changed files
with
233 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,49 @@ | ||
import { | ||
Body, | ||
Controller, | ||
Delete, | ||
Get, | ||
Post, | ||
UseGuards, | ||
} from '@nestjs/common'; | ||
import { | ||
ApiBearerAuth, | ||
ApiOperation, | ||
ApiTags, | ||
} from '@nestjs/swagger'; | ||
import { JwtAuthGuard } from 'src/auth/guards/jwt.guard'; | ||
import { CategoryDto } from 'src/common/dtos/Category.dto'; | ||
import { CategoryIdDto } from 'src/common/dtos/CategoryId.dto'; | ||
import { UtilsService } from './utils.service'; | ||
|
||
@ApiTags('') | ||
@Controller('') | ||
@ApiBearerAuth('accessToken') | ||
@UseGuards(JwtAuthGuard) | ||
export class UtilsController { | ||
constructor(private readonly utilsService: UtilsService) { } | ||
|
||
@ApiOperation({ | ||
summary: '카테고리 정보', | ||
}) | ||
@Get('category') | ||
async getCategory() { | ||
return await this.utilsService.findAllCategory() | ||
} | ||
|
||
@ApiOperation({ | ||
summary: '카테고리 추가', | ||
}) | ||
@Post('category') | ||
async createCategory(@Body() categoryDto: CategoryDto): Promise<void> { | ||
return await this.utilsService.createCategory(categoryDto) | ||
} | ||
|
||
@ApiOperation({ | ||
summary: '카테고리 삭제', | ||
}) | ||
@Delete('category') | ||
async deleteCategory(@Body() categoryIdDto: CategoryIdDto) { | ||
return await this.utilsService.deleteCategory(categoryIdDto) | ||
} | ||
} |
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,17 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { MongooseModule } from '@nestjs/mongoose'; | ||
|
||
import { Category, CategorySchema } from 'src/models/category.model'; | ||
import { CategoryRepository } from 'src/repositories/category.repository'; | ||
|
||
import { UtilsController } from './utils.controller'; | ||
import { UtilsService } from './utils.service'; | ||
|
||
@Module({ | ||
imports: [ | ||
MongooseModule.forFeature([{ name: Category.name, schema: CategorySchema }]) | ||
], | ||
controllers: [UtilsController], | ||
providers: [UtilsService, CategoryRepository], | ||
}) | ||
export class UtilsModule { } |
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,23 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { CategoryDto } from 'src/common/dtos/Category.dto'; | ||
import { CategoryIdDto } from 'src/common/dtos/CategoryId.dto'; | ||
import { CategoryRepository } from 'src/repositories/category.repository'; | ||
|
||
@Injectable() | ||
export class UtilsService { | ||
constructor( | ||
private categoryRepository: CategoryRepository, | ||
) { } | ||
|
||
async createCategory(categoryDto: CategoryDto): Promise<void> { | ||
await this.categoryRepository.create(categoryDto); | ||
} | ||
|
||
async deleteCategory(categoryIdDto: CategoryIdDto): Promise<void> { | ||
await this.categoryRepository.delete(categoryIdDto) | ||
} | ||
|
||
async findAllCategory(): Promise<Array<CategoryDto>> { | ||
return await this.categoryRepository.findAll() | ||
} | ||
} |
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,37 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
import { IsNumber, IsString } from 'class-validator'; | ||
import { Expose } from 'class-transformer'; | ||
export class CategoryDto { | ||
@ApiProperty({ | ||
description: '카테고리 아이디', | ||
type: String, | ||
}) | ||
@IsString() | ||
@Expose() | ||
id: string; | ||
|
||
@ApiProperty({ | ||
description: '카테고리 이름', | ||
type: String, | ||
}) | ||
@IsString() | ||
@Expose() | ||
name: string; | ||
|
||
@ApiProperty({ | ||
description: '카테고리 이미지 경로', | ||
type: String, | ||
}) | ||
@IsString() | ||
@Expose() | ||
imageUrl: string; | ||
|
||
@ApiProperty({ | ||
description: '카테고리 우선순위(낮을수록 우선순위 높음)', | ||
type: Number, | ||
}) | ||
@IsNumber() | ||
@Expose() | ||
priority: Number; | ||
} |
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,10 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
export class CategoryIdDto { | ||
@ApiProperty({ | ||
type: String, | ||
title: '카테고리 아이디', | ||
description: '카테고리 아이디', | ||
example: 'ALL', | ||
}) | ||
id: string; | ||
} |
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
import { | ||
ClassSerializerInterceptor, | ||
ConsoleLogger, | ||
ValidationPipe, | ||
VersioningType, | ||
} from '@nestjs/common'; | ||
|
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,50 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { Prop, Schema, SchemaFactory, SchemaOptions } from '@nestjs/mongoose'; | ||
|
||
import { IsNumber, IsString } from 'class-validator'; | ||
import { Expose } from 'class-transformer'; | ||
|
||
const options: SchemaOptions = { | ||
collection: 'category', | ||
timestamps: true, | ||
}; | ||
|
||
@Schema(options) | ||
export class Category { | ||
@ApiProperty({ | ||
description: '카테고리 아이디', | ||
type: String, | ||
}) | ||
@Prop({ type: String, required: true }) | ||
@IsString() | ||
@Expose() | ||
id: string; | ||
|
||
@ApiProperty({ | ||
description: '카테고리 이름', | ||
type: String, | ||
}) | ||
@Prop({ type: String, required: true }) | ||
@IsString() | ||
@Expose() | ||
name: string; | ||
|
||
@ApiProperty({ | ||
description: '카테고리 이미지 경로', | ||
type: String, | ||
}) | ||
@Prop({ type: String, required: true }) | ||
@IsString() | ||
@Expose() | ||
imageUrl: string; | ||
|
||
@ApiProperty({ | ||
description: '카테고리 우선순위', | ||
type: Number, | ||
}) | ||
@Prop({ type: Number, required: true }) | ||
@IsNumber() | ||
@Expose() | ||
priority: Number; | ||
} | ||
export const CategorySchema = SchemaFactory.createForClass(Category); |
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,32 @@ | ||
import { InjectModel } from '@nestjs/mongoose'; | ||
import { Injectable } from '@nestjs/common'; | ||
|
||
import { Model } from 'mongoose'; | ||
|
||
import { Category } from 'src/models/category.model'; | ||
import { CategoryDto } from 'src/common/dtos/Category.dto'; | ||
import { CategoryIdDto } from 'src/common/dtos/CategoryId.dto'; | ||
|
||
@Injectable() | ||
export class CategoryRepository { | ||
constructor(@InjectModel(Category.name) private readonly categoryModel: Model<Category>) { } | ||
|
||
async create(categoryDto: CategoryDto): Promise<void> { | ||
await this.categoryModel.create(categoryDto) | ||
} | ||
|
||
async delete(categoryIdDto: CategoryIdDto): Promise<void> { | ||
await this.categoryModel.deleteOne({ categoryIdDto }) | ||
} | ||
|
||
async findAll(): Promise<Array<CategoryDto>> { | ||
return await this.categoryModel.find().sort({ priority: 1 }) | ||
.select({ | ||
_id: 0, | ||
id: 1, | ||
name: 1, | ||
imageUrl: 1, | ||
}) | ||
.lean() || {} | ||
} | ||
} |