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

Develop chedda #44

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/auth/auth.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export class User extends BaseEntity {

@ManyToMany(() => CommonRoutine)
@JoinTable()
commonRoutine: CommonRoutine;
commonRoutine: CommonRoutine[];
@ManyToMany(() => SetRoutine)
@JoinTable()
setRoutine: SetRoutine;
setRoutine: SetRoutine[];
}
7 changes: 4 additions & 3 deletions src/common/response/message.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: "유저 루틴 조회 성공했습니다."
};
39 changes: 31 additions & 8 deletions src/commonRoutine/commonRoutine.controller.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,64 @@
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<CommonRoutineListResponseDto> {
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(
@Body(ValidationPipe) commonRoutineDetailDto: CommonRoutineListDto
): Promise<CommonRoutineListResponseDto> {
return this.commonRoutineService.getRoutineDetail(commonRoutineDetailDto)
}

@Get("/userList")
@ApiOperation({
summary: "유저 루틴 조회 API",
description: "유저 루틴 조회 성공입니다.",
})
@ApiOkResponse({
description: "유저 루틴 조회 성공입니다.",
type: CommonRoutineListResponseDto,
})
userRoutineList(
@Body(ValidationPipe) userRoutineListDto: CommonRoutineListDto,
@GetUser() user : User
): Promise<CommonRoutineListResponseDto> {
return this.commonRoutineService.getUserRoutine(userRoutineListDto, user);
}
}
18 changes: 16 additions & 2 deletions src/commonRoutine/commonRoutine.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import {
BeforeUpdate,
Column,
Entity,
PrimaryGeneratedColumn
PrimaryGeneratedColumn,
ManyToMany,
JoinTable,
} from "typeorm";
import { SetRoutine } from "../setRoutine/setRoutine.entity";

@Entity({
name: "uhpuh_routine",
Expand All @@ -26,7 +29,7 @@ export class CommonRoutine extends BaseEntity {
name: 'level',
enumName: 'swim_level',
enum: Level,
comment: '어푸가 추천하는 루틴의 난이도',
comment: '루틴의 난이도',
})
level: Level;

Expand All @@ -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',
Expand All @@ -68,4 +78,8 @@ export class CommonRoutine extends BaseEntity {
updateDates() {
this.updatedAt = new Date();
}

@ManyToMany(() => SetRoutine)
@JoinTable()
setRoutine: SetRoutine[];
}
8 changes: 7 additions & 1 deletion src/commonRoutine/commonRoutine.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
})
Expand Down
25 changes: 24 additions & 1 deletion src/commonRoutine/commonRoutine.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommonRoutineListResponseDto> {
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,
Expand All @@ -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<CommonRoutineListResponseDto> {
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,
);
}
}
9 changes: 9 additions & 0 deletions src/commonRoutine/get-setRoutine.decorator.ts
Original file line number Diff line number Diff line change
@@ -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;
},
);