From aa8bcc2f1c3b1f8eec30fc1e72ee2f24a5234142 Mon Sep 17 00:00:00 2001 From: Chedda98 Date: Sat, 19 Feb 2022 00:34:09 +0900 Subject: [PATCH 1/3] =?UTF-8?q?Fix:=20=ED=85=8C=EC=9D=B4=EB=B8=94=20?= =?UTF-8?q?=EC=A1=B0=EC=9D=B8=20=EB=B0=B0=EC=97=B4=20=ED=98=95=ED=83=9C,?= =?UTF-8?q?=20=EC=96=B4=ED=91=B8=20=EC=B6=94=EC=B2=9C=20=EB=A3=A8=ED=8B=B4?= =?UTF-8?q?=20boolean=EA=B0=92=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/auth/auth.entity.ts | 4 ++-- src/commonRoutine/commonRoutine.entity.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/auth/auth.entity.ts b/src/auth/auth.entity.ts index 18bae96..eb8b50d 100644 --- a/src/auth/auth.entity.ts +++ b/src/auth/auth.entity.ts @@ -62,8 +62,8 @@ export class User extends BaseEntity { @ManyToMany(() => CommonRoutine) @JoinTable() - commonRoutine: CommonRoutine; + commonRoutine: CommonRoutine[]; @ManyToMany(() => SetRoutine) @JoinTable() - setRoutine: SetRoutine; + setRoutine: SetRoutine[]; } diff --git a/src/commonRoutine/commonRoutine.entity.ts b/src/commonRoutine/commonRoutine.entity.ts index a2ca148..ec5c652 100644 --- a/src/commonRoutine/commonRoutine.entity.ts +++ b/src/commonRoutine/commonRoutine.entity.ts @@ -26,7 +26,7 @@ export class CommonRoutine extends BaseEntity { name: 'level', enumName: 'swim_level', enum: Level, - comment: '어푸가 추천하는 루틴의 난이도', + comment: '루틴의 난이도', }) level: Level; @@ -51,6 +51,13 @@ export class CommonRoutine extends BaseEntity { }) description: string; + @Column({ + type: 'boolean', + name: 'uhp_routine', + comment: '어푸 추천 루틴', + }) + uhp_routine: Boolean; + @Column({ type: 'datetime', name: 'created_at', From f1c0a7fed8e7b7246261756b3318ad2a57240bd4 Mon Sep 17 00:00:00 2001 From: Chedda98 Date: Sat, 19 Feb 2022 02:15:26 +0900 Subject: [PATCH 2/3] =?UTF-8?q?Feat:=20=EC=9C=A0=EC=A0=80=20=EB=A3=A8?= =?UTF-8?q?=ED=8B=B4=20=EC=A1=B0=ED=9A=8C=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/response/message.response.ts | 7 ++-- src/commonRoutine/commonRoutine.controller.ts | 34 +++++++++++++++---- src/commonRoutine/commonRoutine.module.ts | 8 ++++- src/commonRoutine/commonRoutine.service.ts | 19 +++++++++++ 4 files changed, 57 insertions(+), 11 deletions(-) diff --git a/src/common/response/message.response.ts b/src/common/response/message.response.ts index af00257..693505b 100644 --- a/src/common/response/message.response.ts +++ b/src/common/response/message.response.ts @@ -27,7 +27,8 @@ export default { GET_DATE_RECORDS_SUCCESS: '수영한 날짜 리스트 조회에 성공했습니다.', /*routine*/ - GET_COMMON_ROUTINE_SUCCESS: "기본 루틴 조회 성공했습니다.", - GET_COMMON_ROUTINE_DETAIL_SUCCESS: "기본 루틴 상세 페이지 조회 성공했습니다.", - GET_COMMON_ROUTINE_SET_SUCCESS: "기본 루틴의 세트 조회 성공했습니다." + GET_COMMON_ROUTINE_SUCCESS: "전체 루틴 조회 성공했습니다.", + GET_COMMON_ROUTINE_DETAIL_SUCCESS: "전체 루틴 상세 페이지 조회 성공했습니다.", + GET_COMMON_ROUTINE_SET_SUCCESS: "전체 루틴의 세트 조회 성공했습니다.", + GET_USER_ROUTINE_SUCCESS: "유저 루틴 조회 성공했습니다." }; diff --git a/src/commonRoutine/commonRoutine.controller.ts b/src/commonRoutine/commonRoutine.controller.ts index af50da8..60090a2 100644 --- a/src/commonRoutine/commonRoutine.controller.ts +++ b/src/commonRoutine/commonRoutine.controller.ts @@ -1,21 +1,25 @@ -import { Body, Controller, Get, ValidationPipe } from "@nestjs/common"; +import { Body, Controller, Get, UseGuards, ValidationPipe } from "@nestjs/common"; import { ApiOkResponse, ApiOperation, ApiTags } from "@nestjs/swagger"; import { CommonRoutineListResponseDto } from "./dto/commonRoutine.response.dto"; import { CommonRoutineService } from "./commonRoutine.service"; import { CommonRoutineListDto } from "./dto/commonRoutine.data.dto"; +import { AuthGuard } from "@nestjs/passport"; +import { GetUser } from "src/auth/get-user.decorator"; +import { User } from "src/auth/auth.entity"; @ApiTags('commonRoutine') @Controller('commonRoutine') +@UseGuards(AuthGuard()) export class CommonRoutineController { constructor(private commonRoutineService: CommonRoutineService) {} @Get('/list') @ApiOperation({ - summary: '기본 루틴 조회 API', - description: '어푸에서 추천하는 기본 루틴 조회 API', + summary: '전체 루틴 조회 API', + description: '전체 루틴 조회 API', }) @ApiOkResponse({ - description: '기본 루틴 조회 성공입니다.', + description: '전체 루틴 조회 성공입니다.', type: CommonRoutineListResponseDto, }) commonRoutineList( @@ -26,11 +30,11 @@ export class CommonRoutineController { @Get("/detail") @ApiOperation({ - summary: "기본 루틴 상세 조회 API", - description: "어푸에서 추천하는 기본 루틴의 상세 조회 API", + summary: "전체 루틴 상세 조회 API", + description: "전체 루틴의 상세 조회 API", }) @ApiOkResponse({ - description: "기본 루틴 상세 조회 성공했습니다.", + description: "전체 루틴 상세 조회 성공입니다.", type: CommonRoutineListResponseDto, }) commonRoutineDetail( @@ -38,4 +42,20 @@ export class CommonRoutineController { ): Promise { return this.commonRoutineService.getRoutineDetail(commonRoutineDetailDto) } + + @Get("/userList") + @ApiOperation({ + summary: "유저 루틴 조회 API", + description: "유저 루틴 조회 성공입니다.", + }) + @ApiOkResponse({ + description: "유저 루틴 조회 성공입니다.", + type: CommonRoutineListResponseDto, + }) + userRoutineList( + @Body(ValidationPipe) userRoutineListDto: CommonRoutineListDto, + @GetUser() user : User + ): Promise { + return this.commonRoutineService.getUserRoutine(userRoutineListDto, user); + } } diff --git a/src/commonRoutine/commonRoutine.module.ts b/src/commonRoutine/commonRoutine.module.ts index 59d96bb..f12f31e 100644 --- a/src/commonRoutine/commonRoutine.module.ts +++ b/src/commonRoutine/commonRoutine.module.ts @@ -3,10 +3,16 @@ import { TypeOrmModule } from '@nestjs/typeorm'; import { CommonRoutineController } from './commonRoutine.controller'; import { CommonRoutineService } from './commonRoutine.service'; import { CommonRoutineRepository } from './commonRoutine.repository'; +import { AuthRepository } from 'src/auth/auth.repository'; import 'dotenv/config'; +import { AuthModule } from 'src/auth/auth.module'; + @Module({ - imports: [TypeOrmModule.forFeature([CommonRoutineRepository])], + imports: [TypeOrmModule.forFeature([CommonRoutineRepository, + AuthRepository]), + AuthModule, + ], controllers: [CommonRoutineController], providers: [CommonRoutineService], }) diff --git a/src/commonRoutine/commonRoutine.service.ts b/src/commonRoutine/commonRoutine.service.ts index 4213fe5..b4ec91d 100644 --- a/src/commonRoutine/commonRoutine.service.ts +++ b/src/commonRoutine/commonRoutine.service.ts @@ -5,12 +5,16 @@ import { CommonRoutineListResponseDto } from './dto/commonRoutine.response.dto'; import { CommonRoutineListDto } from './dto/commonRoutine.data.dto'; import utilResponse from 'src/common/response/util.response'; import messageResponse from '../common/response/message.response'; +import { AuthRepository } from 'src/auth/auth.repository'; +import { User } from 'src/auth/auth.entity'; @Injectable() export class CommonRoutineService { constructor( @InjectRepository(CommonRoutineRepository) private readonly CommonRoutineRepository: CommonRoutineRepository, + @InjectRepository(AuthRepository) + private readonly AuthRepository: AuthRepository, ) {} async getAllRoutine( @@ -31,4 +35,19 @@ export class CommonRoutineService { const result = await this.CommonRoutineRepository.find(); return utilResponse.success(messageResponse.GET_COMMON_ROUTINE_DETAIL_SUCCESS, result); } + + async getUserRoutine( + userRoutineDto: CommonRoutineListDto, + user: User + ): Promise { + const userId = user.id; + const users = await this.AuthRepository.find({ relations: ['commonRoutine'], where: {id: userId} }); + // users.forEach((user) => { + // console.log(user.commonRoutine) + // }); + return utilResponse.success( + messageResponse.GET_USER_ROUTINE_SUCCESS, + users, + ); + } } From 5bc481ecca3b2f65e07041e9d02b90a5b01b4896 Mon Sep 17 00:00:00 2001 From: Chedda98 Date: Sat, 19 Feb 2022 22:59:10 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=EC=A4=91=20...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/commonRoutine/commonRoutine.controller.ts | 5 ++++- src/commonRoutine/commonRoutine.entity.ts | 9 ++++++++- src/commonRoutine/commonRoutine.service.ts | 8 ++++++-- src/commonRoutine/get-setRoutine.decorator.ts | 9 +++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 src/commonRoutine/get-setRoutine.decorator.ts diff --git a/src/commonRoutine/commonRoutine.controller.ts b/src/commonRoutine/commonRoutine.controller.ts index 60090a2..7816ff6 100644 --- a/src/commonRoutine/commonRoutine.controller.ts +++ b/src/commonRoutine/commonRoutine.controller.ts @@ -6,6 +6,8 @@ import { CommonRoutineListDto } from "./dto/commonRoutine.data.dto"; import { AuthGuard } from "@nestjs/passport"; import { GetUser } from "src/auth/get-user.decorator"; import { User } from "src/auth/auth.entity"; +import { GetRoutineSet } from "./get-setRoutine.decorator"; +import { SetRoutine } from "src/setRoutine/setRoutine.entity"; @ApiTags('commonRoutine') @Controller('commonRoutine') @@ -24,8 +26,9 @@ export class CommonRoutineController { }) commonRoutineList( @Body(ValidationPipe) commonRoutineListDto: CommonRoutineListDto, + @GetRoutineSet() setRoutine : SetRoutine ): Promise { - return this.commonRoutineService.getAllRoutine(commonRoutineListDto); + return this.commonRoutineService.getAllRoutine(commonRoutineListDto, setRoutine); } @Get("/detail") diff --git a/src/commonRoutine/commonRoutine.entity.ts b/src/commonRoutine/commonRoutine.entity.ts index ec5c652..db647f4 100644 --- a/src/commonRoutine/commonRoutine.entity.ts +++ b/src/commonRoutine/commonRoutine.entity.ts @@ -4,8 +4,11 @@ import { BeforeUpdate, Column, Entity, - PrimaryGeneratedColumn + PrimaryGeneratedColumn, + ManyToMany, + JoinTable, } from "typeorm"; +import { SetRoutine } from "../setRoutine/setRoutine.entity"; @Entity({ name: "uhpuh_routine", @@ -75,4 +78,8 @@ export class CommonRoutine extends BaseEntity { updateDates() { this.updatedAt = new Date(); } + + @ManyToMany(() => SetRoutine) + @JoinTable() + setRoutine: SetRoutine[]; } diff --git a/src/commonRoutine/commonRoutine.service.ts b/src/commonRoutine/commonRoutine.service.ts index b4ec91d..bf3ce4b 100644 --- a/src/commonRoutine/commonRoutine.service.ts +++ b/src/commonRoutine/commonRoutine.service.ts @@ -7,6 +7,7 @@ import utilResponse from 'src/common/response/util.response'; import messageResponse from '../common/response/message.response'; import { AuthRepository } from 'src/auth/auth.repository'; import { User } from 'src/auth/auth.entity'; +import { SetRoutine } from 'src/setRoutine/setRoutine.entity'; @Injectable() export class CommonRoutineService { @@ -19,9 +20,11 @@ export class CommonRoutineService { async getAllRoutine( commonRoutineListDto: CommonRoutineListDto, + setRoutine: SetRoutine ): Promise { + const setRoutineId = setRoutine.id; const result = await this.CommonRoutineRepository.find({ - select: ['id', 'title', 'level', 'distanceSum', 'timeSum', 'description'], + select: ['id', 'title', 'level', 'distanceSum', 'timeSum', 'description'], where: {setRoutineId: setRoutineId} }); return utilResponse.success( messageResponse.GET_COMMON_ROUTINE_SUCCESS, @@ -41,7 +44,8 @@ export class CommonRoutineService { user: User ): Promise { const userId = user.id; - const users = await this.AuthRepository.find({ relations: ['commonRoutine'], where: {id: userId} }); + const users = await this.AuthRepository.find({ relations: ['commonRoutine'], where: {id: userId} + }); // users.forEach((user) => { // console.log(user.commonRoutine) // }); diff --git a/src/commonRoutine/get-setRoutine.decorator.ts b/src/commonRoutine/get-setRoutine.decorator.ts new file mode 100644 index 0000000..71cb5cd --- /dev/null +++ b/src/commonRoutine/get-setRoutine.decorator.ts @@ -0,0 +1,9 @@ +import { createParamDecorator, ExecutionContext } from "@nestjs/common"; +import { SetRoutine } from "src/setRoutine/setRoutine.entity"; + +export const GetRoutineSet = createParamDecorator( + (data, ctx: ExecutionContext): SetRoutine => { + const req = ctx.switchToHttp().getRequest(); + return req.setRoutine; + }, +);