Skip to content

Commit

Permalink
Merge pull request #65 from Fam-Story/fix/64-post-date
Browse files Browse the repository at this point in the history
Fix: 게시글 날짜 세부적으로 분할
  • Loading branch information
synoti21 authored Nov 30, 2023
2 parents afdf91b + a04700e commit 9a954ba
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 13 deletions.
26 changes: 23 additions & 3 deletions src/domain/post/dto/request/create-post.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,28 @@ export class CreatePostDto {
@IsString()
readonly context: string;

@ApiProperty({ example: '2021-10-10', description: '포스트가 작성된 날짜' })
@ApiProperty({ example: 2021, description: '포스트가 작성된 날짜의 연도' })
@IsNotEmpty()
@IsString()
readonly createdDate: Date;
@IsNumber()
readonly createdYear: number;

@ApiProperty({ example: 10, description: '포스트가 작성된 날짜의 월' })
@IsNotEmpty()
@IsNumber()
readonly createdMonth: number;

@ApiProperty({ example: 1, description: '포스트가 작성된 날짜의 일' })
@IsNotEmpty()
@IsNumber()
readonly createdDay: number;

@ApiProperty({ example: 20, description: '포스트가 작성된 날짜의 시' })
@IsNotEmpty()
@IsNumber()
readonly createdHour: number;

@ApiProperty({ example: 5, description: '포스트가 작성된 날짜의 분' })
@IsNotEmpty()
@IsNumber()
readonly createdMinute: number;
}
46 changes: 39 additions & 7 deletions src/domain/post/dto/response/response-post.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,20 @@ export class ResponsePostDto {
@ApiProperty({ example: '푸앙이가 먹는 모습', description: '포스트의 내용' })
readonly context: string;

@ApiProperty({ example: '2021-10-10', description: '포스트가 작성된 날짜' })
readonly createdDate: Date;
@ApiProperty({ example: 2021, description: '포스트가 작성된 날짜의 연도' })
readonly createdYear: number;

@ApiProperty({ example: 10, description: '포스트가 작성된 날짜의 월' })
readonly createdMonth: number;

@ApiProperty({ example: 1, description: '포스트가 작성된 날짜의 일' })
readonly createdDay: number;

@ApiProperty({ example: 20, description: '포스트가 작성된 날짜의 시' })
readonly createdHour: number;

@ApiProperty({ example: 5, description: '포스트가 작성된 날짜의 분' })
readonly createdMinute: number;

@ApiProperty({
example: 1,
Expand All @@ -31,14 +43,22 @@ export class ResponsePostDto {
familyMemberId: number,
title: string,
context: string,
createdDate: Date,
createdYear: number,
createdMonth: number,
createdDay: number,
createdHour: number,
createdMinute: number,
familyId: number,
) {
this.postId = postId;
this.familyMemberId = familyMemberId;
this.title = title;
this.context = context;
this.createdDate = createdDate;
this.createdYear = createdYear;
this.createdMonth = createdMonth;
this.createdDay = createdDay;
this.createdHour = createdHour;
this.createdMinute = createdMinute;
this.familyId = familyId;
}

Expand All @@ -47,15 +67,23 @@ export class ResponsePostDto {
familyMemberId: number,
title: string,
context: string,
createdDate: Date,
createdYear: number,
createdMonth: number,
createdDay: number,
createdHour: number,
createdMinute: number,
familyId: number,
): ResponsePostDto {
return new ResponsePostDto(
postId,
familyMemberId,
title,
context,
createdDate,
createdYear,
createdMonth,
createdDay,
createdHour,
createdMinute,
familyId,
);
}
Expand All @@ -66,7 +94,11 @@ export class ResponsePostDto {
post.srcMember.id,
post.title,
post.context,
post.createdDate,
post.createdDate.getFullYear(),
post.createdDate.getMonth(),
post.createdDate.getDate(),
post.createdDate.getHours(),
post.createdDate.getMinutes(),
post.family.id,
);
}
Expand Down
10 changes: 9 additions & 1 deletion src/domain/post/post.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,18 @@ export class PostService {
);
const family = await this.validateFamily(createPostDto.familyId);

const createDate = new Date(
createPostDto.createdYear,
createPostDto.createdMonth,
createPostDto.createdDay,
);
createDate.setHours(createPostDto.createdHour);
createDate.setMinutes(createPostDto.createdMinute);

const post: Post = Post.createPost(
createPostDto.title,
createPostDto.context,
createPostDto.createdDate,
createDate,
familyMember,
family,
);
Expand Down
13 changes: 11 additions & 2 deletions src/test/service/post.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ describe('PostService', () => {
srcMemberId: 1,
title: 'test',
context: 'test',
createdDate: new Date(),
createdYear: 2021,
createdMonth: 10,
createdDay: 1,
createdHour: 20,
createdMinute: 5,
};

jest
Expand Down Expand Up @@ -93,7 +97,12 @@ describe('PostService', () => {
postId: 1,
title: 'test',
context: 'test',
createdDate: new Date(),
srcMemberId: 1,
createdYear: 2021,
createdMonth: 10,
createdDay: 1,
createdHour: 20,
createdMinute: 5,
};

jest.spyOn(postRepository, 'findOne').mockResolvedValue(post);
Expand Down

0 comments on commit 9a954ba

Please sign in to comment.