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

[5기 손가현] Shorten-URL 과제 제출합니다. #72

Open
wants to merge 14 commits into
base: hyun2371
Choose a base branch
from

Conversation

hyun2371
Copy link
Member

@hyun2371 hyun2371 commented Dec 17, 2023

📌 과제 설명

원본 url을 shortUrl로 변환해주는 애플리케이션입니다.

요구사항

각 요구사항을 모두 충족할 수 있도록 노력해봅시다.

  • URL 입력폼 제공 및 결과 출력
  • URL Shortening Key는 8 Character 이내로 생성
  • 단축된 URL 요청시 원래 URL로 리다이렉트
  • 단축된 URL에 대한 요청 수 정보저장 (optional)
  • Shortening Key를 생성하는 알고리즘 2개 이상 제공하며 애플리케이션 실행중 동적으로 변경 가능 (optional)

구현 내용

  • base62 알고리즘으로 encoder를 구현하였고, 이 때 value 값으로 자동 생성되는 url_id 값을 활용했습니다.
  • shortUri을 디코딩해 유저 아이디를 획득한 후, repository에서 해당 아이디로 원본 url을 조회했습니다.
  • custom valid annotation을 활용하여 사용자가 유효하지 않은 Url을 넘길 경우 에러 페이지로 이동시켰습니다.
  • service와 url 유효성 검증 로직에 대한 테스트를 수행했습니다.

구현 이미지

사용자가 url을 넣어주면 shortUrl로 변환합니다.
해당 shortUrl 클릭시 사용자가 붙여넣은 url로 이동됩니다.

shortener1 shortened_url2

✅ PR 포인트 & 궁금한 점

  • 서비스에 url이 있는지 조회하고 없으면 생성해서 반환하는 로직이 있습니다. exists로 존재여부를 확인하고 분기처리를 했는데 optional.orElseGet(()->repository.save(urlEntity))을 사용하는게 더 나은 방법일지 궁금합니다.
  • 테스트 코드 로직이 잘 짜여졌는지 궁금합니다.

@hyun2371 hyun2371 changed the title [5기 손가현] Shorten-URL 과제 제출합니다. (수정 중) [5기 손가현] Shorten-URL 과제 제출합니다. Dec 18, 2023
Copy link

@ordilov ordilov left a comment

Choose a reason for hiding this comment

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

과제 고생하셨습니다~!!
질문 주신 부분들은 해당 부분에 답글 달았습니다!

Comment on lines +25 to +27
Url savedUrl = getSavedUrl(request.originUrl());

savedUrl.increaseRequestCount();
Copy link

Choose a reason for hiding this comment

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

질문주신 orElseGet 으로 처리해도 괜찮을 것 같습니다. 다만 개선하면 좋을 포인트가 있습니다.

  1. 트랜잭션 범위를 줄여도 괜찮을 것 같습니다.
  2. 위 경우대로 값을 불러오면 처음 생성한 url 도 요청수가 +1 되서 나오게 됩니다.

@InjectMocks
private UrlService service;

@DisplayName("Base62인코딩으로 shortenUrl을 생성할 수 있다.")
Copy link

Choose a reason for hiding this comment

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

테스트 작성해주신 부분은 좋지만 추가되면 좋을 부분이 있습니다.
테스트만 봤을 때는 요구사항을 만족하는지 알 수가 없습니다.

  1. 8글자 이내로 생성되었는지?
  2. 요청 수가 저장되었는지?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants