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

지도/코스의 장소 수정 API , 지도 썸네일 수정 API #184

Merged
merged 8 commits into from
Nov 25, 2024

Conversation

Miensoap
Copy link
Collaborator

@Miensoap Miensoap commented Nov 25, 2024

📄 Summary

지도/코스의 장소 수정 API , 지도 썸네일 수정 API

🙋🏻 More

지도/코스에 추가된 장소와 실제 장소 네이밍이 햇갈릴 수 있을 거 같아요.
orElseThrow 메서드 구현해 사용, 커스텀 예외 사용 리팩터링

🕰️ Actual Time of Completion

2H

close #177

@Miensoap Miensoap added BE 백엔드 관련 이슈입니다 🌱 기능추가 새로운 기능 요청입니다 ⚙️ 리팩터링 코드 퀄리티를 높입니다 labels Nov 25, 2024
@Miensoap Miensoap added this to the week5 milestone Nov 25, 2024
@Miensoap Miensoap self-assigned this Nov 25, 2024
) {
const { comment } = updatePlaceInCourseRequest;
if (updatePlaceInCourseRequest.isEmpty()) {
throw new BadRequestException('수정할 정보가 없습니다.');
Copy link
Collaborator

Choose a reason for hiding this comment

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

q: nest 제공 에러를 쓰면 에러 코드는 어떻게 들어가나요?

Copy link
Collaborator Author

@Miensoap Miensoap Nov 25, 2024

Choose a reason for hiding this comment

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

필터에서 999 로 들어갑니다!

여러 도메인에서 사용되는 에러인데, common exception 으로 만드는게 나을까요?

Copy link
Collaborator

Choose a reason for hiding this comment

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

그것도 괜찮을 것 같네요!

@Transactional()
async setPlacesOfCourse(
id: number,
setPlacesOfCourseRequest: SetPlacesOfCourseRequest,
) {
const course = await this.courseRepository.findById(id);
if (!course) throw new CourseNotFoundException(id);
const course = await this.getCourseOrElseThrowNotFound(id);
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Comment on lines +12 to 17
@IsOptional()
@IsUrl()
thumbnailUrl?: string;
Copy link
Collaborator

Choose a reason for hiding this comment

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

p2: IsOptional 은 클라에서 아예 필드를 주지 않을 때 동작합니다.
클라에서 만약 thumnailUrl: "" 로 보내면 에러 납니다.

저는 그래서 아래와 같이 해결했었어요. 클라이언트에서도 없으면 빈값으로 보내기로 예전에 이야기 했었습니다!

  // CreateCourseRequest 참고
  @ValidateIf((object, value) => value !== '')
  @IsUrl()
  thumbnailUrl?: string;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

아래와 같이 수정하겠습니다.

  1. thumbnailUrl 필드가 존재하지 않으면 업데이트에 반영하지 않는다.
  2. thumbnailUrl 필드가 존재하나 빈 문자열인 경우 기본 url 로 변경한다.
  3. thumbnailUrl 필드가 존재하며 유효한 url 인 경우 해당 url 로 변경한다.

backend/src/course/entity/course.entity.ts Show resolved Hide resolved
Comment on lines 87 to 90
if (updateMapInfoRequest.isEmpty()) {
throw new BadRequestException('수정할 정보가 없습니다.');
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

q: Request 검증은 controller의 역할이라 생각해서 service에 넣지 않고 여기 넣으신건가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

넵 맞습니다

if (!(await this.placeRepository.existById(placeId))) {
throw new InvalidPlaceToMapException(placeId);
}
@Transactional()
Copy link
Collaborator

Choose a reason for hiding this comment

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

q: 트랜잭션이 필요할까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

스크린샷 2024-11-25 140706

새 객체로 교체하고 aggregate root를 저장하는 방식이라, insert, delete 쿼리가 별개로 나가더라구요

Comment on lines 137 to 143
async deletePlace(id: number, placeId: number) {
const map = await this.mapRepository.findById(id);
if (!map) throw new MapNotFoundException(id);
const map = await this.getMapOrElseThrowNotFound(id);

map.deletePlace(placeId);
await this.mapRepository.save(map);

return { deletedId: placeId };
Copy link
Collaborator

Choose a reason for hiding this comment

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

p1: 만약 위에서 필요하다면 여기도 필요할 것 같네요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

image

여긴 delete 쿼리 하나만 실행되어서 없어도 될 것 같습니다.
( 삭제할 장소가 없는 경우 delete 쿼리 실행 x )

Copy link
Collaborator

Choose a reason for hiding this comment

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

고수시군요

@koomchang koomchang self-requested a review November 25, 2024 06:39
Copy link
Collaborator

@hyohyo12 hyohyo12 left a comment

Choose a reason for hiding this comment

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

수고하셨습니다!!

@Miensoap Miensoap merged commit 3557c71 into develop Nov 25, 2024
2 checks passed
@Miensoap Miensoap deleted the feature/#177 branch November 25, 2024 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BE 백엔드 관련 이슈입니다 ⚙️ 리팩터링 코드 퀄리티를 높입니다 🌱 기능추가 새로운 기능 요청입니다
Projects
None yet
3 participants