Skip to content

Commit

Permalink
fix: user id기반으로 조회하도록 변경 (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
yeongbinim authored Nov 22, 2023
1 parent 0f44a6c commit 757396e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
4 changes: 1 addition & 3 deletions BE/src/categories/categories.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ export class CategoriesController {
description: '잘못된 요청입니다.',
})
getCategories(@User('id') user_id: number): Promise<CategoryDto[]> {
// TODO: 유저 id를 받아올 방식 정하기
user_id;
return this.categoriesService.findByUserId(1);
return this.categoriesService.findByUserId(user_id);
}

@Post()
Expand Down
8 changes: 3 additions & 5 deletions BE/src/categories/categories.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ export class CategoriesService {
return this.entityToDto(savedCategory);
}

async findAll(): Promise<Categories[]> {
return this.categoriesRepository.find();
}

async findByUserId(user_id: number): Promise<CategoryDto[]> {
const categories = await this.categoriesRepository.find({
where: { user_id: { id: user_id } },
Expand All @@ -47,6 +43,7 @@ export class CategoriesService {
categoriesData: CategoryUpdateDto,
id: number,
): Promise<CategoryDto> {
// todo - user_id를 검증
const category = await this.categoriesRepository.findOne({
where: { id },
relations: ['user_id'],
Expand All @@ -58,6 +55,7 @@ export class CategoriesService {
}

async remove(user_id: number, id: number): Promise<void> {
// todo - user_id를 검증
const result = await this.categoriesRepository.delete(id);
if (result.affected === 0) {
throw new NotFoundException('해당 카테고리가 존재하지 않습니다.');
Expand All @@ -66,7 +64,7 @@ export class CategoriesService {

entityToDto(category: Categories): CategoryDto {
const categoryDto: CategoryDto = {
id: category.id,
category_id: category.id,
name: category.name,
color_code: category.color_code,
};
Expand Down
2 changes: 1 addition & 1 deletion BE/src/categories/dto/response/category.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class CategoryDto {
example: '1',
description: '카테고리 id',
})
id: number;
category_id: number;

@ApiProperty({
type: 'string',
Expand Down
1 change: 1 addition & 0 deletions BE/src/study-logs/study-logs.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class StudyLogs {

@ManyToOne(() => Categories, (categories) => categories.study_logs, {
eager: true,
nullable: true,
})
@JoinColumn({ name: 'category_id' })
category_id: Categories;
Expand Down

0 comments on commit 757396e

Please sign in to comment.