Skip to content

Commit

Permalink
Merge pull request #42 from depromeet/dev
Browse files Browse the repository at this point in the history
직렬화 과정 리팩토링
  • Loading branch information
ImNM authored May 6, 2022
2 parents e5beb4e + c191722 commit a5fbae4
Show file tree
Hide file tree
Showing 25 changed files with 372 additions and 375 deletions.
Binary file removed public/.DS_Store
Binary file not shown.
7 changes: 0 additions & 7 deletions public/css/styles.css

This file was deleted.

64 changes: 0 additions & 64 deletions public/js/scripts.js

This file was deleted.

7 changes: 3 additions & 4 deletions src/apis/letter/letter.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ import { SuccessInterceptor } from 'src/common/interceptors/sucess.interceptor';
@Controller('letters')
@ApiBearerAuth('accessToken')
@UseGuards(JwtAuthGuard)
@UseInterceptors(SuccessInterceptor)
export class LetterController {
constructor(private readonly letterService: LetterService) {}
@UseInterceptors(ClassSerializerInterceptor)

@ApiOperation({ summary: '편지를 상대방에게 보낼 수 있음' })
@ApiResponse({
status: 201,
Expand All @@ -65,6 +64,7 @@ export class LetterController {
);
}

// 시리얼라이징 적용 필요
@ApiOperation({ summary: '상대방과 편지를 한걸 모아볼수있음' })
@ApiResponse({
status: 200,
Expand All @@ -82,7 +82,6 @@ export class LetterController {
);
}

@UseInterceptors(ClassSerializerInterceptor)
@ApiOperation({ summary: '쪽지탭용' })
@ApiResponse({
status: 200,
Expand All @@ -97,7 +96,7 @@ export class LetterController {
console.log(instanceToPlain(list[0]));
return list;
}
@UseInterceptors(ClassSerializerInterceptor)

@ApiOperation({ summary: '쪽지룸을 떠남' })
@ApiResponse({
status: 200,
Expand Down
51 changes: 51 additions & 0 deletions src/apis/questions/dto/QuestionList.res.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { ApiProperty, PickType } from '@nestjs/swagger';
import { Comment, Question } from 'src/models/question.model';
import { Types } from 'mongoose';
import { Exclude, Expose } from 'class-transformer';
export class QuestionListShowDto extends PickType(Question, [
'_id',
'user',
'content',
'commentList',
'likes',
'createdAt',
'myUserId',
] as const) {
@Expose({ toClassOnly: true })
@Exclude({ toPlainOnly: true })
commentList: Comment[];

@ApiProperty({
description: '좋아요 갯수',
type: Number,
})
@Expose()
get likesCount(): number {
return this.likes.length;
}

@ApiProperty({
description: '댓글갯수',
type: Number,
})
@Expose()
get commentsCount(): number {
return this.commentList.length;
}

@ApiProperty({
description: '내가 좋아요 눌렀는지',
type: Boolean,
})
@Expose({ name: 'ilike' })
get ilike(): boolean {
if (
this.likes.find((user) => {
return user._id.equals(this.myUserId);
})
)
return true;

return false;
}
}
8 changes: 4 additions & 4 deletions src/apis/questions/questions.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ import { User } from 'src/models/user.model';
import { CommentStringDto } from './dto/CommentString.dto';
import { IlikeResDto } from './dto/Ilike.res.dto';
import { QuestionShowDto } from './dto/Question.res.dto';
import { QuestionListShowDto } from './dto/QuestionList.res.dto';
import { QuestionFindRequestDto } from './dto/QuestionsList.req.dto';
import { QuestionsService } from './questions.service';

@ApiTags('questions')
@Controller('questions')
@ApiBearerAuth('accessToken')
@UseInterceptors(ClassSerializerInterceptor)
@UseInterceptors(SuccessInterceptor)
@UseGuards(JwtAuthGuard)
export class QuestionsController {
constructor(private readonly questionService: QuestionsService) {}
Expand All @@ -48,8 +47,9 @@ export class QuestionsController {
})
@ApiResponse({
status: 200,
description: '요청 성공시',
type: [QuestionShowDto],
description:
'요청 성공시 , 코멘트 갯수만 반환합니다 밑에 QuestionShow는 디테일 인포 용입니당!',
type: [QuestionListShowDto],
})
@Get()
findQuestions(
Expand Down
5 changes: 3 additions & 2 deletions src/apis/questions/questions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { UserRepository } from 'src/repositories/user.repository';
import { CommentStringDto } from './dto/CommentString.dto';
import { IlikeResDto } from './dto/Ilike.res.dto';
import { QuestionShowDto } from './dto/Question.res.dto';
import { QuestionListShowDto } from './dto/QuestionList.res.dto';
import { QuestionFindRequestDto } from './dto/QuestionsList.req.dto';

@Injectable()
Expand All @@ -30,11 +31,11 @@ export class QuestionsService {
return new RoomIdDto(user.myRoom._id);
}

@returnValueToDto(QuestionShowDto)
@returnValueToDto(QuestionListShowDto)
async findQuestions(
userIdDto: UserIdDto,
questionFindRequestDto: QuestionFindRequestDto,
): Promise<QuestionShowDto[]> {
): Promise<QuestionListShowDto[]> {
// 내 아이디 정보를 넣어서 비교로직 추가가 필요함.
const myRoomIdDto = await this.checkMyRoom(userIdDto);
let result = [];
Expand Down
74 changes: 32 additions & 42 deletions src/apis/rooms/dto/find-room.res.dto copy.ts
Original file line number Diff line number Diff line change
@@ -1,50 +1,40 @@
import { ApiProperty } from '@nestjs/swagger';
import { Types } from 'mongoose';
import { CATEGORY_TYPE } from 'src/common/consts/enum';
import { ApiProperty, PickType } from '@nestjs/swagger';
import { Exclude, Expose } from 'class-transformer';
import { UserProfileDto } from 'src/common/dtos/UserProfile.dto';
import { Room } from 'src/models/room.model';

export class ResFindRoomDto {
constructor(room: Room, iFavorite: boolean, iJoin: boolean) {
this._id = room._id;
this.category = room.category;
this.name = room.name;
this.radius = room.radius;
this.lat = room.geometry.coordinates[0];
this.lng = room.geometry.coordinates[1];
this.userCount = room.userCount;
this.distance = room.distance;
this.iFavorite = iFavorite;
this.iJoin = iJoin;
}
@ApiProperty()
_id: string;

@ApiProperty({ description: '채팅방 이름' })
name: string;

@ApiProperty({ description: '반경정보' })
radius: number;

@ApiProperty({ enum: CATEGORY_TYPE, description: '카테고리정보' })
category: CATEGORY_TYPE;

@ApiProperty()
lat: number;

@ApiProperty()
lng: number;

@ApiProperty({ description: '채팅방내 유저숫자' })
userCount: number;

@ApiProperty({ description: '거리정보' })
distance: number;

@ApiProperty({ description: '내가 즐겨찾기 했는지' })
export class ResFindRoomDto extends PickType(Room, [
'_id',
'name',
'category',
'radius',
'userList',
'geometry',
'userCount',
] as const) {
@Expose({ toClassOnly: true })
@Exclude({ toPlainOnly: true })
userList: UserProfileDto[];

@ApiProperty({ description: '내가 즐겨찾기 했는지', type: Boolean })
@Expose()
iFavorite: boolean;

@ApiProperty({ description: '내가 들어가 있는지' })
@ApiProperty({ description: '내가 들어가 있는지', type: Boolean })
@Expose()
iJoin: boolean;

@ApiProperty({ description: '위도 가로선', type: Number })
@Expose()
get lat(): number {
return this.geometry.coordinates[0];
}

@ApiProperty({ description: '경도 세로선', type: Number })
@Expose()
get lng(): number {
return this.geometry.coordinates[1];
}
}
// console.log(plainToClass(User, fromPlainUser, { excludeExtraneousValues: true }));
// '_id',
Expand Down
Loading

0 comments on commit a5fbae4

Please sign in to comment.