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/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..7816ff6 100644 --- a/src/commonRoutine/commonRoutine.controller.ts +++ b/src/commonRoutine/commonRoutine.controller.ts @@ -1,36 +1,43 @@ -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"; +import { GetRoutineSet } from "./get-setRoutine.decorator"; +import { SetRoutine } from "src/setRoutine/setRoutine.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( @Body(ValidationPipe) commonRoutineListDto: CommonRoutineListDto, + @GetRoutineSet() setRoutine : SetRoutine ): Promise { - return this.commonRoutineService.getAllRoutine(commonRoutineListDto); + return this.commonRoutineService.getAllRoutine(commonRoutineListDto, setRoutine); } @Get("/detail") @ApiOperation({ - summary: "기본 루틴 상세 조회 API", - description: "어푸에서 추천하는 기본 루틴의 상세 조회 API", + summary: "전체 루틴 상세 조회 API", + description: "전체 루틴의 상세 조회 API", }) @ApiOkResponse({ - description: "기본 루틴 상세 조회 성공했습니다.", + description: "전체 루틴 상세 조회 성공입니다.", type: CommonRoutineListResponseDto, }) commonRoutineDetail( @@ -38,4 +45,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.entity.ts b/src/commonRoutine/commonRoutine.entity.ts index a2ca148..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", @@ -26,7 +29,7 @@ export class CommonRoutine extends BaseEntity { name: 'level', enumName: 'swim_level', enum: Level, - comment: '어푸가 추천하는 루틴의 난이도', + comment: '루틴의 난이도', }) level: Level; @@ -51,6 +54,13 @@ export class CommonRoutine extends BaseEntity { }) description: string; + @Column({ + type: 'boolean', + name: 'uhp_routine', + comment: '어푸 추천 루틴', + }) + uhp_routine: Boolean; + @Column({ type: 'datetime', name: 'created_at', @@ -68,4 +78,8 @@ export class CommonRoutine extends BaseEntity { updateDates() { this.updatedAt = new Date(); } + + @ManyToMany(() => SetRoutine) + @JoinTable() + setRoutine: SetRoutine[]; } 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..bf3ce4b 100644 --- a/src/commonRoutine/commonRoutine.service.ts +++ b/src/commonRoutine/commonRoutine.service.ts @@ -5,19 +5,26 @@ 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'; +import { SetRoutine } from 'src/setRoutine/setRoutine.entity'; @Injectable() export class CommonRoutineService { constructor( @InjectRepository(CommonRoutineRepository) private readonly CommonRoutineRepository: CommonRoutineRepository, + @InjectRepository(AuthRepository) + private readonly AuthRepository: AuthRepository, ) {} 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, @@ -31,4 +38,20 @@ 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, + ); + } } 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; + }, +);