Skip to content

Commit

Permalink
feat: post 관련 스키마, DTO 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
zerosial committed Jan 4, 2024
1 parent aae6b28 commit 76b66de
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/posts/dto/createPost.input.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { IsNotEmpty } from 'class-validator';
import { InputType, Field } from '@nestjs/graphql';
import { ApiProperty } from '@nestjs/swagger';

@InputType()
export class CreatePostInput {
@Field()
@Field() // GraphQL 데코레이터
@ApiProperty({ description: 'The content of the post' }) // Swagger 데코레이터
@IsNotEmpty()
content: string;

@Field()
@Field() // GraphQL 데코레이터
@ApiProperty({ description: 'The title of the post' }) // Swagger 데코레이터
@IsNotEmpty()
title: string;
}
7 changes: 6 additions & 1 deletion src/posts/dto/post-order.input.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Field, InputType, registerEnumType } from '@nestjs/graphql';
import { ApiProperty } from '@nestjs/swagger';
import { Order } from '../../common/order/order';

export enum PostOrderField {
Expand All @@ -16,7 +17,11 @@ registerEnumType(PostOrderField, {
});

@InputType()
export class PostOrder extends Order {
export class PostOrder extends Order {
@Field(() => PostOrderField)
@ApiProperty({
enum: PostOrderField,
description: 'Field by which to order posts',
})
field: PostOrderField;
}
9 changes: 9 additions & 0 deletions src/posts/models/post.model.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
import { Field, ObjectType } from '@nestjs/graphql';
import { ApiProperty } from '@nestjs/swagger';
import { User } from '../../users/models/user.model';
import { BaseModel } from '../../common/models/base.model';

@ObjectType()
export class Post extends BaseModel {
@Field()
@ApiProperty({ description: 'The title of the post' })
title: string;

@Field(() => String, { nullable: true })
@ApiProperty({ description: 'The content of the post', nullable: true })
content?: string | null;

@Field(() => Boolean)
@ApiProperty({ description: 'Whether the post is published or not' })
published: boolean;

@Field(() => User, { nullable: true })
@ApiProperty({
description: 'The author of the post',
nullable: true,
type: () => User,
})
author?: User | null;
}
2 changes: 2 additions & 0 deletions src/posts/posts.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { PostsController } from './posts.controller';
import { Module } from '@nestjs/common';
import { PostsResolver } from './posts.resolver';

@Module({
imports: [],
controllers: [PostsController],
providers: [PostsResolver],
})
export class PostsModule {}

0 comments on commit 76b66de

Please sign in to comment.