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

[NDD-172]: 카테고리 삭제 기능 구현 (2h / 1h) #54

Merged
merged 6 commits into from
Nov 17, 2023

Conversation

JangAJang
Copy link
Collaborator

@JangAJang JangAJang commented Nov 16, 2023

NDD-162 Powered by Pull Request Badge

Why

기획상의 추가사항 : 회원이 보고 싶지 않은 카테고리를 삭제해야 한다.
이를 적용하기 위해 카테고리를 삭제하는 기능을 만들었다.

How

카테고리 삭제시에, 카테고리 내의 질문들 또한 같이 삭제하게 추후에 구현해야 한다. (Question 구현시에 추가 예정)
삭제 시에 권한 확인을 해야한다.

Result

// 비즈니스 로직
async deleteCategoryById(member: Member, categoryId: number) {
    validateManipulatedToken(member); // 토큰 조작 확인

    const category = await this.categoryRepository.findByCategoryId(categoryId);
     // id를 통해 Category를 가져올 때, Member는 eager로 설정되어있다. 
    if (isEmpty(category)) {
      throw new CategoryNotFoundException(); // 해당 id의 카테고리가 없을 시에 에러
    }

    if (!category.isOwnedBy(member)) {
      throw new UnauthorizedException(); // 카테고리에 N:1로 매핑되어있는 회원 검증
    }

    await this.categoryRepository.remove(category);
  }

Copy link

cloudflare-workers-and-pages bot commented Nov 16, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: f58c37e
Status: ✅  Deploy successful!
Preview URL: https://dbf35827.gomterview.pages.dev
Branch Preview URL: https://feature-ndd-162.gomterview.pages.dev

View logs

@JangAJang JangAJang changed the title Feature/ndd 162 [NDD-172]: 카테고리 삭제 기능 구현 (2h / 1h) Nov 16, 2023
@JangAJang JangAJang self-assigned this Nov 17, 2023
@@ -0,0 +1,2 @@
export const objectEquals = (obj1: object, obj2: object) =>
Object.entries(obj1).toString() === Object.entries(obj2).toString();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 테스트할 때 제외하면 사용할 일이 있을까요? 테스트만을 위해 사용할꺼라면 util.ts가 아니라 test.util.ts는 어떨까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트용이 아닌, 카테고리에서 회원 객체를 가져올 때, jwt를 통해 가져온 회원과 비교하는 프로덕션 코드입니다!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 그런거였나요???! 제가 코드를 잘못봤나보네요! 알겠습니다!!

import { CreateCategoryRequest } from '../dto/createCategoryRequest';

@Entity({ name: 'Category' })
export class Category extends DefaultEntity {
@Column()
name: string;

@ManyToOne(() => Member, { nullable: true, onDelete: 'CASCADE' })
@ManyToOne(() => Member, { nullable: true, onDelete: 'CASCADE', eager: true })
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

카테고리를 불러올 때 거의 대부분의 경우에 Member도 같이 불러오나요??
eager를 여기에서 왜 사용하셨는지 이유가 궁금합니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eager를 통해서 Member를 가져옵니다. 등록되지 않았을 때 Member가 조회되지 않는 문제가 있었습니다.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 알겠습니다! 감사합니다:)

Copy link
Collaborator

@quiet-honey quiet-honey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 2주차도 고생하셨습니다 장희님!

@JangAJang JangAJang merged commit 9c33747 into dev Nov 17, 2023
1 check passed
@delete-merged-branch delete-merged-branch bot deleted the feature/NDD-162 branch November 17, 2023 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants