Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/room #6

Merged
merged 6 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/apis/rooms/dto/create-room.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PickType } from '@nestjs/swagger';
import { ApiProperty, PickType } from '@nestjs/swagger';
import { IsNumber } from 'class-validator';
import { Room } from 'src/models/room.model';

Expand All @@ -7,8 +7,18 @@ export class CreateRoomDto extends PickType(Room, [
'category',
'radius',
] as const) {
@ApiProperty({
type: Number,
title: '경도',
example: '127',
})
@IsNumber()
lng: number;
@ApiProperty({
type: Number,
title: '위도',
example: '37',
})
@IsNumber()
lat: number;
}
10 changes: 9 additions & 1 deletion src/apis/rooms/dto/find-room.dto.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { IsNumber } from 'class-validator';
import { ApiProperty } from '@nestjs/swagger';
import { IsNumber, Max, Min } from 'class-validator';

export class FindRoomDto {
@ApiProperty({ example: '127', description: '경도입니다 세로선!' })
@IsNumber()
@Min(120)
@Max(135)
lng: number;

@ApiProperty({ example: '37', description: '위도입니다 가로선' })
@IsNumber()
@Min(30)
@Max(45)
lat: number;
}
83 changes: 83 additions & 0 deletions src/apis/rooms/dto/find-room.res.dto copy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { ApiProperty } from '@nestjs/swagger';
import { Types } from 'mongoose';
import { CATEGORY_TYPE } from 'src/common/consts/enum';
import { Room } from 'src/models/room.model';

export class ResFindRoomDto {
constructor(room: Room) {
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.userList.length;
this.distance = room.distance;
}
@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;
}

// '_id',
// 'name',
// 'radius',
// 'category',

// export class UserShowDto {
// // (1)
// @Exclude() private readonly _id: number;
// @Exclude() private readonly _firstName: string;
// @Exclude() private readonly _lastName: string;
// @Exclude() private readonly _orderDateTime: LocalDateTime;

// constructor(user: User) {
// this._id = user.id;
// this._firstName = user.firstName;
// this._lastName = user.lastName;
// this._orderDateTime = user.orderDateTime.plusDays(1); // (2)
// }

// @ApiProperty()
// @Expose() // (3)
// get id(): number {
// return this._id;
// }

// @ApiProperty()
// @Expose()
// get firstName(): string {
// return this._firstName;
// }

// @ApiProperty()
// @Expose()
// get lastName(): string {
// return this._lastName;
// }

// @ApiProperty()
// @Expose()
// get orderDateTime(): string {
// return DateTimeUtil.toString(this._orderDateTime); // (4)
// }
// }
94 changes: 94 additions & 0 deletions src/apis/rooms/dto/findOne-room.res.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { ApiProperty, PickType } from '@nestjs/swagger';
import { Expose } from 'class-transformer';
import { Types } from 'mongoose';
import { CATEGORY_TYPE } from 'src/common/consts/enum';

import { UserProfileDto } from 'src/common/dtos/UserProfile.dto';
import { Room } from 'src/models/room.model';

export class ResFindOneRoomDto {
constructor(room: Room, isUserFavoriteRoom?: 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];
if (isUserFavoriteRoom) {
this.userList = room.userList as UserProfileDto[];
this.isUserFavoriteRoom = isUserFavoriteRoom;
}
this.userCount = room.userList.length;
}
@ApiProperty()
_id: string;

@ApiProperty()
name: string;

@ApiProperty()
radius: number;

@ApiProperty({ enum: CATEGORY_TYPE })
category: CATEGORY_TYPE;

@ApiProperty()
lat: number;

@ApiProperty()
lng: number;

@ApiProperty({ type: [UserProfileDto], required: false })
@Expose()
userList?: UserProfileDto[];

@ApiProperty()
userCount: number;

@ApiProperty()
isUserFavoriteRoom?: boolean;
}

// '_id',
// 'name',
// 'radius',
// 'category',

// export class UserShowDto {
// // (1)
// @Exclude() private readonly _id: number;
// @Exclude() private readonly _firstName: string;
// @Exclude() private readonly _lastName: string;
// @Exclude() private readonly _orderDateTime: LocalDateTime;

// constructor(user: User) {
// this._id = user.id;
// this._firstName = user.firstName;
// this._lastName = user.lastName;
// this._orderDateTime = user.orderDateTime.plusDays(1); // (2)
// }

// @ApiProperty()
// @Expose() // (3)
// get id(): number {
// return this._id;
// }

// @ApiProperty()
// @Expose()
// get firstName(): string {
// return this._firstName;
// }

// @ApiProperty()
// @Expose()
// get lastName(): string {
// return this._lastName;
// }

// @ApiProperty()
// @Expose()
// get orderDateTime(): string {
// return DateTimeUtil.toString(this._orderDateTime); // (4)
// }
// }
81 changes: 70 additions & 11 deletions src/apis/rooms/rooms.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,97 @@ import {
Param,
Delete,
Query,
UsePipes,
SerializeOptions,
} from '@nestjs/common';
import { RoomsService } from './rooms.service';
import { CreateRoomDto } from './dto/create-room.dto';
import { UpdateRoomDto } from './dto/update-room.dto';
import {
ApiBody,
ApiOperation,
ApiParam,
ApiQuery,
ApiResponse,
ApiTags,
} from '@nestjs/swagger';
import { FindRoomDto } from './dto/find-room.dto';
import { MongoId } from 'src/common/dtos/MongoId.dto';
import { ObjectIdValidationPipe } from 'src/common/pipes/ObjectIdCheck.pipe';
import { ObjectId } from 'mongoose';
import { UserIdDto } from 'src/common/dtos/UserId.dto';
import { RoomIdDto } from 'src/common/dtos/RoomId.dto';
import { ResFindOneRoomDto } from './dto/findOne-room.res.dto';
import { ResFindRoomDto } from './dto/find-room.res.dto copy';

@ApiTags('rooms')
@Controller('rooms')
// TODO : 나중에 가드오면 가드달아야함 이찬진 4월 14일
export class RoomsController {
constructor(private readonly roomsService: RoomsService) {}

@ApiOperation({ summary: '룸을 생성할수 있음' })
@ApiBody({ type: CreateRoomDto })
@Post()
create(@Body() createRoomDto: CreateRoomDto) {
return this.roomsService.createRoom(createRoomDto);
}

@ApiOperation({ summary: '위치정보를 토대로 내 주변 채팅방 정보를 가져옴' })
@ApiResponse({
status: 200,
description: '요청 성공시',
type: ResFindRoomDto,
})
@Get()
findAll(@Query('lng') lng: number, @Query('lat') lat: number) {
@UsePipes()
findAll(@Query() FindRoomDto: FindRoomDto) {
// console.log(FindRoomDto);
// 경도lng 위도lat
return this.roomsService.findRoom({ lng, lat });
return this.roomsService.findRoom(FindRoomDto);
}

@ApiOperation({ summary: '룸의 세부정보를 볼수있음, 유저 목록과 함께' })
@ApiResponse({
status: 200,
description: '요청 성공시',
type: ResFindOneRoomDto,
})
@Get(':roomId')
findOne(@Param() roomId: RoomIdDto) {
//, @Body() userId: UserIdDto
console.log(roomId);
return this.roomsService.findOneRoomById(
roomId,
new UserIdDto('624c24cae25c551b68a6645c'),
);
}

@Get(':id')
findOne(@Param('id') id: string) {
return this.roomsService.findOne(+id);
// TODO : user id field 가드 통해서 받아와야함 지금은 바디로
@ApiOperation({ summary: '유저를 룸에 집어넣는다' })
@ApiBody({ type: UserIdDto })
@Post(':roomId/join')
joinRoom(@Param() roomId: RoomIdDto, @Body() userId: UserIdDto) {
return this.roomsService.addUserToRoom(roomId, userId);
}

@Patch(':id')
update(@Param('id') id: string, @Body() updateRoomDto: UpdateRoomDto) {
return this.roomsService.update(+id, updateRoomDto);
@ApiOperation({ summary: '유저가 룸을 즐겨찾기한다' })
@ApiBody({ type: UserIdDto })
@Post(':roomId/star')
pushRoomToUserFavoriteList(
@Param() roomId: RoomIdDto,
@Body() userId: UserIdDto,
) {
return this.roomsService.pushRoomToUserFavoriteList(roomId, userId);
}

@Delete(':id')
remove(@Param('id') id: string) {
return this.roomsService.remove(+id);
@ApiOperation({ summary: '유저가 룸을 즐겨찾기에서 뺀다' })
@ApiBody({ type: UserIdDto })
@Delete(':roomId/star')
pullRoomToUserFavoriteList(
@Param() roomId: RoomIdDto,
@Body() userId: UserIdDto,
) {
return this.roomsService.pullRoomToUserFavoriteList(roomId, userId);
}
}
9 changes: 7 additions & 2 deletions src/apis/rooms/rooms.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ import { RoomsController } from './rooms.controller';
import { MongooseModule } from '@nestjs/mongoose';
import { Room, RoomSchema } from 'src/models/room.model';
import { RoomRepository } from 'src/repositories/room.repository';
import { UserRepository } from 'src/repositories/user.repository';
import { User, UserSchema } from 'src/models/user.model';
@Module({
imports: [
MongooseModule.forFeature([{ name: Room.name, schema: RoomSchema }]),
MongooseModule.forFeature([
{ name: Room.name, schema: RoomSchema },
{ name: User.name, schema: UserSchema },
]),
],
controllers: [RoomsController],
providers: [RoomsService, RoomRepository],
providers: [RoomsService, RoomRepository, UserRepository],
})
export class RoomsModule {}
Loading